Chilled color scheme as swappable tokens, Fredoka wordmark with a configurable tagline, genre categories, search and random hotkeys. The homepage offers a Game of the Day, a Time Machine with a date picker, recently played games and Flashpoint playlist shelves. Mature games are hidden unless opted in from the user menu, stored in the browser and the account. Browse lists default to a seeded shuffle and accept release date ranges.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { usersApi } from '@/lib/api';
|
|
import { logger } from '@/lib/logger';
|
|
import { useAuthStore } from '@/store/auth';
|
|
import { SHOW_MATURE_SETTING, useMatureStore } from '@/store/mature';
|
|
|
|
/** Adopts the signed-in account's mature content preference, or saves this browser's to it. */
|
|
export function useMatureSync(): void {
|
|
const userId = useAuthStore((state) =>
|
|
state.isAuthenticated && !state.isGuest ? state.user?.id : undefined
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (userId === undefined) return;
|
|
let cancelled = false;
|
|
usersApi
|
|
.getAllSettings()
|
|
.then((settings) => {
|
|
if (cancelled) return;
|
|
const saved = settings[SHOW_MATURE_SETTING];
|
|
if (saved === undefined) {
|
|
if (useMatureStore.getState().showMature) useMatureStore.getState().setShowMature(true);
|
|
return;
|
|
}
|
|
useMatureStore.setState({ showMature: saved === '1' });
|
|
})
|
|
.catch((error) => logger.debug('Failed to load mature preference:', error));
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [userId]);
|
|
}
|