Skip to content

Commit

Permalink
chore: territories refetched on nsfwMode change
Browse files Browse the repository at this point in the history
  • Loading branch information
aegroto committed Nov 20, 2024
1 parent 343f1fb commit 8c7c82a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions components/sub-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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] : []),
Expand All @@ -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
Expand All @@ -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 (
<Select
onChange={onChange || ((_, e) => {
Expand Down
1 change: 1 addition & 0 deletions fragments/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ${STREAK_FIELDS}
imgproxyOnly
showImagesAndVideos
nostrCrossposting
nsfwMode
sats
tipDefault
tipRandom
Expand Down

0 comments on commit 8c7c82a

Please sign in to comment.