mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: clearing theme
This commit is contained in:
parent
777f8573d2
commit
2246775046
4 changed files with 70 additions and 60 deletions
|
@ -9,26 +9,32 @@ export interface SettingsContext {
|
||||||
updateUserPreferences: (values: Partial<UserPreferences>) => Promise<void>;
|
updateUserPreferences: (values: Partial<UserPreferences>) => Promise<void>;
|
||||||
setCurrentCategoryIndex: React.Dispatch<React.SetStateAction<number>>;
|
setCurrentCategoryIndex: React.Dispatch<React.SetStateAction<number>>;
|
||||||
clearSourceUrl: () => void;
|
clearSourceUrl: () => void;
|
||||||
|
clearTheme: () => void;
|
||||||
sourceUrl: string | null;
|
sourceUrl: string | null;
|
||||||
currentCategoryIndex: number;
|
currentCategoryIndex: number;
|
||||||
blockedUsers: UserBlocks["blocks"];
|
blockedUsers: UserBlocks["blocks"];
|
||||||
fetchBlockedUsers: () => Promise<void>;
|
fetchBlockedUsers: () => Promise<void>;
|
||||||
appearanceTheme: string | null;
|
appearance: {
|
||||||
appearanceAuthorId: string | null;
|
theme: string | null;
|
||||||
appearanceAuthorName: string | null;
|
authorId: string | null;
|
||||||
|
authorName: string | null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const settingsContext = createContext<SettingsContext>({
|
export const settingsContext = createContext<SettingsContext>({
|
||||||
updateUserPreferences: async () => {},
|
updateUserPreferences: async () => {},
|
||||||
setCurrentCategoryIndex: () => {},
|
setCurrentCategoryIndex: () => {},
|
||||||
clearSourceUrl: () => {},
|
clearSourceUrl: () => {},
|
||||||
|
clearTheme: () => {},
|
||||||
sourceUrl: null,
|
sourceUrl: null,
|
||||||
currentCategoryIndex: 0,
|
currentCategoryIndex: 0,
|
||||||
blockedUsers: [],
|
blockedUsers: [],
|
||||||
fetchBlockedUsers: async () => {},
|
fetchBlockedUsers: async () => {},
|
||||||
appearanceTheme: null,
|
appearance: {
|
||||||
appearanceAuthorId: null,
|
theme: null,
|
||||||
appearanceAuthorName: null,
|
authorId: null,
|
||||||
|
authorName: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { Provider } = settingsContext;
|
const { Provider } = settingsContext;
|
||||||
|
@ -43,15 +49,16 @@ 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 [appearanceTheme, setAppearanceTheme] = useState<string | null>(null);
|
const [appearance, setAppearance] = useState<{
|
||||||
const [appearanceAuthorId, setAppearanceAuthorId] = useState<string | null>(
|
theme: string | null;
|
||||||
null
|
authorId: string | null;
|
||||||
);
|
authorName: string | null;
|
||||||
const [appearanceAuthorName, setAppearanceAuthorName] = useState<
|
}>({
|
||||||
string | null
|
theme: null,
|
||||||
>(null);
|
authorId: null,
|
||||||
|
authorName: 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();
|
||||||
|
@ -71,8 +78,8 @@ export function SettingsContextProvider({
|
||||||
}, [defaultSourceUrl]);
|
}, [defaultSourceUrl]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (appearanceTheme) setCurrentCategoryIndex(3);
|
if (appearance.theme) setCurrentCategoryIndex(3);
|
||||||
}, [appearanceTheme]);
|
}, [appearance.theme]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
@ -80,9 +87,11 @@ export function SettingsContextProvider({
|
||||||
defaultAppearanceAuthorId &&
|
defaultAppearanceAuthorId &&
|
||||||
defaultAppearanceAuthorName
|
defaultAppearanceAuthorName
|
||||||
) {
|
) {
|
||||||
setAppearanceTheme(defaultAppearanceTheme);
|
setAppearance({
|
||||||
setAppearanceAuthorId(defaultAppearanceAuthorId);
|
theme: defaultAppearanceTheme,
|
||||||
setAppearanceAuthorName(defaultAppearanceAuthorName);
|
authorId: defaultAppearanceAuthorId,
|
||||||
|
authorName: defaultAppearanceAuthorName,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
defaultAppearanceTheme,
|
defaultAppearanceTheme,
|
||||||
|
@ -90,6 +99,14 @@ export function SettingsContextProvider({
|
||||||
defaultAppearanceAuthorName,
|
defaultAppearanceAuthorName,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const clearTheme = useCallback(() => {
|
||||||
|
setAppearance({
|
||||||
|
theme: null,
|
||||||
|
authorId: null,
|
||||||
|
authorName: null,
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -115,12 +132,11 @@ export function SettingsContextProvider({
|
||||||
setCurrentCategoryIndex,
|
setCurrentCategoryIndex,
|
||||||
clearSourceUrl,
|
clearSourceUrl,
|
||||||
fetchBlockedUsers,
|
fetchBlockedUsers,
|
||||||
|
clearTheme,
|
||||||
currentCategoryIndex,
|
currentCategoryIndex,
|
||||||
sourceUrl,
|
sourceUrl,
|
||||||
blockedUsers,
|
blockedUsers,
|
||||||
appearanceTheme,
|
appearance,
|
||||||
appearanceAuthorId,
|
|
||||||
appearanceAuthorName,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useCallback, useContext, 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";
|
import { ImportThemeModal } from "./modals/import-theme-modal";
|
||||||
|
import { settingsContext } from "@renderer/context";
|
||||||
|
|
||||||
interface SettingsAppearanceProps {
|
interface SettingsAppearanceProps {
|
||||||
appearanceTheme: string | null;
|
appearance: {
|
||||||
appearanceAuthorId: string | null;
|
theme: string | null;
|
||||||
appearanceAuthorName: string | null;
|
authorId: string | null;
|
||||||
|
authorName: string | null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SettingsAppearance = ({
|
export function SettingsAppearance({
|
||||||
appearanceTheme,
|
appearance,
|
||||||
appearanceAuthorId,
|
}: Readonly<SettingsAppearanceProps>) {
|
||||||
appearanceAuthorName,
|
|
||||||
}: SettingsAppearanceProps) => {
|
|
||||||
const [themes, setThemes] = useState<Theme[]>([]);
|
const [themes, setThemes] = useState<Theme[]>([]);
|
||||||
const [isImportThemeModalVisible, setIsImportThemeModalVisible] =
|
const [isImportThemeModalVisible, setIsImportThemeModalVisible] =
|
||||||
useState(false);
|
useState(false);
|
||||||
|
@ -24,14 +25,16 @@ export const SettingsAppearance = ({
|
||||||
authorName: string;
|
authorName: string;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
const loadThemes = async () => {
|
const { clearTheme } = useContext(settingsContext);
|
||||||
|
|
||||||
|
const loadThemes = useCallback(async () => {
|
||||||
const themesList = await window.electron.getAllCustomThemes();
|
const themesList = await window.electron.getAllCustomThemes();
|
||||||
setThemes(themesList);
|
setThemes(themesList);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadThemes();
|
loadThemes();
|
||||||
}, []);
|
}, [loadThemes]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubscribe = window.electron.onCssInjected(() => {
|
const unsubscribe = window.electron.onCssInjected(() => {
|
||||||
|
@ -39,18 +42,24 @@ export const SettingsAppearance = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => unsubscribe();
|
return () => unsubscribe();
|
||||||
}, []);
|
}, [loadThemes]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (appearanceTheme && appearanceAuthorId && appearanceAuthorName) {
|
if (appearance.theme && appearance.authorId && appearance.authorName) {
|
||||||
setIsImportThemeModalVisible(true);
|
setIsImportThemeModalVisible(true);
|
||||||
setImportTheme({
|
setImportTheme({
|
||||||
theme: appearanceTheme,
|
theme: appearance.theme,
|
||||||
authorId: appearanceAuthorId,
|
authorId: appearance.authorId,
|
||||||
authorName: appearanceAuthorName,
|
authorName: appearance.authorName,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [appearanceTheme, appearanceAuthorId, appearanceAuthorName]);
|
}, [appearance.theme, appearance.authorId, appearance.authorName]);
|
||||||
|
|
||||||
|
const onThemeImported = useCallback(() => {
|
||||||
|
setIsImportThemeModalVisible(false);
|
||||||
|
loadThemes();
|
||||||
|
clearTheme();
|
||||||
|
}, [clearTheme, loadThemes]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-appearance">
|
<div className="settings-appearance">
|
||||||
|
@ -80,10 +89,7 @@ export const SettingsAppearance = ({
|
||||||
<ImportThemeModal
|
<ImportThemeModal
|
||||||
visible={isImportThemeModalVisible}
|
visible={isImportThemeModalVisible}
|
||||||
onClose={() => setIsImportThemeModalVisible(false)}
|
onClose={() => setIsImportThemeModalVisible(false)}
|
||||||
onThemeImported={() => {
|
onThemeImported={onThemeImported}
|
||||||
setIsImportThemeModalVisible(false);
|
|
||||||
loadThemes();
|
|
||||||
}}
|
|
||||||
themeName={importTheme.theme}
|
themeName={importTheme.theme}
|
||||||
authorId={importTheme.authorId}
|
authorId={importTheme.authorId}
|
||||||
authorName={importTheme.authorName}
|
authorName={importTheme.authorName}
|
||||||
|
@ -91,4 +97,4 @@ export const SettingsAppearance = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ export function SettingsAccount() {
|
||||||
return () => {
|
return () => {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
};
|
};
|
||||||
}, [fetchUserDetails, updateUserDetails, showSuccessToast]);
|
}, [fetchUserDetails, updateUserDetails, t, showSuccessToast]);
|
||||||
|
|
||||||
const visibilityOptions = [
|
const visibilityOptions = [
|
||||||
{ value: "PUBLIC", label: t("public") },
|
{ value: "PUBLIC", label: t("public") },
|
||||||
|
|
|
@ -65,13 +65,7 @@ export default function Settings() {
|
||||||
return (
|
return (
|
||||||
<SettingsContextProvider>
|
<SettingsContextProvider>
|
||||||
<SettingsContextConsumer>
|
<SettingsContextConsumer>
|
||||||
{({
|
{({ currentCategoryIndex, setCurrentCategoryIndex, appearance }) => {
|
||||||
currentCategoryIndex,
|
|
||||||
setCurrentCategoryIndex,
|
|
||||||
appearanceTheme,
|
|
||||||
appearanceAuthorId,
|
|
||||||
appearanceAuthorName,
|
|
||||||
}) => {
|
|
||||||
const renderCategory = () => {
|
const renderCategory = () => {
|
||||||
if (currentCategoryIndex === 0) {
|
if (currentCategoryIndex === 0) {
|
||||||
return <SettingsGeneral />;
|
return <SettingsGeneral />;
|
||||||
|
@ -86,13 +80,7 @@ export default function Settings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentCategoryIndex === 3) {
|
if (currentCategoryIndex === 3) {
|
||||||
return (
|
return <SettingsAppearance appearance={appearance} />;
|
||||||
<SettingsAppearance
|
|
||||||
appearanceTheme={appearanceTheme}
|
|
||||||
appearanceAuthorId={appearanceAuthorId}
|
|
||||||
appearanceAuthorName={appearanceAuthorName}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentCategoryIndex === 4) {
|
if (currentCategoryIndex === 4) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue