|
1 | 1 | import { invoke } from '$lib/backend/ipc'; |
2 | 2 | import { VirtualBranchService } from '$lib/vbranches/virtualBranch'; |
3 | 3 | import { isDefined } from '@gitbutler/ui/utils/typeguards'; |
4 | | -import { derived, readable, type Readable } from 'svelte/store'; |
| 4 | +import { get } from 'svelte/store'; |
5 | 5 | import type { Project } from '$lib/backend/projects'; |
6 | 6 | import type { VirtualBranch } from '$lib/vbranches/types'; |
7 | 7 |
|
@@ -119,39 +119,34 @@ export class UpstreamIntegrationService { |
119 | 119 | private virtualBranchService: VirtualBranchService |
120 | 120 | ) {} |
121 | 121 |
|
122 | | - upstreamStatuses(targetCommitOid?: string): Readable<StackStatusesWithBranches | undefined> { |
123 | | - const branchStatuses = readable<BranchStatusesResponse | undefined>(undefined, (set) => { |
124 | | - invoke<BranchStatusesResponse>('upstream_integration_statuses', { |
125 | | - projectId: this.project.id, |
126 | | - targetCommitOid |
127 | | - }).then(set); |
| 122 | + async upstreamStatuses(targetCommitOid?: string): Promise<StackStatusesWithBranches | undefined> { |
| 123 | + const branchStatuses = await invoke<BranchStatusesResponse>('upstream_integration_statuses', { |
| 124 | + projectId: this.project.id, |
| 125 | + targetCommitOid |
128 | 126 | }); |
129 | 127 |
|
130 | | - const branchStatusesWithBranches = derived( |
131 | | - [branchStatuses, this.virtualBranchService.branches], |
132 | | - ([branchStatuses, branches]): StackStatusesWithBranches | undefined => { |
133 | | - if (!branchStatuses || !branches) return; |
134 | | - if (branchStatuses.type === 'upToDate') return branchStatuses; |
135 | | - |
136 | | - return { |
137 | | - type: 'updatesRequired', |
138 | | - subject: branchStatuses.subject |
139 | | - .map((status) => { |
140 | | - const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]); |
141 | | - |
142 | | - if (!stack) return; |
143 | | - |
144 | | - return { |
145 | | - stack, |
146 | | - status: status[1] |
147 | | - }; |
148 | | - }) |
149 | | - .filter(isDefined) |
150 | | - }; |
151 | | - } |
152 | | - ); |
153 | | - |
154 | | - return branchStatusesWithBranches; |
| 128 | + const branches = get(this.virtualBranchService.branches); |
| 129 | + |
| 130 | + if (!branchStatuses || !branches) return; |
| 131 | + if (branchStatuses.type === 'upToDate') return branchStatuses; |
| 132 | + |
| 133 | + const stackStatusesWithBranches: StackStatusesWithBranches = { |
| 134 | + type: 'updatesRequired', |
| 135 | + subject: branchStatuses.subject |
| 136 | + .map((status) => { |
| 137 | + const stack = branches.find((appliedBranch) => appliedBranch.id === status[0]); |
| 138 | + |
| 139 | + if (!stack) return; |
| 140 | + |
| 141 | + return { |
| 142 | + stack, |
| 143 | + status: status[1] |
| 144 | + }; |
| 145 | + }) |
| 146 | + .filter(isDefined) |
| 147 | + }; |
| 148 | + |
| 149 | + return stackStatusesWithBranches; |
155 | 150 | } |
156 | 151 |
|
157 | 152 | async integrateUpstream(resolutions: Resolution[], baseBranchResolution?: BaseBranchResolution) { |
|
0 commit comments