mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-30 01:17:37 +03:00
Await reload of prs before loading is set to false
This commit is contained in:
parent
4467aefa7b
commit
1fa737e40f
@ -1,6 +1,22 @@
|
||||
import lscache from 'lscache';
|
||||
import { Observable, EMPTY, BehaviorSubject, of } from 'rxjs';
|
||||
import { catchError, combineLatestWith, map, shareReplay, switchMap, tap } from 'rxjs/operators';
|
||||
import {
|
||||
Observable,
|
||||
EMPTY,
|
||||
BehaviorSubject,
|
||||
of,
|
||||
firstValueFrom,
|
||||
lastValueFrom,
|
||||
Subject
|
||||
} from 'rxjs';
|
||||
import {
|
||||
catchError,
|
||||
combineLatestWith,
|
||||
map,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
take,
|
||||
tap
|
||||
} from 'rxjs/operators';
|
||||
|
||||
import {
|
||||
type PullRequest,
|
||||
@ -14,6 +30,7 @@ export class PrService {
|
||||
error$ = new BehaviorSubject<string | undefined>(undefined);
|
||||
private reload$ = new BehaviorSubject<{ skipCache: boolean } | undefined>(undefined);
|
||||
private inject$ = new BehaviorSubject<PullRequest | undefined>(undefined);
|
||||
private fresh$ = new Subject<void>();
|
||||
|
||||
constructor(ghContext$: Observable<GitHubIntegrationContext | undefined>) {
|
||||
this.prs$ = ghContext$.pipe(
|
||||
@ -21,7 +38,9 @@ export class PrService {
|
||||
tap(() => this.error$.next(undefined)),
|
||||
switchMap(([ctx, reload]) => {
|
||||
if (!ctx) return EMPTY;
|
||||
return loadPrs(ctx, !!reload?.skipCache);
|
||||
const prs = loadPrs(ctx, !!reload?.skipCache);
|
||||
this.fresh$.next();
|
||||
return prs;
|
||||
}),
|
||||
combineLatestWith(this.inject$),
|
||||
map(([prs, inject]) => {
|
||||
@ -30,17 +49,17 @@ export class PrService {
|
||||
}),
|
||||
shareReplay(1),
|
||||
catchError((err) => {
|
||||
console.log(err);
|
||||
this.error$.next(err);
|
||||
return of([]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
reload(): Promise<void> {
|
||||
this.reload$.next({ skipCache: true });
|
||||
return firstValueFrom(this.fresh$);
|
||||
}
|
||||
add(pr: PullRequest) {
|
||||
insert(pr: PullRequest) {
|
||||
this.inject$.next(pr);
|
||||
}
|
||||
get(branch: string | undefined): Observable<PullRequest | undefined> | undefined {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { User } from '$lib/backend/cloud';
|
||||
import type { GitHubIntegrationContext } from '$lib/github/types';
|
||||
import type { BaseBranch } from '$lib/vbranches/types';
|
||||
import { combineLatest, switchMap, type Observable, of, shareReplay, distinct } from 'rxjs';
|
||||
import { combineLatest, switchMap, type Observable, of, shareReplay, distinct, tap } from 'rxjs';
|
||||
|
||||
export function getGithubContext(
|
||||
user$: Observable<User | undefined>,
|
||||
@ -18,6 +18,7 @@ export function getGithubContext(
|
||||
const [owner, repo] = remoteUrl.split('.git')[0].split(/\/|:/).slice(-2);
|
||||
return of({ authToken, owner, repo, username });
|
||||
}),
|
||||
distinct((val) => JSON.stringify(val)),
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@
|
||||
isPushing = true;
|
||||
await branchController.pushBranch(branch.id, branch.requiresForce);
|
||||
if (opts?.createPr) {
|
||||
await sleep(500);
|
||||
await sleep(200); // Needed by GitHub
|
||||
await createPr();
|
||||
}
|
||||
isPushing = false;
|
||||
@ -82,7 +82,7 @@
|
||||
return `${target.repoBaseUrl}/compare/${baseBranchName}...${branchName}`;
|
||||
}
|
||||
|
||||
async function createPr() {
|
||||
async function createPr(): Promise<void> {
|
||||
if (githubContext && base?.branchName && branchName) {
|
||||
const pr = await createPullRequest(
|
||||
githubContext,
|
||||
@ -92,10 +92,10 @@
|
||||
branch.notes
|
||||
);
|
||||
if (pr) {
|
||||
prService.add(pr);
|
||||
prService.reload();
|
||||
prService.insert(pr);
|
||||
await prService.reload();
|
||||
}
|
||||
return pr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user