Skip to content

Commit 661da24

Browse files
committed
Fix history page performance issue
Looks like code was in need of a bit of love.
1 parent c9024e9 commit 661da24

File tree

6 files changed

+38
-90
lines changed

6 files changed

+38
-90
lines changed

apps/desktop/src/components/FileList.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
draggableFiles?: boolean;
3737
ancestorMostConflictedCommitId?: string;
3838
hideLastFileBorder?: boolean;
39-
onselect?: () => void;
39+
onselect?: (change: TreeChange) => void;
4040
};
4141
4242
const {
@@ -182,7 +182,7 @@
182182
if (e.key === 'Enter' || e.key === ' ' || e.key === 'l') {
183183
e.stopPropagation();
184184
selectFilesInList(e, change, changes, idSelection, selectedFileIds, true, idx, selectionId);
185-
onselect?.();
185+
onselect?.(change);
186186
return true;
187187
}
188188
@@ -251,7 +251,7 @@
251251
onclick={(e) => {
252252
e.stopPropagation();
253253
selectFilesInList(e, change, changes, idSelection, selectedFileIds, true, idx, selectionId);
254-
onselect?.();
254+
onselect?.(change);
255255
}}
256256
{conflictEntries}
257257
/>

apps/desktop/src/components/FileListItemWrapper.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
111111
async function onContextMenu(e: MouseEvent) {
112112
const changes = await idSelection.treeChanges(projectId, selectionId);
113-
if (idSelection.has(change.path, selectionId)) {
113+
if (idSelection.has(change.path, selectionId) && changes.length > 0) {
114114
contextMenu?.open(e, { changes });
115115
return;
116116
}

apps/desktop/src/components/SnapshotAttachment.svelte

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { Icon } from '@gitbutler/ui';
33
import { pxToRem } from '@gitbutler/ui/utils/pxToRem';
4-
import { onMount } from 'svelte';
54
import type { Snippet } from 'svelte';
65
76
interface Props {
@@ -20,24 +19,6 @@
2019
2120
let isOpen: boolean = $state(false);
2221
let el = $state<HTMLElement>();
23-
24-
let contentHeight = $state<string>();
25-
26-
function setHeight() {
27-
contentHeight = `calc(${pxToRem(el?.scrollHeight ?? 0)}rem + ${pxToRem(8)}rem)`;
28-
}
29-
30-
onMount(() => {
31-
if (!foldable) return;
32-
33-
setHeight();
34-
});
35-
36-
$effect(() => {
37-
if (el) {
38-
setHeight();
39-
}
40-
});
4122
</script>
4223

4324
<div class="snapshot-attachment">
@@ -51,7 +32,7 @@
5132
}
5233
}}
5334
class="snapshot-attachment__content"
54-
style="max-height: {foldable ? (isOpen ? contentHeight : foldedHeight) : 'auto'}"
35+
style="max-height: {foldable ? (isOpen ? pxToRem(300) + 'rem' : foldedHeight) : 'auto'}"
5536
>
5637
{@render children?.()}
5738
</div>

apps/desktop/src/components/SnapshotCard.svelte

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script lang="ts">
2+
import FileList from '$components/FileList.svelte';
23
import ReduxResult from '$components/ReduxResult.svelte';
34
import SnapshotAttachment from '$components/SnapshotAttachment.svelte';
45
import { createdOnDay, HISTORY_SERVICE } from '$lib/history/history';
56
import { MODE_SERVICE } from '$lib/mode/modeService';
67
import { toHumanReadableTime } from '$lib/utils/time';
78
import { inject } from '@gitbutler/core/context';
8-
import { Button, Icon, FileListItem } from '@gitbutler/ui';
9+
import { Button, Icon, ScrollableContainer } from '@gitbutler/ui';
910
import { focusable } from '@gitbutler/ui/focus/focusable';
1011
import type { Snapshot, SnapshotDetails } from '$lib/history/types';
1112
import type iconsJson from '@gitbutler/ui/data/icons.json';
@@ -15,23 +16,10 @@
1516
isWithinRestore?: boolean;
1617
onRestoreClick: () => void;
1718
onDiffClick: (filePath: string) => void;
18-
selectedFile?:
19-
| {
20-
entryId: string;
21-
path: string;
22-
}
23-
| undefined;
2419
projectId: string;
2520
}
2621
27-
const {
28-
projectId,
29-
entry,
30-
isWithinRestore = true,
31-
selectedFile = undefined,
32-
onRestoreClick,
33-
onDiffClick
34-
}: Props = $props();
22+
const { projectId, entry, isWithinRestore = true, onRestoreClick, onDiffClick }: Props = $props();
3523
3624
function getShortSha(sha: string | undefined) {
3725
if (!sha) return '';
@@ -223,25 +211,22 @@
223211
<ReduxResult result={snapshotDiff.result} {projectId}>
224212
{#snippet children(files)}
225213
{#if files.length > 0 && !isRestoreSnapshot}
226-
<SnapshotAttachment foldable={files.length > 2} foldedAmount={files.length}>
227-
<div class="files-attacment" use:focusable={{ vertical: true }}>
228-
{#each files as file, idx}
229-
<div
230-
use:focusable={{
231-
focusable: true,
232-
onActive: () => onDiffClick(file.path)
233-
}}
234-
>
235-
<FileListItem
236-
listMode="list"
237-
filePath={file.path}
238-
selected={selectedFile?.path === file.path &&
239-
selectedFile?.entryId === entry.id}
240-
hideBorder={idx === files.length - 1}
241-
/>
242-
</div>
243-
{/each}
244-
</div>
214+
<SnapshotAttachment
215+
foldable={files.length > 2}
216+
foldedAmount={files.length}
217+
foldedHeight="7rem"
218+
>
219+
<ScrollableContainer>
220+
<FileList
221+
selectionId={{ type: 'snapshot', snapshotId: entry.id }}
222+
{projectId}
223+
stackId={undefined}
224+
changes={files}
225+
listMode="list"
226+
hideLastFileBorder={false}
227+
onselect={(change) => onDiffClick(change.path)}
228+
/>
229+
</ScrollableContainer>
245230
</SnapshotAttachment>
246231
{/if}
247232
{/snippet}
@@ -386,12 +371,6 @@
386371
white-space: nowrap;
387372
}
388373
389-
/* ATTACHMENT FILES */
390-
.files-attacment {
391-
display: flex;
392-
flex-direction: column;
393-
}
394-
395374
/* ATTACHMENT RESTORE */
396375
.restored-attacment {
397376
display: flex;

apps/desktop/src/lib/selection/fileSelectionManager.svelte.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ export class FileSelectionManager {
164164
case 'commit':
165165
return await this.stackService.commitChangesByPaths(projectId, params.commitId, paths);
166166
case 'snapshot':
167-
throw new Error('unsupported');
167+
// TODO: Use the commented out code once back end support restored!
168+
// Without this we can't show a multi file context menu for snapshots.
169+
// if (paths[0]) {
170+
// const change = await this.oplogService.fetchDiffWorktreeByPath({
171+
// projectId,
172+
// snapshotId: params.snapshotId,
173+
// path: paths[0]
174+
// });
175+
// return change ? [change] : [];
176+
// }
177+
return [];
168178
}
169179
}
170180

apps/desktop/src/routes/[projectId]/history/+page.svelte

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@
7070
return ranges.map((snapshot) => snapshot.id);
7171
}
7272
73-
async function updateFilePreview(entry: Snapshot, path: string) {
74-
const selectionId = createSnapshotSelection({ snapshotId: entry.id });
75-
// Get the diff data to find the file index
76-
const diffs = await historyService.getSnapshotDiff(projectId, entry.id);
77-
const fileIndex = diffs.findIndex((tc) => tc.path === path);
78-
if (fileIndex === -1) return;
79-
80-
idSelection.set(path, selectionId, fileIndex);
81-
currentSelectionId = selectionId;
82-
}
83-
8473
let scrollContainer: HTMLDivElement | undefined = $state();
8574
</script>
8675

@@ -126,28 +115,17 @@
126115
{#if entry.details}
127116
<SnapshotCard
128117
{projectId}
129-
isWithinRestore={withinRestoreItems.includes(entry.id)}
130118
{entry}
119+
isWithinRestore={withinRestoreItems.includes(entry.id)}
131120
onRestoreClick={() => {
132121
historyService.restoreSnapshot(projectId, entry.id);
133122
// In some cases, restoring the snapshot doesnt update the UI correctly
134123
// Until we have that figured out, we need to reload the page.
135124
location.reload();
136125
}}
137-
onDiffClick={(path) => {
138-
if (
139-
selectedFile?.path === path &&
140-
selectedFile?.type === 'snapshot' &&
141-
selectedFile.snapshotId === entry.id
142-
) {
143-
currentSelectionId = undefined;
144-
} else {
145-
updateFilePreview(entry, path);
146-
}
126+
onDiffClick={() => {
127+
currentSelectionId = createSnapshotSelection({ snapshotId: entry.id });
147128
}}
148-
selectedFile={currentSelectionId && selectedFile && selectedFile.type === 'snapshot'
149-
? { entryId: selectedFile.snapshotId, path: selectedFile.path }
150-
: undefined}
151129
/>
152130
{/if}
153131
{/each}

0 commit comments

Comments
 (0)