From 8c7c82a09378760340d80a23ac99f61a40e59c4f Mon Sep 17 00:00:00 2001 From: aegroto Date: Wed, 20 Nov 2024 14:11:58 +0100 Subject: [PATCH] chore: territories refetched on nsfwMode change --- components/sub-select.js | 15 +++++++++------ fragments/users.js | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/sub-select.js b/components/sub-select.js index d06c9d703..dfb3d27e5 100644 --- a/components/sub-select.js +++ b/components/sub-select.js @@ -5,6 +5,7 @@ import { EXTRA_LONG_POLL_INTERVAL, SSR } from '@/lib/constants' import { SUBS } from '@/fragments/subs' import { useQuery } from '@apollo/client' import styles from './sub-select.module.css' +import { useMe } from './me' export function SubSelectInitial ({ sub }) { const router = useRouter() @@ -27,6 +28,12 @@ export function useSubs ({ prependSubs = DEFAULT_PREPEND_SUBS, sub, filterSubs = nextFetchPolicy: 'cache-and-network' }) + const { me } = useMe() + + useEffect(() => { + refetch() + }, [me.privates?.nsfwMode]) + const [subs, setSubs] = useState([ ...prependSubs.filter(s => s !== sub), ...(sub ? [sub] : []), @@ -45,12 +52,12 @@ export function useSubs ({ prependSubs = DEFAULT_PREPEND_SUBS, sub, filterSubs = ...appendSubs]) }, [data]) - return [subs, refetch] + return subs } export default function SubSelect ({ prependSubs, sub, onChange, size, appendSubs, filterSubs, className, ...props }) { const router = useRouter() - const [subs, refetchSubs] = useSubs({ prependSubs, sub, filterSubs, appendSubs }) + const subs = useSubs({ prependSubs, sub, filterSubs, appendSubs }) const valueProps = props.noForm ? { value: sub @@ -63,10 +70,6 @@ export default function SubSelect ({ prependSubs, sub, onChange, size, appendSub // to display the correct sub name in the sub selector const subItems = !sub || subs.find((s) => s === sub) ? subs : [sub].concat(subs) - useEffect(() => { - refetchSubs() - }, []) - return (