refactor: lint

This commit is contained in:
Hachi-R 2025-01-29 03:46:59 -03:00
parent 5a19e9fd12
commit b56fc4d888
13 changed files with 81 additions and 63 deletions

View File

@ -315,7 +315,8 @@
"delete_all_themes": "Delete all themes", "delete_all_themes": "Delete all themes",
"delete_all_themes_description": "This will delete all your custom themes", "delete_all_themes_description": "This will delete all your custom themes",
"delete_theme_description": "This will delete the theme {{theme}}", "delete_theme_description": "This will delete the theme {{theme}}",
"cancel": "Cancel" "cancel": "Cancel",
"appearance": "Appearance"
}, },
"notifications": { "notifications": {
"download_complete": "Download complete", "download_complete": "Download complete",

View File

@ -1,7 +1,10 @@
import { themes } from "@main/level/sublevels/themes"; import { themes } from "@main/level/sublevels/themes";
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
const getCustomThemeById = async (_event: Electron.IpcMainInvokeEvent, themeId: string) => { const getCustomThemeById = async (
_event: Electron.IpcMainInvokeEvent,
themeId: string
) => {
return await themes.get(themeId); return await themes.get(themeId);
}; };

View File

@ -1,7 +1,10 @@
import { WindowManager } from "@main/services"; import { WindowManager } from "@main/services";
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
const openEditorWindow = async (_event: Electron.IpcMainInvokeEvent, themeId: string) => { const openEditorWindow = async (
_event: Electron.IpcMainInvokeEvent,
themeId: string
) => {
WindowManager.openEditorWindow(themeId); WindowManager.openEditorWindow(themeId);
}; };

View File

@ -230,15 +230,10 @@ export class WindowManager {
`${process.env["ELECTRON_RENDERER_URL"]}#/editor?themeId=${themeId}` `${process.env["ELECTRON_RENDERER_URL"]}#/editor?themeId=${themeId}`
); );
} else { } else {
editorWindow.loadFile( editorWindow.loadFile(path.join(__dirname, "../renderer/index.html"), {
path.join(__dirname, "../renderer/index.html"),
{
hash: "editor", hash: "editor",
});
} }
);
}
editorWindow.once("ready-to-show", () => { editorWindow.once("ready-to-show", () => {
editorWindow.show(); editorWindow.show();

View File

@ -349,11 +349,12 @@ contextBridge.exposeInMainWorld("electron", {
getActiveCustomTheme: () => ipcRenderer.invoke("getActiveCustomTheme"), getActiveCustomTheme: () => ipcRenderer.invoke("getActiveCustomTheme"),
/* Editor */ /* Editor */
openEditorWindow: (themeId: string) => ipcRenderer.invoke("openEditorWindow", themeId), openEditorWindow: (themeId: string) =>
injectCSS: (cssString: string) => ipcRenderer.invoke("openEditorWindow", themeId),
ipcRenderer.invoke("injectCSS", cssString), injectCSS: (cssString: string) => ipcRenderer.invoke("injectCSS", cssString),
onCssInjected: (cb: (cssString: string) => void) => { onCssInjected: (cb: (cssString: string) => void) => {
const listener = (_event: Electron.IpcRendererEvent, cssString: string) => cb(cssString); const listener = (_event: Electron.IpcRendererEvent, cssString: string) =>
cb(cssString);
ipcRenderer.on("css-injected", listener); ipcRenderer.on("css-injected", listener);
return () => ipcRenderer.removeListener("css-injected", listener); return () => ipcRenderer.removeListener("css-injected", listener);
}, },

View File

@ -282,7 +282,9 @@ declare global {
/* Editor */ /* Editor */
openEditorWindow: (themeId: string) => Promise<void>; openEditorWindow: (themeId: string) => Promise<void>;
injectCSS: (cssString: string) => Promise<void>; injectCSS: (cssString: string) => Promise<void>;
onCssInjected: (cb: (cssString: string) => void) => () => Electron.IpcRenderer; onCssInjected: (
cb: (cssString: string) => void
) => () => Electron.IpcRenderer;
} }
interface Window { interface Window {

View File

@ -1,22 +1,26 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from "react";
import "./editor.scss"; import "./editor.scss";
import Editor from '@monaco-editor/react'; import Editor from "@monaco-editor/react";
import { Theme } from '@types'; import { Theme } from "@types";
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from "react-router-dom";
import { Button } from '@renderer/components'; import { Button } from "@renderer/components";
import { CheckIcon, CodeIcon, ProjectRoadmapIcon } from '@primer/octicons-react'; import {
import { useTranslation } from 'react-i18next'; CheckIcon,
CodeIcon,
ProjectRoadmapIcon,
} from "@primer/octicons-react";
import { useTranslation } from "react-i18next";
const EditorPage = () => { const EditorPage = () => {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const [theme, setTheme] = useState<Theme | null>(null); const [theme, setTheme] = useState<Theme | null>(null);
const [code, setCode] = useState(''); const [code, setCode] = useState("");
const [activeTab, setActiveTab] = useState('code'); const [activeTab, setActiveTab] = useState("code");
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
const themeId = searchParams.get('themeId'); const themeId = searchParams.get("themeId");
const { t } = useTranslation('settings'); const { t } = useTranslation("settings");
const handleTabChange = (tab: string) => { const handleTabChange = (tab: string) => {
setActiveTab(tab); setActiveTab(tab);
@ -24,7 +28,7 @@ const EditorPage = () => {
useEffect(() => { useEffect(() => {
if (themeId) { if (themeId) {
window.electron.getCustomThemeById(themeId).then(loadedTheme => { window.electron.getCustomThemeById(themeId).then((loadedTheme) => {
if (loadedTheme) { if (loadedTheme) {
setTheme(loadedTheme); setTheme(loadedTheme);
setCode(loadedTheme.code); setCode(loadedTheme.code);
@ -35,16 +39,16 @@ const EditorPage = () => {
useEffect(() => { useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === 's') { if ((event.ctrlKey || event.metaKey) && event.key === "s") {
event.preventDefault(); event.preventDefault();
handleSave(); handleSave();
} }
}; };
window.addEventListener('keydown', handleKeyDown); window.addEventListener("keydown", handleKeyDown);
return () => { return () => {
window.removeEventListener('keydown', handleKeyDown); window.removeEventListener("keydown", handleKeyDown);
}; };
}, [code, theme]); }, [code, theme]);
@ -60,7 +64,7 @@ const EditorPage = () => {
const updatedTheme = { const updatedTheme = {
...theme, ...theme,
code: code, code: code,
updatedAt: new Date() updatedAt: new Date(),
}; };
await window.electron.updateCustomTheme(theme.id, updatedTheme); await window.electron.updateCustomTheme(theme.id, updatedTheme);
@ -76,13 +80,10 @@ const EditorPage = () => {
<div className="editor"> <div className="editor">
<div className="editor__header"> <div className="editor__header">
<h1>{theme?.name}</h1> <h1>{theme?.name}</h1>
{hasUnsavedChanges && ( {hasUnsavedChanges && <div className="editor__header__status"></div>}
<div className="editor__header__status">
</div>
)}
</div> </div>
{activeTab === 'code' && ( {activeTab === "code" && (
<Editor <Editor
theme="vs-dark" theme="vs-dark"
defaultLanguage="css" defaultLanguage="css"
@ -91,37 +92,45 @@ const EditorPage = () => {
options={{ options={{
minimap: { enabled: false }, minimap: { enabled: false },
fontSize: 14, fontSize: 14,
lineNumbers: 'on', lineNumbers: "on",
wordWrap: 'on', wordWrap: "on",
automaticLayout: true, automaticLayout: true,
}} }}
/> />
)} )}
{activeTab === 'info' && ( {activeTab === "info" && (
<div className="editor__info"> <div className="editor__info">
entao mano eu ate fiz isso aqui mas tava feio dms ai deu vergonha e removi kkkk entao mano eu ate fiz isso aqui mas tava feio dms ai deu vergonha e
removi kkkk
</div> </div>
)} )}
<div className="editor__footer"> <div className="editor__footer">
<div className="editor__footer-actions"> <div className="editor__footer-actions">
<div className="editor__footer-actions__tabs"> <div className="editor__footer-actions__tabs">
<Button onClick={() => handleTabChange('code')} theme='dark' className={activeTab === 'code' ? 'active' : ''}> <Button
onClick={() => handleTabChange("code")}
theme="dark"
className={activeTab === "code" ? "active" : ""}
>
<CodeIcon /> <CodeIcon />
{t('editor_tab_code')} {t("editor_tab_code")}
</Button> </Button>
<Button onClick={() => handleTabChange('info')} theme='dark' className={activeTab === 'info' ? 'active' : ''}> <Button
onClick={() => handleTabChange("info")}
theme="dark"
className={activeTab === "info" ? "active" : ""}
>
<ProjectRoadmapIcon /> <ProjectRoadmapIcon />
{t('editor_tab_info')} {t("editor_tab_info")}
</Button> </Button>
</div> </div>
<Button onClick={handleSave}> <Button onClick={handleSave}>
<CheckIcon /> <CheckIcon />
{t('editor_tab_save')} {t("editor_tab_save")}
</Button> </Button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,7 +11,7 @@ interface ThemeActionsProps {
} }
export const ThemeActions = ({ onListUpdated }: ThemeActionsProps) => { export const ThemeActions = ({ onListUpdated }: ThemeActionsProps) => {
const { t } = useTranslation('settings'); const { t } = useTranslation("settings");
const [addThemeModalVisible, setAddThemeModalVisible] = useState(false); const [addThemeModalVisible, setAddThemeModalVisible] = useState(false);
const [deleteAllThemesModalVisible, setDeleteAllThemesModalVisible] = const [deleteAllThemesModalVisible, setDeleteAllThemesModalVisible] =

View File

@ -14,7 +14,7 @@ interface ThemeCardProps {
} }
export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => { export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => {
const { t } = useTranslation('settings'); const { t } = useTranslation("settings");
const navigate = useNavigate(); const navigate = useNavigate();
const [deleteThemeModalVisible, setDeleteThemeModalVisible] = useState(false); const [deleteThemeModalVisible, setDeleteThemeModalVisible] = useState(false);
@ -31,14 +31,14 @@ export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => {
removeCustomCss(); removeCustomCss();
await window.electron.updateCustomTheme(activeTheme.id, { await window.electron.updateCustomTheme(activeTheme.id, {
...activeTheme, ...activeTheme,
isActive: false isActive: false,
}); });
} }
injectCustomCss(currentTheme.code); injectCustomCss(currentTheme.code);
await window.electron.updateCustomTheme(currentTheme.id, { await window.electron.updateCustomTheme(currentTheme.id, {
...currentTheme, ...currentTheme,
isActive: true isActive: true,
}); });
onListUpdated(); onListUpdated();
@ -52,7 +52,7 @@ export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => {
removeCustomCss(); removeCustomCss();
await window.electron.updateCustomTheme(theme.id, { await window.electron.updateCustomTheme(theme.id, {
...theme, ...theme,
isActive: false isActive: false,
}); });
onListUpdated(); onListUpdated();

View File

@ -26,7 +26,11 @@ export const SettingsAppearance = () => {
<ThemePlaceholder onListUpdated={loadThemes} /> <ThemePlaceholder onListUpdated={loadThemes} />
) : ( ) : (
[...themes] [...themes]
.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()) .sort(
(a, b) =>
new Date(b.updatedAt).getTime() -
new Date(a.updatedAt).getTime()
)
.map((theme) => ( .map((theme) => (
<ThemeCard <ThemeCard
key={theme.id} key={theme.id}