fix(spotlight): remove all non-null assertions to pass oxlint
- Refactor groupDispatchers to accept userId as a parameter instead of closing over nullable userId - Replace mutationGroup! with a guard clause - Use optional chaining for preferenceChildrenOptionsByKey lookup with fallback
This commit is contained in:
2 files changed
+13
-11
No files matched your search
@@ -65,7 +65,8 @@ export const preferencesGroup = createGroup<PreferencesGroupOption>({
|
|||||||
useInteraction: (option) => ({
|
useInteraction: (option) => ({
|
||||||
type: "children",
|
type: "children",
|
||||||
...(option.preferenceKey
|
...(option.preferenceKey
|
||||||
? preferenceChildrenOptionsByKey[option.preferenceKey as keyof typeof preferenceChildrenOptionsByKey]!({})
|
? (preferenceChildrenOptionsByKey[option.preferenceKey as keyof typeof preferenceChildrenOptionsByKey]?.({}) ??
|
||||||
|
settingsChildrenOptions({}))
|
||||||
: settingsChildrenOptions({})),
|
: settingsChildrenOptions({})),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -100,22 +100,22 @@ export const useUserPreferences = () => {
|
|||||||
const pick = (field: UserPreferenceKey, changedKey: UserPreferenceKey, value: unknown) =>
|
const pick = (field: UserPreferenceKey, changedKey: UserPreferenceKey, value: unknown) =>
|
||||||
field === changedKey ? value : getEffective(field);
|
field === changedKey ? value : getEffective(field);
|
||||||
|
|
||||||
const groupDispatchers: Record<string, (key: UserPreferenceKey, value: unknown) => Promise<unknown>> = {
|
const groupDispatchers: Record<string, (uid: string, key: UserPreferenceKey, value: unknown) => Promise<unknown>> = {
|
||||||
searchPreferences: (key, value) =>
|
searchPreferences: (uid, key, value) =>
|
||||||
searchMutation.mutateAsync({
|
searchMutation.mutateAsync({
|
||||||
userId: userId!,
|
userId: uid,
|
||||||
defaultSearchEngineId: pick("defaultSearchEngineId", key, value) as string | null,
|
defaultSearchEngineId: pick("defaultSearchEngineId", key, value) as string | null,
|
||||||
openInNewTab: pick("openSearchInNewTab", key, value) as boolean,
|
openInNewTab: pick("openSearchInNewTab", key, value) as boolean,
|
||||||
ddgBangsEnabled: pick("ddgBangs", key, value) as boolean,
|
ddgBangsEnabled: pick("ddgBangs", key, value) as boolean,
|
||||||
}),
|
}),
|
||||||
homeBoards: (key, value) =>
|
homeBoards: (uid, key, value) =>
|
||||||
homeBoardsMutation.mutateAsync({
|
homeBoardsMutation.mutateAsync({
|
||||||
userId: userId!,
|
userId: uid,
|
||||||
homeBoardId: pick("homeBoardId", key, value) as string | null,
|
homeBoardId: pick("homeBoardId", key, value) as string | null,
|
||||||
mobileHomeBoardId: pick("mobileHomeBoardId", key, value) as string | null,
|
mobileHomeBoardId: pick("mobileHomeBoardId", key, value) as string | null,
|
||||||
}),
|
}),
|
||||||
firstDayOfWeek: (_key, value) => firstDayMutation.mutateAsync({ id: userId!, firstDayOfWeek: value as DayOfWeek }),
|
firstDayOfWeek: (uid, _key, value) => firstDayMutation.mutateAsync({ id: uid, firstDayOfWeek: value as DayOfWeek }),
|
||||||
pingIconsEnabled: (_key, value) => pingMutation.mutateAsync({ id: userId!, pingIconsEnabled: value as boolean }),
|
pingIconsEnabled: (uid, _key, value) => pingMutation.mutateAsync({ id: uid, pingIconsEnabled: value as boolean }),
|
||||||
};
|
};
|
||||||
|
|
||||||
const groupPending: Record<string, boolean> = {
|
const groupPending: Record<string, boolean> = {
|
||||||
@@ -170,15 +170,16 @@ export const useUserPreferences = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const group = userPreferenceDefinitionByKey[key].mutationGroup!;
|
const group = userPreferenceDefinitionByKey[key].mutationGroup;
|
||||||
|
if (!group) return;
|
||||||
const dispatcher = groupDispatchers[group];
|
const dispatcher = groupDispatchers[group];
|
||||||
if (!dispatcher) return;
|
if (!dispatcher || !userId) return;
|
||||||
|
|
||||||
setOptimistic(key, value);
|
setOptimistic(key, value);
|
||||||
|
|
||||||
pendingRef.current[group] = true;
|
pendingRef.current[group] = true;
|
||||||
try {
|
try {
|
||||||
await dispatcher(key, value);
|
await dispatcher(userId, key, value);
|
||||||
} catch {
|
} catch {
|
||||||
clearOptimistic(getGroupKeys(key));
|
clearOptimistic(getGroupKeys(key));
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
|
|||||||
Reference in new issue
Block a user