feat: enhance theme import flow with redirect and modal

This commit is contained in:
Hachi-R 2025-02-16 15:17:11 -03:00
parent ca75ad6721
commit ef28337729
3 changed files with 52 additions and 7 deletions

View file

@ -10,6 +10,7 @@ import { PythonRPC } from "./services/python-rpc";
import { Aria2 } from "./services/aria2"; import { Aria2 } from "./services/aria2";
import { db, levelKeys } from "./level"; import { db, levelKeys } from "./level";
import { loadState } from "./main"; import { loadState } from "./main";
import { sleep } from "./helpers";
const { autoUpdater } = updater; const { autoUpdater } = updater;
@ -92,11 +93,15 @@ const handleDeepLinkPath = (uri?: string) => {
const authorCode = url.searchParams.get("author"); const authorCode = url.searchParams.get("author");
if (themeName && authorCode) { if (themeName && authorCode) {
WindowManager.mainWindow?.webContents.send( WindowManager.redirect(`settings?theme=true`);
"import-theme",
themeName, sleep(1000).then(() => {
authorCode WindowManager.mainWindow?.webContents.send(
); "import-theme",
themeName,
authorCode
);
});
} }
} }
} catch (error) { } catch (error) {

View file

@ -37,13 +37,14 @@ export function SettingsContextProvider({
}: Readonly<SettingsContextProviderProps>) { }: Readonly<SettingsContextProviderProps>) {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [sourceUrl, setSourceUrl] = useState<string | null>(null); const [sourceUrl, setSourceUrl] = useState<string | null>(null);
const [appearanceUrl, setAppearanceUrl] = useState<string | null>(null);
const [currentCategoryIndex, setCurrentCategoryIndex] = useState(0); const [currentCategoryIndex, setCurrentCategoryIndex] = useState(0);
const [blockedUsers, setBlockedUsers] = useState<UserBlocks["blocks"]>([]); const [blockedUsers, setBlockedUsers] = useState<UserBlocks["blocks"]>([]);
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const defaultSourceUrl = searchParams.get("urls"); const defaultSourceUrl = searchParams.get("urls");
const defaultAppearanceUrl = searchParams.get("theme");
useEffect(() => { useEffect(() => {
if (sourceUrl) setCurrentCategoryIndex(2); if (sourceUrl) setCurrentCategoryIndex(2);
}, [sourceUrl]); }, [sourceUrl]);
@ -54,6 +55,16 @@ export function SettingsContextProvider({
} }
}, [defaultSourceUrl]); }, [defaultSourceUrl]);
useEffect(() => {
if (appearanceUrl) setCurrentCategoryIndex(3);
}, [appearanceUrl]);
useEffect(() => {
if (defaultAppearanceUrl) {
setAppearanceUrl(defaultAppearanceUrl);
}
}, [defaultAppearanceUrl]);
const fetchBlockedUsers = useCallback(async () => { const fetchBlockedUsers = useCallback(async () => {
const blockedUsers = await window.electron.getBlockedUsers(12, 0); const blockedUsers = await window.electron.getBlockedUsers(12, 0);
setBlockedUsers(blockedUsers.blocks); setBlockedUsers(blockedUsers.blocks);

View file

@ -2,9 +2,16 @@ import { useEffect, useState } from "react";
import "./settings-appearance.scss"; import "./settings-appearance.scss";
import { ThemeActions, ThemeCard, ThemePlaceholder } from "./index"; import { ThemeActions, ThemeCard, ThemePlaceholder } from "./index";
import type { Theme } from "@types"; import type { Theme } from "@types";
import { ImportThemeModal } from "./modals/import-theme-modal";
export const SettingsAppearance = () => { export const SettingsAppearance = () => {
const [themes, setThemes] = useState<Theme[]>([]); const [themes, setThemes] = useState<Theme[]>([]);
const [isImportThemeModalVisible, setIsImportThemeModalVisible] =
useState(false);
const [importTheme, setImportTheme] = useState<{
theme: string;
author: string;
} | null>(null);
const loadThemes = async () => { const loadThemes = async () => {
const themesList = await window.electron.getAllCustomThemes(); const themesList = await window.electron.getAllCustomThemes();
@ -23,6 +30,15 @@ export const SettingsAppearance = () => {
return () => unsubscribe(); return () => unsubscribe();
}, []); }, []);
useEffect(() => {
const unsubscribe = window.electron.onImportTheme((theme, author) => {
setIsImportThemeModalVisible(true);
setImportTheme({ theme, author });
});
return () => unsubscribe();
}, []);
return ( return (
<div className="settings-appearance"> <div className="settings-appearance">
<ThemeActions onListUpdated={loadThemes} themesCount={themes.length} /> <ThemeActions onListUpdated={loadThemes} themesCount={themes.length} />
@ -46,6 +62,19 @@ export const SettingsAppearance = () => {
)) ))
)} )}
</div> </div>
{importTheme && (
<ImportThemeModal
visible={isImportThemeModalVisible}
onClose={() => setIsImportThemeModalVisible(false)}
onThemeImported={() => {
setIsImportThemeModalVisible(false);
loadThemes();
}}
themeName={importTheme.theme}
authorCode={importTheme.author}
/>
)}
</div> </div>
); );
}; };