Skip to content

Commit

Permalink
REFACTOR theme switching on detail pages
Browse files Browse the repository at this point in the history
  • Loading branch information
lencodes committed Nov 21, 2023
1 parent 36238fa commit 60778f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pwa/src/hooks/openWoo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const useOpenWoo = (queryClient: QueryClient) => {

const getAll = (filters: IFiltersContext, currentPage: number, limit: number) =>
useQuery<any, Error>(
["OpenWoo", filters, currentPage, limit],
["OpenWoo", filters, currentPage, limit, window.sessionStorage.getItem("OIDN_NUMBER")],
() => API?.OpenWoo.getAll(filters, currentPage, limit),
{
onError: (error) => {
Expand All @@ -19,13 +19,17 @@ export const useOpenWoo = (queryClient: QueryClient) => {
);

const getOne = (requestId: string) =>
useQuery<any, Error>(["OpenWoo", requestId], () => API?.OpenWoo.getOne(requestId), {
initialData: () => queryClient.getQueryData<any[]>("OpenWoo")?.find((_OpenWoo) => _OpenWoo.id === requestId),
onError: (error) => {
throw new Error(error.message);
useQuery<any, Error>(
["OpenWoo", requestId, window.sessionStorage.getItem("OIDN_NUMBER")],
() => API?.OpenWoo.getOne(requestId),
{
initialData: () => queryClient.getQueryData<any[]>("OpenWoo")?.find((_OpenWoo) => _OpenWoo.id === requestId),
onError: (error) => {
throw new Error(error.message);
},
enabled: !!requestId,
},
enabled: !!requestId,
});
);

return { getAll, getOne };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SelectSingle } from "@conduction/components";
import { useForm } from "react-hook-form";
import { availableThemes } from "../../../services/getConfig";
import { useEnvironment } from "../../../hooks/useEnvironment";
import { navigate } from "gatsby";

export const ThemeSwitcherTopBar: React.FC = () => {
const { initiateFromJSON } = useEnvironment();
Expand All @@ -30,6 +31,8 @@ export const ThemeSwitcherTopBar: React.FC = () => {
React.useEffect(() => {
if (!watchTheme) return;

navigate("/");

initiateFromJSON(watchTheme.value);
}, [watchTheme]);

Expand Down

0 comments on commit 60778f8

Please sign in to comment.