mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-30 20:09:50 +03:00
Clean up variable assigment
- just making the code more readable
This commit is contained in:
parent
e49bf7a4ef
commit
4f2dfca322
@ -1,4 +1,5 @@
|
||||
import { invoke } from '$lib/backend/ipc';
|
||||
import { observableToStore } from '$lib/rxjs/store';
|
||||
import * as toasts from '$lib/utils/toasts';
|
||||
import { RemoteBranch, RemoteBranchData } from '$lib/vbranches/types';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
@ -7,14 +8,15 @@ import {
|
||||
Observable,
|
||||
catchError,
|
||||
combineLatest,
|
||||
of,
|
||||
shareReplay,
|
||||
switchMap
|
||||
} from 'rxjs';
|
||||
import type { Readable } from 'svelte/store';
|
||||
|
||||
export class RemoteBranchService {
|
||||
branches: Readable<RemoteBranch[] | undefined>;
|
||||
branches$: Observable<RemoteBranch[]>;
|
||||
branchesError$ = new BehaviorSubject<any>(undefined);
|
||||
error: Readable<string | undefined>;
|
||||
private reload$ = new BehaviorSubject<void>(undefined);
|
||||
|
||||
constructor(
|
||||
@ -28,11 +30,11 @@ export class RemoteBranchService {
|
||||
shareReplay(1),
|
||||
catchError((e) => {
|
||||
console.error(e);
|
||||
this.branchesError$.next(e);
|
||||
toasts.error(`Failed load remote branches`);
|
||||
return of([]);
|
||||
throw e;
|
||||
})
|
||||
);
|
||||
[this.branches, this.error] = observableToStore(this.branches$);
|
||||
}
|
||||
|
||||
reload() {
|
||||
|
@ -21,13 +21,13 @@ import {
|
||||
startWith,
|
||||
Subject
|
||||
} from 'rxjs';
|
||||
import type { Readable } from 'svelte/store';
|
||||
import { writable, type Readable } from 'svelte/store';
|
||||
|
||||
export class VirtualBranchService {
|
||||
branches$: Observable<Branch[] | undefined>;
|
||||
stashedBranches$: Observable<Branch[] | undefined>;
|
||||
activeBranches$: Observable<Branch[] | undefined>;
|
||||
branchesError$ = new BehaviorSubject<any>(undefined);
|
||||
branchesError = writable<any>();
|
||||
private reload$ = new BehaviorSubject<void>(undefined);
|
||||
private fresh$ = new Subject<void>();
|
||||
|
||||
@ -62,7 +62,7 @@ export class VirtualBranchService {
|
||||
startWith(undefined),
|
||||
shareReplay(1),
|
||||
catchError((err) => {
|
||||
this.branchesError$.next(err);
|
||||
this.branchesError.set(err);
|
||||
return [];
|
||||
})
|
||||
);
|
||||
@ -77,7 +77,7 @@ export class VirtualBranchService {
|
||||
}
|
||||
|
||||
async reload() {
|
||||
this.branchesError$.next(undefined);
|
||||
this.branchesError.set(undefined);
|
||||
const fresh = firstValueFrom(
|
||||
this.fresh$.pipe(
|
||||
timeout(10000),
|
||||
|
@ -18,18 +18,20 @@
|
||||
|
||||
export let data: LayoutData;
|
||||
|
||||
$: vbranchService = data.vbranchService;
|
||||
$: branchesError$ = vbranchService.branchesError$;
|
||||
$: project$ = data.project$;
|
||||
$: projectId = data.projectId;
|
||||
$: baseBranchService = data.baseBranchService;
|
||||
$: baseBranch$ = baseBranchService.base$;
|
||||
$: baseError$ = baseBranchService.error$;
|
||||
$: gbBranchActive$ = data.gbBranchActive$;
|
||||
$: user$ = data.user$;
|
||||
$: branchService = data.branchService;
|
||||
$: branchController = data.branchController;
|
||||
$: ({
|
||||
vbranchService,
|
||||
project$,
|
||||
projectId,
|
||||
baseBranchService,
|
||||
gbBranchActive$,
|
||||
user$,
|
||||
branchService,
|
||||
branchController
|
||||
} = data);
|
||||
|
||||
$: branchesError = vbranchService.branchesError;
|
||||
$: baseBranch = baseBranchService.base;
|
||||
$: baseError = baseBranchService.error;
|
||||
|
||||
$: setContext(BranchController, branchController);
|
||||
$: setContext(BranchService, branchService);
|
||||
@ -45,44 +47,40 @@
|
||||
function setupFetchInterval() {
|
||||
baseBranchService.fetchFromTarget();
|
||||
clearFetchInterval();
|
||||
intervalId = setInterval(() => baseBranchService.fetchFromTarget(), 15 * 60 * 1000);
|
||||
const intervalMs = 15 * 60 * 1000; // 15 minutes
|
||||
intervalId = setInterval(() => baseBranchService.fetchFromTarget(), intervalMs);
|
||||
}
|
||||
|
||||
function clearFetchInterval() {
|
||||
if (intervalId) clearInterval(intervalId);
|
||||
}
|
||||
|
||||
$: if ($baseBranch$ === null) {
|
||||
goto(`/${projectId}/setup`, { replaceState: true });
|
||||
}
|
||||
// TODO: Is this an ok way to redirect?
|
||||
$: if ($baseBranch === null) goto(`/${projectId}/setup`, { replaceState: true });
|
||||
|
||||
onMount(() => {
|
||||
// Once on load and every time the project id changes
|
||||
handleMenuActions(data.projectId);
|
||||
return unsubscribe(
|
||||
menuSubscribe(data.projectId),
|
||||
hotkeys.on('Meta+Shift+S', () => syncToCloud(projectId))
|
||||
);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
clearFetchInterval();
|
||||
});
|
||||
|
||||
$: if (data) {
|
||||
setContext('hello', data.projectId);
|
||||
}
|
||||
onDestroy(() => clearFetchInterval());
|
||||
</script>
|
||||
|
||||
{#if !$project$}
|
||||
<p>Project not found!</p>
|
||||
{:else if $baseBranch$ === null}
|
||||
{:else if $baseBranch === null}
|
||||
<!-- Be careful, this works because of the redirect above -->
|
||||
<slot />
|
||||
{:else if $baseError$}
|
||||
<ProblemLoadingRepo project={$project$} error={$baseError$} />
|
||||
{:else if $branchesError$}
|
||||
<ProblemLoadingRepo project={$project$} error={$branchesError$} />
|
||||
{:else if !$gbBranchActive$ && $baseBranch$}
|
||||
<NotOnGitButlerBranch project={$project$} baseBranch={$baseBranch$} />
|
||||
{:else if $baseError}
|
||||
<ProblemLoadingRepo project={$project$} error={$baseError} />
|
||||
{:else if $branchesError}
|
||||
<ProblemLoadingRepo project={$project$} error={$branchesError} />
|
||||
{:else if !$gbBranchActive$ && $baseBranch}
|
||||
<NotOnGitButlerBranch project={$project$} baseBranch={$baseBranch} />
|
||||
{:else if $baseBranch}
|
||||
<div class="view-wrap" role="group" on:dragover|preventDefault>
|
||||
<Navigation project={$project$} user={$user$} />
|
||||
|
@ -14,14 +14,10 @@
|
||||
const baseBranchService = getContextByClass(BaseBranchService);
|
||||
const baseBranch = baseBranchService.base;
|
||||
|
||||
$: vbranchService = data.vbranchService;
|
||||
$: cloud = data.cloud;
|
||||
$: projectId = data.projectId;
|
||||
$: user$ = data.user$;
|
||||
$: ({ vbranchService, cloud, projectId, user$, project$ } = data);
|
||||
|
||||
$: project$ = data.project$;
|
||||
$: activeBranches$ = vbranchService.activeBranches$;
|
||||
$: error$ = vbranchService.branchesError$;
|
||||
$: error$ = vbranchService.branchesError;
|
||||
|
||||
let viewport: HTMLDivElement;
|
||||
let contents: HTMLDivElement;
|
||||
|
@ -11,17 +11,15 @@
|
||||
const githubService = getContextByClass(GitHubService);
|
||||
|
||||
$: project$ = data.project$;
|
||||
$: remoteBranchService = data.remoteBranchService;
|
||||
$: branches$ = remoteBranchService.branches$;
|
||||
$: error$ = remoteBranchService.branchesError$;
|
||||
$: ({ error, branches } = data.remoteBranchService);
|
||||
|
||||
$: branch = $branches$?.find((b) => b.sha == $page.params.sha);
|
||||
$: branch = $branches?.find((b) => b.sha == $page.params.sha);
|
||||
$: pr = githubService.getPr(branch?.displayName);
|
||||
</script>
|
||||
|
||||
{#if $error$}
|
||||
{#if $error}
|
||||
<p>Error...</p>
|
||||
{:else if !$branches$}
|
||||
{:else if !$branches}
|
||||
<FullscreenLoading />
|
||||
{:else if branch}
|
||||
<RemoteBranchPreview
|
||||
|
@ -7,9 +7,7 @@
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
$: authService = data.authService;
|
||||
$: projectId = data.projectId;
|
||||
$: project$ = data.project$;
|
||||
$: ({ authService, projectId, project$ } = data);
|
||||
</script>
|
||||
|
||||
{#await getRemoteBranches(projectId)}
|
||||
|
@ -12,16 +12,11 @@
|
||||
let applyConflictedModal: Modal;
|
||||
let deleteBranchModal: Modal;
|
||||
|
||||
$: projectId = data.projectId;
|
||||
$: user$ = data.user$;
|
||||
$: cloud = data.cloud;
|
||||
$: project$ = data.project$;
|
||||
|
||||
$: branchController = data.branchController;
|
||||
$: vbranchService = data.vbranchService;
|
||||
|
||||
$: ({ projectId, project$, cloud, userService, branchController, vbranchService } = data);
|
||||
$: branches$ = vbranchService.branches$;
|
||||
$: error$ = vbranchService.branchesError$;
|
||||
$: error$ = vbranchService.activeBranches$;
|
||||
$: user = userService.user;
|
||||
|
||||
$: branch = $branches$?.find((b) => b.id == $page.params.branchId);
|
||||
</script>
|
||||
|
||||
@ -35,7 +30,7 @@
|
||||
{cloud}
|
||||
project={$project$}
|
||||
isUnapplied={!branch.active}
|
||||
user={$user$}
|
||||
user={$user}
|
||||
projectPath={$project$.path}
|
||||
/>
|
||||
{:else}
|
||||
|
Loading…
Reference in New Issue
Block a user