subscribe to fetch events

This commit is contained in:
Nikita Galaiko 2023-07-03 16:05:08 +02:00
parent f83df47b77
commit ef5ce12fb5
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,10 @@
import { listen } from '$lib/ipc';
export function subscribe(
params: { projectId: string },
callback: (params: { projectId: string }) => Promise<void> | void
) {
return listen<{ head: string }>(`project://${params.projectId}/git/fetch`, (event) =>
callback({ ...params, ...event.payload })
);
}

View File

@ -5,6 +5,7 @@ export type { Activity } from './activities';
export * as heads from './heads';
export * as diffs from './diffs';
export * as indexes from './indexes';
export * as fetches from './fetches';
import { invoke } from '$lib/ipc';

View File

@ -1,4 +1,5 @@
import { invoke } from '$lib/ipc';
import { git } from '$lib/api/ipc';
import type { BranchData } from './types';
import { writable, type Loadable } from 'svelte-loadable-store';
import { error } from '$lib/toasts';
@ -30,11 +31,11 @@ export function getRemoteBranches(
function createWriteable(projectId: string) {
return writable(getRemoteBranchesData(projectId), (set) => {
setInterval(() => {
git.fetches.subscribe({ projectId }, () => {
getRemoteBranchesData(projectId).then((branches) => {
set(sortBranchData(branches));
});
}, 60000); // poll since we don't have a way to subscribe to changes
});
});
}