diff --git a/packages/view/src/App.tsx b/packages/view/src/App.tsx index 8a3f21f7..869281d7 100644 --- a/packages/view/src/App.tsx +++ b/packages/view/src/App.tsx @@ -11,6 +11,7 @@ import { useAnalayzedData } from "hooks"; import { RefreshButton } from "components/RefreshButton"; import type { IDESentEvents } from "types/IDESentEvents"; import { useBranchStore, useDataStore, useGithubInfo, useLoadingStore } from "store"; +import { THEME_INFO } from "components/ThemeSelector/ThemeSelector.const"; const App = () => { const initRef = useRef(false); @@ -40,7 +41,7 @@ const App = () => { if (loading) { return ( void; }; -const themeInfo: ThemeInfo[] = [ - { - title: "Githru", - value: "githru", - colors: { - primary: "#e06091", - secondary: "#8840bb", - tertiary: "#ffd08a", - }, - }, - { - title: "Hacker Blue", - value: "hacker-blue", - colors: { - primary: "#456cf7", - secondary: "#3f4c73", - tertiary: "#6c60f0", - }, - }, - { - title: "Aqua", - value: "aqua", - colors: { - primary: "#51decd", - secondary: "#0687a3", - tertiary: "#a7ffff", - }, - }, - { - title: "Cotton Candy", - value: "cotton-candy", - colors: { - primary: "#ffcccb", - secondary: "#feffd1", - tertiary: "#a39aeb", - }, - }, - - { - title: "Mono", - value: "mono", - colors: { - primary: "#68788f", - secondary: "#3a4776", - tertiary: "#9aaed1", - }, - }, -]; - const ThemeIcons = ({ title, value, colors, onClick }: ThemeIconsProps) => { - const [selectedItem, setSelectedItem] = useState(""); - - useEffect(() => { - const selectedTheme = document.documentElement.getAttribute("custom-type"); - if (selectedTheme) setSelectedItem(selectedTheme); - }, []); - return (
@@ -101,8 +38,9 @@ const ThemeSelector = () => { const themeSelectorRef = useRef(null); const handleTheme = (value: string) => { - setCustomTheme(value); - document.documentElement.setAttribute("custom-type", value); + sendUpdateThemeCommand(value); + window.theme = value; + document.documentElement.setAttribute("theme", value); }; useEffect(() => { @@ -118,7 +56,7 @@ const ThemeSelector = () => { }, []); useEffect(() => { - document.documentElement.setAttribute("custom-type", window.theme); + document.documentElement.setAttribute("theme", window.theme); }, []); return ( @@ -137,7 +75,7 @@ const ThemeSelector = () => { />
- {themeInfo.map((theme) => ( + {Object.entries(THEME_INFO).map(([_, theme]) => ( void; sendFetchBranchListMessage: () => void; sendFetchGithubInfo: () => void; - setCustomTheme: (theme: string) => void; + sendUpdateThemeMessage: (theme: string) => void; } diff --git a/packages/view/src/ide/VSCodeIDEAdapter.ts b/packages/view/src/ide/VSCodeIDEAdapter.ts index cd666a2c..087ab161 100644 --- a/packages/view/src/ide/VSCodeIDEAdapter.ts +++ b/packages/view/src/ide/VSCodeIDEAdapter.ts @@ -58,9 +58,9 @@ export default class VSCodeIDEAdapter implements IDEPort { this.sendMessageToIDE(message); } - public setCustomTheme(theme: string) { + public sendUpdateThemeMessage(theme: string) { const message: IDEMessage = { - command: "updateCustomTheme", + command: "updateTheme", payload: JSON.stringify({ theme }), }; this.sendMessageToIDE(message); diff --git a/packages/view/src/services/index.ts b/packages/view/src/services/index.ts index 8a29aa82..754ca3c8 100644 --- a/packages/view/src/services/index.ts +++ b/packages/view/src/services/index.ts @@ -2,9 +2,9 @@ import { container } from "tsyringe"; import type IDEPort from "ide/IDEPort"; -export const setCustomTheme = (color: string) => { +export const sendUpdateThemeCommand = (theme: string) => { const ideAdapter = container.resolve("IDEAdapter"); - ideAdapter.setCustomTheme(color); + ideAdapter.sendUpdateThemeMessage(theme); }; export const sendFetchAnalyzedDataCommand = (selectedBranch?: string) => { diff --git a/packages/view/src/styles/_colors.scss b/packages/view/src/styles/_colors.scss index d7294f6d..31d45d87 100644 --- a/packages/view/src/styles/_colors.scss +++ b/packages/view/src/styles/_colors.scss @@ -5,7 +5,7 @@ $color-medium-gray: #757880; $color-dark-gray: #3c4048; $color-background: #222324; -html[custom-type="githru"] { +html[theme="githru"] { --color-primary: #e06091; --color-secondary: #8840bb; --color-tertiary: #ffd08a; @@ -13,7 +13,7 @@ html[custom-type="githru"] { --color-failed: #ee2479; } -html[custom-type="hacker-blue"] { +html[theme="hacker-blue"] { --color-primary: #456cf7; --color-secondary: #3f4c73; --color-tertiary: #6c60f0; @@ -21,7 +21,7 @@ html[custom-type="hacker-blue"] { --color-failed: #ee2479; } -html[custom-type="aqua"] { +html[theme="aqua"] { --color-primary: #51decd; --color-secondary: #0687a3; --color-tertiary: #a7ffff; @@ -29,7 +29,7 @@ html[custom-type="aqua"] { --color-failed: #ee2479; } -html[custom-type="cotton-candy"] { +html[theme="cotton-candy"] { --color-primary: #ffcccb; --color-secondary: #feffd1; --color-tertiary: #a39aeb; @@ -37,7 +37,7 @@ html[custom-type="cotton-candy"] { --color-failed: #ff8bbc; } -html[custom-type="mono"] { +html[theme="mono"] { --color-primary: #68788f; --color-secondary: #3a4776; --color-tertiary: #9aaed1; diff --git a/packages/view/src/types/IDEMessage.ts b/packages/view/src/types/IDEMessage.ts index 69c3bfb9..076e86d7 100644 --- a/packages/view/src/types/IDEMessage.ts +++ b/packages/view/src/types/IDEMessage.ts @@ -13,4 +13,4 @@ export type IDEMessageCommandNames = | "fetchBranchList" | "fetchCurrentBranch" | "fetchGithubInfo" - | "updateCustomTheme"; + | "updateTheme"; \ No newline at end of file diff --git a/packages/vscode/src/setting-repository.ts b/packages/vscode/src/setting-repository.ts index a391aac3..0a62b45a 100644 --- a/packages/vscode/src/setting-repository.ts +++ b/packages/vscode/src/setting-repository.ts @@ -17,17 +17,17 @@ export const deleteGithubToken = async (secrets: vscode.SecretStorage) => { return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN); }; -export const setTheme = async (newTheme: string) => { +export const setTheme = (theme: string) => { const configuration = vscode.workspace.getConfiguration(); - configuration.update(SETTING_PROPERTY_NAMES.THEME, newTheme); + configuration.update(SETTING_PROPERTY_NAMES.THEME, theme); }; -export const getTheme = async (): Promise => { +export const getTheme = () => { const configuration = vscode.workspace.getConfiguration(); const theme = configuration.get(SETTING_PROPERTY_NAMES.THEME) as string; if (!theme) { - await setTheme("githru"); + setTheme("githru"); return "githru"; } return theme; diff --git a/packages/vscode/src/webview-loader.ts b/packages/vscode/src/webview-loader.ts index 26a3d0b1..ce15056a 100644 --- a/packages/vscode/src/webview-loader.ts +++ b/packages/vscode/src/webview-loader.ts @@ -85,10 +85,10 @@ export default class WebviewLoader implements vscode.Disposable { }); } - if (command === "updateCustomTheme") { - const colorCode = payload && JSON.parse(payload); - if (colorCode.theme) { - setTheme(colorCode.theme); + if (command === "updateTheme") { + const themeInfo = payload && JSON.parse(payload); + if (themeInfo.theme) { + setTheme(themeInfo.theme); } } } catch (e) { @@ -100,7 +100,7 @@ export default class WebviewLoader implements vscode.Disposable { // this.dispose(); // throw new Error("Project not connected to Git."); // } - this.setWebviewContent(); + this._panel.webview.html = this.getWebviewContent(this._panel.webview); } dispose() { @@ -119,12 +119,12 @@ export default class WebviewLoader implements vscode.Disposable { }); } - private async getWebviewContent(webview: vscode.Webview): Promise { + private getWebviewContent(webview: vscode.Webview) { const reactAppPathOnDisk = vscode.Uri.file(path.join(this.extensionPath, "dist", "webviewApp.js")); const reactAppUri = webview.asWebviewUri(reactAppPathOnDisk); // const reactAppUri = reactAppPathOnDisk.with({ scheme: "vscode-resource" }); - const theme = await getTheme(); + const theme = getTheme(); const returnString = ` @@ -149,12 +149,14 @@ export default class WebviewLoader implements vscode.Disposable { return returnString; } - private async setWebviewContent() { + public setGlobalOwnerAndRepo(owner: string, repo: string) { if (this._panel) { - this._panel.webview.html = await this.getWebviewContent(this._panel.webview); + this._panel.webview.postMessage({ + command: "setGlobalOwnerAndRepo", + data: { owner, repo }, + }); } } - } type GithruFetcher = (...params: P) => Promise;