Wipe in-memory state after clearing cache
This commit is contained in:
parent
164ea113f7
commit
52de4718cb
23
src/admin/ClearCacheButton.tsx
Normal file
23
src/admin/ClearCacheButton.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
||||||
|
import { syncCacheAction } from '@/photo/actions';
|
||||||
|
import { useMoreComponentsState } from '@/state/MoreComponentsState';
|
||||||
|
import { BiTrash } from 'react-icons/bi';
|
||||||
|
|
||||||
|
export default function ClearCacheButton() {
|
||||||
|
const {
|
||||||
|
clearMoreComponentsState,
|
||||||
|
} = useMoreComponentsState();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={syncCacheAction}>
|
||||||
|
<SubmitButtonWithStatus
|
||||||
|
icon={<BiTrash />}
|
||||||
|
onFormSubmit={clearMoreComponentsState}
|
||||||
|
>
|
||||||
|
Clear Cache
|
||||||
|
</SubmitButtonWithStatus>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,9 +1,7 @@
|
|||||||
|
import ClearCacheButton from '@/admin/ClearCacheButton';
|
||||||
import InfoBlock from '@/components/InfoBlock';
|
import InfoBlock from '@/components/InfoBlock';
|
||||||
import SiteGrid from '@/components/SiteGrid';
|
import SiteGrid from '@/components/SiteGrid';
|
||||||
import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
|
||||||
import { syncCacheAction } from '@/photo/actions';
|
|
||||||
import SiteChecklist from '@/site/SiteChecklist';
|
import SiteChecklist from '@/site/SiteChecklist';
|
||||||
import { BiTrash } from 'react-icons/bi';
|
|
||||||
|
|
||||||
export default async function AdminConfigurationPage() {
|
export default async function AdminConfigurationPage() {
|
||||||
return (
|
return (
|
||||||
@ -14,13 +12,7 @@ export default async function AdminConfigurationPage() {
|
|||||||
<div className="flex-grow">
|
<div className="flex-grow">
|
||||||
App Configuration
|
App Configuration
|
||||||
</div>
|
</div>
|
||||||
<form action={syncCacheAction}>
|
<ClearCacheButton />
|
||||||
<SubmitButtonWithStatus
|
|
||||||
icon={<BiTrash />}
|
|
||||||
>
|
|
||||||
Clear Cache
|
|
||||||
</SubmitButtonWithStatus>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<InfoBlock>
|
<InfoBlock>
|
||||||
<SiteChecklist />
|
<SiteChecklist />
|
||||||
|
|||||||
@ -12,6 +12,7 @@ interface Props extends HTMLProps<HTMLButtonElement> {
|
|||||||
spinnerColor?: SpinnerColor
|
spinnerColor?: SpinnerColor
|
||||||
onFormStatusChange?: (pending: boolean) => void
|
onFormStatusChange?: (pending: boolean) => void
|
||||||
onFormSubmitToastMessage?: string
|
onFormSubmitToastMessage?: string
|
||||||
|
onFormSubmit?: () => void
|
||||||
primary?: boolean
|
primary?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ export default function SubmitButtonWithStatus({
|
|||||||
spinnerColor,
|
spinnerColor,
|
||||||
onFormStatusChange,
|
onFormStatusChange,
|
||||||
onFormSubmitToastMessage,
|
onFormSubmitToastMessage,
|
||||||
|
onFormSubmit,
|
||||||
children,
|
children,
|
||||||
disabled,
|
disabled,
|
||||||
className,
|
className,
|
||||||
@ -39,9 +41,10 @@ export default function SubmitButtonWithStatus({
|
|||||||
onFormSubmitToastMessage
|
onFormSubmitToastMessage
|
||||||
) {
|
) {
|
||||||
toastSuccess(onFormSubmitToastMessage);
|
toastSuccess(onFormSubmitToastMessage);
|
||||||
|
onFormSubmit?.();
|
||||||
}
|
}
|
||||||
pendingPrevious.current = pending;
|
pendingPrevious.current = pending;
|
||||||
}, [pending, onFormSubmitToastMessage]);
|
}, [pending, onFormSubmitToastMessage, onFormSubmit]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onFormStatusChange?.(pending);
|
onFormStatusChange?.(pending);
|
||||||
|
|||||||
@ -29,11 +29,16 @@ export default function MoreComponentsProvider({
|
|||||||
}));
|
}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const clearMoreComponentsState = useCallback(() => {
|
||||||
|
setState(MORE_COMPONENTS_INITIAL_STATE);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MoreComponentsContext.Provider
|
<MoreComponentsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
state,
|
state,
|
||||||
setStateForKey,
|
setStateForKey,
|
||||||
|
clearMoreComponentsState,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export interface MoreComponentsContext {
|
|||||||
key: MoreComponentsKey,
|
key: MoreComponentsKey,
|
||||||
state: MoreComponentsStateForKeyArgument,
|
state: MoreComponentsStateForKeyArgument,
|
||||||
) => void
|
) => void
|
||||||
|
clearMoreComponentsState: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MORE_COMPONENTS_INITIAL_STATE: MoreComponentsState = {
|
export const MORE_COMPONENTS_INITIAL_STATE: MoreComponentsState = {
|
||||||
@ -47,6 +48,7 @@ export const MoreComponentsContext =
|
|||||||
createContext<MoreComponentsContext>({
|
createContext<MoreComponentsContext>({
|
||||||
state: MORE_COMPONENTS_INITIAL_STATE,
|
state: MORE_COMPONENTS_INITIAL_STATE,
|
||||||
setStateForKey: () => {},
|
setStateForKey: () => {},
|
||||||
|
clearMoreComponentsState: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useMoreComponentsState = () =>
|
export const useMoreComponentsState = () =>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user