👁️
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix list optimistic updates

+17 -10
+17 -10
src/lib/collection-list-queries.ts
··· 5 5 6 6 import type { Did } from "@atcute/lexicons"; 7 7 import { 8 + type InfiniteData, 8 9 infiniteQueryOptions, 9 10 queryOptions, 10 11 useQueryClient, ··· 234 235 rkey, 235 236 ]); 236 237 237 - const previousLists = queryClient.getQueryData<{ 238 - records: CollectionListRecord[]; 239 - }>(["collection-lists", did]); 238 + type ListPage = { records: CollectionListRecord[]; cursor?: string }; 239 + const previousLists = queryClient.getQueryData<InfiniteData<ListPage>>([ 240 + "collection-lists", 241 + did, 242 + ]); 240 243 241 244 queryClient.setQueryData<CollectionList>( 242 245 ["collection-list", did, rkey], ··· 244 247 ); 245 248 246 249 if (previousLists) { 247 - queryClient.setQueryData<{ records: CollectionListRecord[] }>( 250 + queryClient.setQueryData<InfiniteData<ListPage>>( 248 251 ["collection-lists", did], 249 252 { 250 253 ...previousLists, 251 - records: previousLists.records.map((record) => 252 - record.uri.endsWith(`/${rkey}`) 253 - ? { ...record, value: newList } 254 - : record, 255 - ), 254 + pages: previousLists.pages.map((page) => ({ 255 + ...page, 256 + records: page.records.map((record) => 257 + record.uri.endsWith(`/${rkey}`) 258 + ? { ...record, value: newList } 259 + : record, 260 + ), 261 + })), 256 262 }, 257 263 ); 258 264 } ··· 267 273 ); 268 274 } 269 275 if (context?.previousLists) { 270 - queryClient.setQueryData<{ records: CollectionListRecord[] }>( 276 + type ListPage = { records: CollectionListRecord[]; cursor?: string }; 277 + queryClient.setQueryData<InfiniteData<ListPage>>( 271 278 ["collection-lists", did], 272 279 context.previousLists, 273 280 );