mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-23 20:54:50 +03:00
Fix race condition in listing patch stacks
This commit is contained in:
parent
538c19671b
commit
73f458738b
@ -1,4 +1,5 @@
|
||||
import { getUserErrorCode, invoke } from '$lib/backend/ipc';
|
||||
import { ProjectService, type Project } from '$lib/backend/projects';
|
||||
import { BaseBranchService } from '$lib/baseBranch/baseBranchService';
|
||||
import { PatchStackCreationService } from '$lib/branch/patchStackCreationService';
|
||||
import { BranchListingService } from '$lib/branches/branchListing';
|
||||
@ -22,7 +23,6 @@ import {
|
||||
} from '@gitbutler/shared/cloud/stacks/service';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { derived } from 'svelte/store';
|
||||
import { ProjectService, type Project } from '$lib/backend/projects';
|
||||
import type { LayoutLoad } from './$types';
|
||||
|
||||
export const prerender = false;
|
||||
|
@ -148,7 +148,13 @@ export interface PatchStackUpdateParams {
|
||||
}
|
||||
|
||||
export class PatchStacksApiService {
|
||||
constructor(private readonly httpClient: HttpClient) {}
|
||||
readonly canGetPatchStacks: Readable<boolean>;
|
||||
readonly canCreatePatchStack: Readable<boolean>;
|
||||
|
||||
constructor(private readonly httpClient: HttpClient) {
|
||||
this.canGetPatchStacks = httpClient.authenticationAvailable;
|
||||
this.canCreatePatchStack = httpClient.authenticationAvailable;
|
||||
}
|
||||
|
||||
async getPatchStacks(
|
||||
repositoryId: string,
|
||||
@ -201,11 +207,16 @@ export class CloudPatchStacksService {
|
||||
private readonly repositoryId: Readable<string | undefined>,
|
||||
private readonly patchStacksApiService: PatchStacksApiService
|
||||
) {
|
||||
this.#apiPatchStacks = writableDerived<ApiPatchStack[], string | undefined>(
|
||||
this.repositoryId,
|
||||
const values = derived(
|
||||
[this.patchStacksApiService.canGetPatchStacks, this.repositoryId],
|
||||
(values) => values
|
||||
);
|
||||
|
||||
this.#apiPatchStacks = writableDerived<ApiPatchStack[], [boolean, string | undefined]>(
|
||||
values,
|
||||
[],
|
||||
(repositoryId, set) => {
|
||||
if (!repositoryId) {
|
||||
([canGetPatchStacks, repositoryId], set) => {
|
||||
if (!repositoryId || !canGetPatchStacks) {
|
||||
set([]);
|
||||
return;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { get, type Readable } from 'svelte/store';
|
||||
import { derived, get, type Readable } from 'svelte/store';
|
||||
|
||||
export const DEFAULT_HEADERS = {
|
||||
'Content-Type': 'application/json'
|
||||
@ -14,12 +14,21 @@ type RequestOptions = {
|
||||
export class HttpClient {
|
||||
readonly apiUrl: URL;
|
||||
|
||||
/**
|
||||
* Signals whether authentication is available.
|
||||
*
|
||||
* It should be noted that the authentication may be present but invalid.
|
||||
*/
|
||||
readonly authenticationAvailable: Readable<boolean>;
|
||||
|
||||
constructor(
|
||||
public fetch = window.fetch,
|
||||
publicApiBaseUrl: string,
|
||||
private token: Readable<string | undefined>
|
||||
) {
|
||||
this.apiUrl = new URL('/api/', publicApiBaseUrl);
|
||||
|
||||
this.authenticationAvailable = derived(token, (token) => !!token);
|
||||
}
|
||||
|
||||
private getApiUrl(path: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user