mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 21:51:14 -05:00
Implement API improvements Phases 1-4
This commit is contained in:
@@ -166,13 +166,28 @@ export function useProfileActivity(
|
||||
photoItemsMap.get(item.photo_submission_id)!.push(item);
|
||||
});
|
||||
|
||||
interface DatabaseEntity {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
const entityMap = new Map<string, EntityData>([
|
||||
...parks.map((p: any): [string, EntityData] => [p.id, p]),
|
||||
...rides.map((r: any): [string, EntityData] => [r.id, r])
|
||||
...parks.map((p: DatabaseEntity): [string, EntityData] => [p.id, p]),
|
||||
...rides.map((r: DatabaseEntity): [string, EntityData] => [r.id, r])
|
||||
]);
|
||||
|
||||
interface PhotoSubmissionWithAllFields {
|
||||
id: string;
|
||||
photo_count?: number;
|
||||
photo_preview?: string;
|
||||
entity_type?: string;
|
||||
entity_id?: string;
|
||||
content?: unknown;
|
||||
}
|
||||
|
||||
// Enrich submissions
|
||||
photoSubmissions.forEach((sub: any) => {
|
||||
photoSubmissions.forEach((sub: PhotoSubmissionWithAllFields) => {
|
||||
const photoSub = photoSubMap.get(sub.id);
|
||||
if (photoSub) {
|
||||
const items = photoItemsMap.get(photoSub.id) || [];
|
||||
|
||||
@@ -64,18 +64,26 @@ export function useProfileLocationMutation() {
|
||||
await queryClient.cancelQueries({ queryKey: ['profile', user?.id] });
|
||||
|
||||
// Snapshot current value
|
||||
const previousProfile = queryClient.getQueryData(['profile', user?.id]);
|
||||
interface Profile {
|
||||
personal_location?: string;
|
||||
home_park_id?: string;
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
const previousProfile = queryClient.getQueryData<Profile>(['profile', user?.id]);
|
||||
|
||||
// Optimistically update cache
|
||||
if (previousProfile) {
|
||||
queryClient.setQueryData(['profile', user?.id], (old: any) => ({
|
||||
...old,
|
||||
personal_location: newData.personal_location,
|
||||
home_park_id: newData.home_park_id,
|
||||
timezone: newData.timezone,
|
||||
preferred_language: newData.preferred_language,
|
||||
preferred_pronouns: newData.preferred_pronouns,
|
||||
}));
|
||||
queryClient.setQueryData<Profile>(['profile', user?.id], (old) =>
|
||||
old ? {
|
||||
...old,
|
||||
personal_location: newData.personal_location,
|
||||
home_park_id: newData.home_park_id,
|
||||
timezone: newData.timezone,
|
||||
preferred_language: newData.preferred_language,
|
||||
preferred_pronouns: newData.preferred_pronouns,
|
||||
} : old
|
||||
);
|
||||
}
|
||||
|
||||
return { previousProfile };
|
||||
|
||||
@@ -37,14 +37,20 @@ export function useProfileUpdateMutation() {
|
||||
// Cancel outgoing refetches
|
||||
await queryClient.cancelQueries({ queryKey: ['profile', userId] });
|
||||
|
||||
interface Profile {
|
||||
display_name?: string;
|
||||
bio?: string;
|
||||
location_id?: string;
|
||||
website?: string;
|
||||
}
|
||||
|
||||
// Snapshot previous value
|
||||
const previousProfile = queryClient.getQueryData(['profile', userId]);
|
||||
const previousProfile = queryClient.getQueryData<Profile>(['profile', userId]);
|
||||
|
||||
// Optimistically update
|
||||
queryClient.setQueryData(['profile', userId], (old: any) => ({
|
||||
...old,
|
||||
...updates,
|
||||
}));
|
||||
queryClient.setQueryData<Profile>(['profile', userId], (old) =>
|
||||
old ? { ...old, ...updates } : old
|
||||
);
|
||||
|
||||
return { previousProfile, userId };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user