- {/* {localStorage.getItem("ide") === "jetbrains" ||
- localStorage.getItem("hideFeature") === "true" || (
-
{
- localStorage.setItem("hideFeature", "true");
- }}
- onMouseEnter={() => {
- dispatch(
- setBottomMessage(
- `🎁 New Feature: Use ${getMetaKeyLabel()}⇧R automatically debug errors in the terminal (you can click the sparkle icon to make it go away)`
- )
- );
- }}
- onMouseLeave={() => {
- dispatch(
- setBottomMessageCloseTimeout(
- setTimeout(() => {
- dispatch(setBottomMessage(undefined));
- }, 2000)
- )
- );
- }}
- width="1.3em"
- height="1.3em"
- color="yellow"
- />
- )} */}
{indexingProgress >= 1 && // Would take up too much space together with indexing progress
defaultModel?.provider === "free-trial" &&
(location.pathname === "/settings" ||
- parseInt(localStorage.getItem("ftc") || "0") >= 125) && (
+ (getLocalStorage("ftc") ?? 0) >= 125) && (
)}
diff --git a/gui/src/components/dialogs/KeyboardShortcuts.tsx b/gui/src/components/dialogs/KeyboardShortcuts.tsx
index 28dac7fee..fd5fb903b 100644
--- a/gui/src/components/dialogs/KeyboardShortcuts.tsx
+++ b/gui/src/components/dialogs/KeyboardShortcuts.tsx
@@ -7,6 +7,7 @@ import {
vscForeground,
} from "..";
import { getPlatform } from "../../util";
+import { isJetBrains } from "../../util/ide";
const GridDiv = styled.div`
display: grid;
@@ -209,18 +210,17 @@ function KeyboardShortcutsDialog() {
Keyboard Shortcuts
- {(localStorage.getItem("ide") === "jetbrains"
- ? jetbrainsShortcuts
- : vscodeShortcuts
- ).map((shortcut) => {
- return (
-
- );
- })}
+ {(isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts).map(
+ (shortcut) => {
+ return (
+
+ );
+ },
+ )}
);
diff --git a/gui/src/components/mainInput/ContinueButton.tsx b/gui/src/components/mainInput/ContinueButton.tsx
index b550aec48..6a2ab8da4 100644
--- a/gui/src/components/mainInput/ContinueButton.tsx
+++ b/gui/src/components/mainInput/ContinueButton.tsx
@@ -1,5 +1,4 @@
import { PlayIcon, StopIcon } from "@heroicons/react/24/outline";
-import { useEffect, useState } from "react";
import styled from "styled-components";
import { Button } from "..";
@@ -43,28 +42,9 @@ function ContinueButton(props: {
disabled: boolean;
showStop: boolean;
}) {
- const [buttonColor, setButtonColor] = useState(
- localStorage.getItem("continueButtonColor")
- );
-
- useEffect(() => {
- const handleStorageChange = (e: any) => {
- if (e.key === "continueButtonColor") {
- // Update your state or do whatever you need to do here
- setButtonColor(e.newValue);
- }
- };
-
- window.addEventListener("storage", handleStorageChange);
-
- // Don't forget to cleanup the event listener
- return () => window.removeEventListener("storage", handleStorageChange);
- }, []);
-
return (
{
if (defaultModel?.provider === "free-trial") {
- const ftc = localStorage.getItem("ftc");
+ const ftc = getLocalStorage("ftc");
if (ftc) {
- const u = parseInt(ftc);
- localStorage.setItem("ftc", (u + 1).toString());
+ setLocalStorage("ftc", ftc + 1);
- if (u >= 250) {
+ if (ftc >= 250) {
dispatch(setShowDialog(true));
dispatch(setDialogMessage());
posthog?.capture("ftc_reached");
return;
}
} else {
- localStorage.setItem("ftc", "1");
+ setLocalStorage("ftc", 1);
}
}
diff --git a/gui/src/pages/settings.tsx b/gui/src/pages/settings.tsx
index 63ee5d2f1..ff42c21b6 100644
--- a/gui/src/pages/settings.tsx
+++ b/gui/src/pages/settings.tsx
@@ -20,6 +20,7 @@ import Loader from "../components/loaders/Loader";
import { RootState } from "../redux/store";
import { getFontSize, getPlatform } from "../util";
import { postToIde } from "../util/ide";
+import { setLocalStorage } from "../util/localStorage";
const CancelButton = styled(Button)`
background-color: transparent;
@@ -264,7 +265,7 @@ function Settings() {
step="1"
defaultValue={getFontSize()}
onChange={(e) => {
- localStorage.setItem("fontSize", e.target.value);
+ setLocalStorage("fontSize", parseInt(e.target.value));
}}
/>
diff --git a/gui/src/util/ide.ts b/gui/src/util/ide.ts
index 28e7557fc..57ab45f04 100644
--- a/gui/src/util/ide.ts
+++ b/gui/src/util/ide.ts
@@ -6,6 +6,7 @@ import {
} from "core/web/webviewProtocol";
import { v4 as uuidv4 } from "uuid";
import "vscode-webview";
+import { getLocalStorage } from "./localStorage";
interface vscode {
postMessage(message: any): vscode;
}
@@ -14,7 +15,7 @@ declare const vscode: any;
function _postToIde(messageType: string, data: any, messageId?: string) {
if (typeof vscode === "undefined") {
- if (localStorage.getItem("ide") === "jetbrains") {
+ if (isJetBrains()) {
if (window.postIntellijMessage === undefined) {
console.log(
"Unable to send message: postIntellijMessage is undefined. ",
@@ -183,5 +184,5 @@ export function appendText(text: string) {
}
export function isJetBrains() {
- return localStorage.getItem("ide") === "jetbrains";
+ return getLocalStorage("ide") === "jetbrains";
}
diff --git a/gui/src/util/index.ts b/gui/src/util/index.ts
index 3fa6f8412..17e220808 100644
--- a/gui/src/util/index.ts
+++ b/gui/src/util/index.ts
@@ -1,3 +1,5 @@
+import { getLocalStorage } from "./localStorage";
+
type Platform = "mac" | "linux" | "windows" | "unknown";
export function getPlatform(): Platform {
@@ -43,6 +45,5 @@ export function getMetaKeyLabel(): string {
}
export function getFontSize(): number {
- const fontSize = localStorage.getItem("fontSize");
- return fontSize ? parseInt(fontSize) : 14;
+ return getLocalStorage("fontSize") ?? 14;
}
diff --git a/gui/src/util/localStorage.ts b/gui/src/util/localStorage.ts
index faddd64f6..07cc3396d 100644
--- a/gui/src/util/localStorage.ts
+++ b/gui/src/util/localStorage.ts
@@ -1,6 +1,9 @@
type LocalStorageTypes = {
onboardingComplete: boolean;
mainTextEntryCounter: number;
+ ide: "vscode" | "jetbrains";
+ ftc: number;
+ fontSize: number;
};
export function getLocalStorage