fix refresh button and add backend sync logic#35
Conversation
isLoading is only true on the initial query load (no cached data). During refetch(), React Query sets isFetching=true but isLoading stays false, so the refresh button had no visual feedback after first load. Fixes #34 Co-authored-by: Jagrat Rao <jagrat7@users.noreply.github.com>
|
@claude that doesnt explain why the user was reporting stale data for his wallpapers |
|
Claude finished @jagrat7's task in 1m 29s —— View job Analysis: Stale Wallpaper DataGood question — the PR only fixes the visual feedback. The stale data issue is a separate problem rooted in the backend cache not being bypassed on manual refresh. Here's what's happening: The Root Cause
private wallpaperCache: Wallpaper[] | null = null
private cacheTimestamp: number | null = null
const CACHE_TTL = 5 * 60 * 1000 // 5 minutesThe async getWallpapers(options: GetWallpapersOptions = {}): Promise<Wallpaper[]> {
const { search, refresh = false } = options
if (refresh || !this.wallpaperCache || cacheExpired) {
this.wallpaperCache = await this.scanWallpapers()
}
}The tRPC procedure also exposes this flag: // src/main/trpc/routes/wallpaper.ts
getWallpapers: trpc.procedure
.input(z.object({
search: z.string().optional(),
refresh: z.boolean().default(false), // ← exists but unused
}))
.query(async ({ input }) => wallpaperService.getWallpapers(input))However, the frontend never passes The FixIn // use-wallpapers.ts
const [forceRefresh, setForceRefresh] = useState(false)
const { data, isFetching, refetch } = trpc.wallpaper.getWallpapers.useQuery(
{ search: debouncedSearch, refresh: forceRefresh },
{ ... }
)
const refresh = useCallback(async () => {
setForceRefresh(true)
await refetch()
setForceRefresh(false)
}, [refetch])Or more simply, pass Additional Contributing Factors
|
… into claude/issue-34-20260323-0052
…ry changes Implemented fs.watch on workshop directories with 1.5s debounce to automatically invalidate the wallpaper cache when files change. Replaced manual refresh parameter with invalidateCache mutation that triggers a fresh scan on next query. This enables automatic detection of newly added/removed wallpapers without requiring manual refresh.
…atic cache updates Implemented an event-based invalidation system to automatically refresh React Query caches when backend data changes. Created invalidationService with EventEmitter to broadcast invalidation events, exposed via tRPC subscription, and added useInvalidation hook to listen for events and invalidate corresponding queries. Integrated emissions in wallpaper file watcher and compatibility override updates. Simplified
Renamed the 'start' script to 'dev' in package.json to better align with common development conventions. Updated all references in CONTRIBUTING.md to use 'bun dev' instead of 'bun start'.
…cks and wallpaper cache invalidation Decreased compatibility service cleanup timeout from 3000ms to 2500ms and wallpaper filesystem watcher debounce from 1500ms to 500ms to improve UI responsiveness when detecting changes.
…t compatibility detection Extended the timeout before classifying wallpapers as perfectly compatible to reduce false positives from delayed stderr output.
Fix for issue #34 where the Refresh button had no visual feedback after the initial load.
isFetchingfromuseWallpapersand passing it to theGridHeaderinstead ofisLoading.