atmosphere explorer pdsls.dev
atproto tool typescript

add limit parameter

juli.ee 27210d9f b23dcadc

verified
Changed files
+15 -4
src
+1
src/utils/route-cache.ts
··· 5 5 cursor: string | undefined; 6 6 scrollY: number; 7 7 reverse: boolean; 8 + limit: number; 8 9 } 9 10 10 11 type RouteCache = Record<string, CollectionCacheEntry>;
+14 -4
src/views/collection.tsx
··· 40 40 toDelete: boolean; 41 41 } 42 42 43 - const LIMIT = 100; 43 + const DEFAULT_LIMIT = 100; 44 44 45 45 const RecordLink = (props: { record: AtprotoRecord }) => { 46 46 const [hover, setHover] = createSignal(false); ··· 98 98 const [batchDelete, setBatchDelete] = createSignal(false); 99 99 const [lastSelected, setLastSelected] = createSignal<number>(); 100 100 const [reverse, setReverse] = createSignal(searchParams.reverse === "true"); 101 + const limit = () => { 102 + const limitParam = 103 + Array.isArray(searchParams.limit) ? searchParams.limit[0] : searchParams.limit; 104 + const paramLimit = parseInt(limitParam || ""); 105 + return !isNaN(paramLimit) && paramLimit > 0 && paramLimit <= 100 ? paramLimit : DEFAULT_LIMIT; 106 + }; 101 107 const [recreate, setRecreate] = createSignal(false); 102 108 const [openDelete, setOpenDelete] = createSignal(false); 103 109 const [restoredFromCache, setRestoredFromCache] = createSignal(false); ··· 113 119 setRecords(cached.records as AtprotoRecord[]); 114 120 setCursor(cached.cursor); 115 121 setReverse(cached.reverse); 116 - setSearchParams({ reverse: cached.reverse ? "true" : undefined }); 122 + setSearchParams({ 123 + reverse: cached.reverse ? "true" : undefined, 124 + limit: cached.limit !== DEFAULT_LIMIT ? cached.limit.toString() : undefined, 125 + }); 117 126 setRestoredFromCache(true); 118 127 requestAnimationFrame(() => { 119 128 window.scrollTo(0, cached.scrollY); ··· 131 140 cursor: cursor(), 132 141 scrollY: window.scrollY, 133 142 reverse: reverse(), 143 + limit: limit(), 134 144 }); 135 145 } else { 136 146 clearCollectionCache(cacheKey()); ··· 152 162 params: { 153 163 repo: did as ActorIdentifier, 154 164 collection: params.collection as `${string}.${string}.${string}`, 155 - limit: LIMIT, 165 + limit: limit(), 156 166 cursor: cursor(), 157 167 reverse: reverse(), 158 168 }, 159 169 }); 160 170 if (!res.ok) throw new Error(res.data.error); 161 - setCursor(res.data.records.length < LIMIT ? undefined : res.data.cursor); 171 + setCursor(res.data.records.length < limit() ? undefined : res.data.cursor); 162 172 const tmpRecords: AtprotoRecord[] = []; 163 173 res.data.records.forEach((record) => { 164 174 const rkey = record.uri.split("/").pop()!;