Skip to content

Commit d03c9c1

Browse files
committed
Refetch github/gitlab on focus & reconnect
1 parent e435b9a commit d03c9c1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

apps/desktop/src/lib/state/clientState.svelte.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { tauriBaseQuery } from '$lib/state/backendQuery';
33
import { butlerModule } from '$lib/state/butlerModule';
44
import { ReduxTag } from '$lib/state/tags';
55
import { uiStatePersistConfig, uiStateSlice } from '$lib/state/uiState.svelte';
6+
import { mergeUnlisten } from '@gitbutler/ui/utils/mergeUnlisten';
67
import { combineReducers, configureStore } from '@reduxjs/toolkit';
7-
import { buildCreateApi, coreModule, type RootState } from '@reduxjs/toolkit/query';
8+
import { buildCreateApi, coreModule, setupListeners, type RootState } from '@reduxjs/toolkit/query';
89
import { FLUSH, PAUSE, PERSIST, persistReducer, PURGE, REGISTER, REHYDRATE } from 'redux-persist';
910
import persistStore from 'redux-persist/lib/persistStore';
1011
import type { Tauri } from '$lib/backend/tauri';
@@ -71,13 +72,17 @@ export class ClientState {
7172
githubApi: this.githubApi,
7273
gitlabApi: this.gitlabApi
7374
});
75+
setupListeners(this.store.dispatch);
7476
this.dispatch = this.store.dispatch;
7577
this.rootState = this.store.getState();
7678

7779
$effect(() =>
78-
this.store.subscribe(() => {
79-
this.rootState = this.store.getState();
80-
})
80+
mergeUnlisten(
81+
this.store.subscribe(() => {
82+
this.rootState = this.store.getState();
83+
}),
84+
setupListeners(this.store.dispatch)
85+
)
8186
);
8287
}
8388
}
@@ -162,6 +167,8 @@ export function createGitHubApi(butlerMod: ReturnType<typeof butlerModule>) {
162167
reducerPath: 'github',
163168
tagTypes: Object.values(ReduxTag),
164169
baseQuery: tauriBaseQuery,
170+
refetchOnFocus: true,
171+
refetchOnReconnect: true,
165172
endpoints: (_) => {
166173
return {};
167174
}
@@ -178,6 +185,8 @@ export function createGitLabApi(butlerMod: ReturnType<typeof butlerModule>) {
178185
reducerPath: 'gitlab',
179186
tagTypes: Object.values(ReduxTag),
180187
baseQuery: tauriBaseQuery,
188+
refetchOnFocus: true,
189+
refetchOnReconnect: true,
181190
endpoints: (_) => {
182191
return {};
183192
}

0 commit comments

Comments
 (0)