mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-03 03:33:16 +03:00
refresh sessions on vbranch updates
This commit is contained in:
parent
1a5cda3799
commit
5581a476e9
@ -1,12 +1,13 @@
|
||||
import { Session, listSessions, subscribeToSessions } from '$lib/backend/sessions';
|
||||
import { asyncWritable, get, type Loadable, type WritableLoadable } from '@square/svelte-store';
|
||||
import type { CustomStore } from '$lib/vbranches/types';
|
||||
import { asyncWritable, get } from '@square/svelte-store';
|
||||
|
||||
export function getSessionStore(projectId: string): Loadable<Session[]> {
|
||||
export function getSessionStore(projectId: string): CustomStore<Session[]> {
|
||||
const store = asyncWritable(
|
||||
[],
|
||||
async () => await listSessions(projectId),
|
||||
async (data) => data,
|
||||
{ trackState: true },
|
||||
{ reloadable: true, trackState: true },
|
||||
(set) => {
|
||||
const unsubscribe = subscribeToSessions(projectId, (session) => {
|
||||
const oldValue = get(store)?.filter((b) => b.id != session.id);
|
||||
@ -21,6 +22,6 @@ export function getSessionStore(projectId: string): Loadable<Session[]> {
|
||||
});
|
||||
return () => unsubscribe();
|
||||
}
|
||||
) as WritableLoadable<Session[]>;
|
||||
) as CustomStore<Session[]>;
|
||||
return store;
|
||||
}
|
||||
|
@ -8,20 +8,24 @@ import type {
|
||||
} from './types';
|
||||
import * as toasts from '$lib/utils/toasts';
|
||||
import { invoke } from '$lib/backend/ipc';
|
||||
import type { Session } from '$lib/backend/sessions';
|
||||
|
||||
export class BranchController {
|
||||
constructor(
|
||||
readonly projectId: string,
|
||||
readonly virtualBranchStore: VirtualBranchStore<Branch>,
|
||||
readonly remoteBranchStore: CustomStore<RemoteBranch[] | undefined>,
|
||||
readonly targetBranchStore: CustomStore<BaseBranch | undefined>
|
||||
readonly targetBranchStore: CustomStore<BaseBranch | undefined>,
|
||||
readonly sessionsStore: CustomStore<Session[] | undefined>
|
||||
) {}
|
||||
|
||||
async setTarget(branch: string) {
|
||||
try {
|
||||
await invoke<BaseBranch>('set_base_branch', { projectId: this.projectId, branch });
|
||||
await this.sessionsStore.reload();
|
||||
await this.targetBranchStore.reload();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
toasts.error('Failed to set base branch');
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ export const load: LayoutLoad = async ({ params }) => {
|
||||
projectId,
|
||||
vbranchStore,
|
||||
remoteBranchStore,
|
||||
baseBranchStore
|
||||
baseBranchStore,
|
||||
sessionsStore
|
||||
);
|
||||
|
||||
const githubContextStore = getGitHubContextStore(userStore, baseBranchStore);
|
||||
|
Loading…
Reference in New Issue
Block a user