Skip to content

Commit

Permalink
fix navigation back to the expanded view
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Dec 26, 2024
1 parent ed57887 commit a0bcbe6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/decky-patches/unminify-mode/class-hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function initializeClassHashMap() {
// Filter out things that start with a number (eg: Breakpoints like 800px)
// I have confirmed the new classes don't start with numbers
if (isNaN(Number(value.charAt(0)))) {
// @ts-expect-error
filteredModule[propertyName] = value;
}
});
Expand All @@ -24,9 +25,12 @@ export function initializeClassHashMap() {

const mappings = allClasses.reduce((acc, cur) => {
Object.entries(cur).forEach(([property, value]) => {
// @ts-expect-error
if (acc[property]) {
// @ts-expect-error
acc[property].push(value);
} else {
// @ts-expect-error
acc[property] = [value];
}
});
Expand Down
9 changes: 2 additions & 7 deletions src/modules/theme-store/components/BrowserSearchFields.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useEffect, useMemo } from "react";
import {
useThemeBrowserSharedAction,
useThemeBrowserSharedValue,
Expand All @@ -23,9 +23,6 @@ export function BrowserSearchFields() {
const setSearchOpts = useThemeBrowserStoreAction("setSearchOpts");
const refreshThemes = useThemeBrowserStoreAction("refreshThemes");

const targetOverride = useThemeBrowserSharedValue("targetOverride");
const setTargetOverride = useThemeBrowserSharedAction("setTargetOverride");

const browserCardSize = useThemeBrowserSharedValue("browserCardSize");
const setBrowserCardSize = useThemeBrowserSharedAction("setBrowserCardSize");

Expand Down Expand Up @@ -65,12 +62,10 @@ export function BrowserSearchFields() {
menuLabel="Filter"
rgOptions={formattedFilters}
strDefaultLabel="All"
selectedOption={targetOverride ?? searchOpts.filters}
selectedOption={searchOpts.filters}
onChange={(value) => {
// When you select a new target, remove the global override
const newSearchOpts = { ...searchOpts, filters: value.data, page: 1 };
void setSearchOpts(newSearchOpts);
setTargetOverride(null);
}}
/>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/modules/theme-store/context/ThemeBrowserSharedStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export type ColumnNumbers = 3 | 4 | 5;

interface ThemeBrowserSharedStoreValues {
browserCardSize: ColumnNumbers;
currentTab: string;
targetOverride: string | null;
}

interface ThemeBrowserSharedStoreActions {
setBrowserCardSize: (value: ColumnNumbers) => void;
setCurrentTab: (value: string) => void;
setTargetOverride: (value: string | null) => void;
}

Expand All @@ -21,8 +23,10 @@ interface IThemeBrowserSharedStore
export const themeBrowserSharedStore = createStore<IThemeBrowserSharedStore>((set) => {
return {
browserCardSize: 3,
currentTab: "bpm-themes",
targetOverride: "",
setBrowserCardSize: (value: ColumnNumbers) => set({ browserCardSize: value }),
setCurrentTab: (value: string) => set({ currentTab: value }),
setTargetOverride: (value: string | null) => set({ targetOverride: value }),
};
});
Expand Down
35 changes: 20 additions & 15 deletions src/modules/theme-store/context/ThemeBrowserStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ThemeBrowserStoreValues {
interface ThemeBrowserStoreActions {
initializeStore: () => Promise<void>;
getFilters: () => Promise<void>;
setSearchOpts: (searchOpts: ThemeQueryRequest) => Promise<void>;
setSearchOpts: (searchOpts: ThemeQueryRequest, forceRefresh?: boolean) => Promise<void>;
refreshThemes: () => Promise<void>;
getThemes: () => Promise<void>;
}
Expand Down Expand Up @@ -88,14 +88,22 @@ export function ThemeBrowserStoreProvider({
initializeStore: async () => {
try {
await get().getFilters();
await get().getThemes();

// This ensures that it actually fetches new themed when you click on a forced target
themeBrowserSharedStore.subscribe((state, prevState) => {
if (state.targetOverride !== prevState.targetOverride) {
get().getThemes();
}
});
// When you navigate to the expanded view and back, it re-loads the page, which re-runs this, so we can just check if there is a target override
const { targetOverride } = getThemeBrowserSharedState();
if (targetOverride) {
get().setSearchOpts(
{
...get().searchOpts,
filters: targetOverride,
page: 1,
},
true
);
themeBrowserSharedStore.setState({ targetOverride: null });
} else {
await get().getThemes();
}
} catch (error) {}
},
getFilters: async () => {
Expand All @@ -117,30 +125,27 @@ export function ThemeBrowserStoreProvider({
}
} catch (error) {}
},
setSearchOpts: async (searchOpts, options: { dontResetPage?: boolean } = {}) => {
setSearchOpts: async (searchOpts, forceRefresh?: boolean) => {
const { searchOpts: prevSearchOpts, themes, getThemes } = get();
set({ searchOpts, prevSearchOpts });

if (!isEqual(prevSearchOpts, searchOpts) || themes.length === 0) {
if (!isEqual(prevSearchOpts, searchOpts) || forceRefresh || themes.length === 0) {
await getThemes();
}
},
refreshThemes: async () => {
// setSearchOpts calls get
const { searchOpts, setSearchOpts } = get();
await setSearchOpts({ ...searchOpts, page: 1 });
await setSearchOpts({ ...searchOpts, page: 1 }, true);
},
getThemes: async () => {
set({ loading: true });
try {
const { searchOpts } = get();
const { targetOverride } = getThemeBrowserSharedState();
const formattedSearchOpts = { ...searchOpts };
targetOverride && (formattedSearchOpts.filters = targetOverride);

const { apiFetch } = getCSSLoaderState();
const response = await apiFetch<ThemeQueryResponse>(
`${themePath}?${generateParamStr(formattedSearchOpts, themeType)}`,
`${themePath}?${generateParamStr(searchOpts, themeType)}`,
{},
requiresAuth
);
Expand Down
10 changes: 7 additions & 3 deletions src/modules/theme-store/pages/ThemeStoreRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Tabs } from "@decky/ui";
import { ThemeBrowserPage, ThemeCardCSSVariableProvider } from "../components";
import { ThemeBrowserStoreProvider } from "../context";
import { useState } from "react";
import {
ThemeBrowserStoreProvider,
useThemeBrowserSharedAction,
useThemeBrowserSharedValue,
} from "../context";

export function ThemeStoreRouter() {
const [currentTab, setCurrentTab] = useState("allthemes");
const currentTab = useThemeBrowserSharedValue("currentTab");
const setCurrentTab = useThemeBrowserSharedAction("setCurrentTab");
return (
<div className="cl_fullscreenroute_container">
<ThemeCardCSSVariableProvider />
Expand Down

0 comments on commit a0bcbe6

Please sign in to comment.