Skip to content

Commit

Permalink
fix: revert commitService.find to plain invoke incl invocation in E…
Browse files Browse the repository at this point in the history
…ditMode.svelte
  • Loading branch information
ndom91 committed Feb 18, 2025
1 parent e4bc72e commit 831e858
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 130 deletions.
210 changes: 107 additions & 103 deletions apps/desktop/src/components/EditMode.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import ReduxResult from './ReduxResult.svelte';
import FileContextMenu from '$components/FileContextMenu.svelte';
import ScrollableContainer from '$components/ScrollableContainer.svelte';
import { Commit } from '$lib/commits/commit';
import { CommitService } from '$lib/commits/commitService.svelte';
import {
conflictEntryHint,
Expand Down Expand Up @@ -51,13 +51,21 @@
let modeServiceSaving = $state<'inert' | 'loading' | 'completed'>('inert');
let initialFiles = $state<[RemoteFile, ConflictEntryPresence | undefined][]>([]);
const commit = $derived(remoteCommitService.find(project.id, editModeMetadata.commitOid));
let commit = $state<Commit>();
async function getCommitData() {
commit = await remoteCommitService.find(project.id, editModeMetadata.commitOid);
}
$effect(() => {
getCommitData();
});
const authorImgUrl = $derived.by(() => {
const commitData = commit.current.data;
if (commitData) {
return commitData.author.email?.toLowerCase() === $user?.email?.toLowerCase()
if (commit) {
return commit.author.email?.toLowerCase() === $user?.email?.toLowerCase()
? $user?.picture
: commitData.author.gravatarUrl;
: commit.author.gravatarUrl;
}
return undefined;
});
Expand Down Expand Up @@ -227,109 +235,105 @@
const loading = $derived(modeServiceSaving === 'loading' || modeServiceAborting === 'loading');
</script>

<ReduxResult result={commit.current}>
{#snippet children(commit)}
<div class="editmode__container">
<h2 class="editmode__title text-18 text-body text-bold">
You are editing commit <span class="code-string">
{editModeMetadata.commitOid.slice(0, 7)}
</span>
<InfoButton title="Edit Mode">
Edit Mode lets you modify an existing commit in isolation or resolve conflicts. Any
changes made, including new files, will be added to the selected commit.
</InfoButton>
</h2>

<div class="commit-group">
<div class="card commit-card">
<h3 class="text-13 text-semibold text-body commit-card__title">
{commit?.descriptionTitle || 'Undefined commit'}
</h3>

{#if commit}
<div class="text-11 commit-card__details">
{#if authorImgUrl && commit.author.email}
<Avatar srcUrl={authorImgUrl} tooltip={commit.author.email} />
<span class="commit-card__divider">•</span>
{/if}
<span class="">{editModeMetadata.commitOid.slice(0, 7)}</span>
<span class="commit-card__divider">•</span>
<span class="">{commit.author.name}</span>
</div>
<div class="editmode__container">
<h2 class="editmode__title text-18 text-body text-bold">
You are editing commit <span class="code-string">
{editModeMetadata.commitOid.slice(0, 7)}
</span>
<InfoButton title="Edit Mode">
Edit Mode lets you modify an existing commit in isolation or resolve conflicts. Any changes
made, including new files, will be added to the selected commit.
</InfoButton>
</h2>

<div class="commit-group">
<div class="card commit-card">
<h3 class="text-13 text-semibold text-body commit-card__title">
{commit?.descriptionTitle || 'Undefined commit'}
</h3>

{#if commit}
<div class="text-11 commit-card__details">
{#if authorImgUrl && commit.author.email}
<Avatar srcUrl={authorImgUrl} tooltip={commit.author.email} />
<span class="commit-card__divider">•</span>
{/if}

<div class="commit-card__type-indicator"></div>
<span class="">{editModeMetadata.commitOid.slice(0, 7)}</span>
<span class="commit-card__divider">•</span>
<span class="">{commit.author.name}</span>
</div>
{/if}

<div bind:this={filesList} class="card files">
<div class="header" class:show-border={isCommitListScrolled}>
<h3 class="text-13 text-semibold">Commit files</h3>
<Badge>{files.length}</Badge>
</div>
<ScrollableContainer
onscroll={(e) => {
if (e.target instanceof HTMLElement) {
isCommitListScrolled = e.target.scrollTop > 0;
}
}}
>
{#each files as file (file.path)}
<div class="file">
<FileListItem
filePath={file.path}
fileStatus={file.status}
conflicted={isConflicted(file)}
onresolveclick={file.conflicted
? () => manuallyResolvedFiles.add(file.path)
: undefined}
conflictHint={file.conflictHint}
onclick={(e) => {
contextMenu?.open(e, { files: [file] });
}}
oncontextmenu={(e) => {
contextMenu?.open(e, { files: [file] });
}}
/>
</div>
{/each}
</ScrollableContainer>
</div>
</div>
<div class="commit-card__type-indicator"></div>
</div>

<FileContextMenu
bind:this={contextMenu}
trigger={filesList}
isUnapplied={false}
branchId={undefined}
/>

<p class="text-12 text-body editmode__helptext">
Please don't make any commits while in edit mode.
<br />
To exit edit mode, use the provided actions.
</p>

<div class="editmode__actions">
<Button kind="outline" onclick={abort} disabled={loading} {loading}>Cancel</Button>
{#if conflictedFiles.length > 0}
<Button
style="neutral"
onclick={openAllConflictedFiles}
icon="open-link"
tooltip={conflictedFiles.length === 1
? 'Open the conflicted file in your editor'
: 'Open all files with conflicts in your editor'}
>
Open conflicted files
</Button>
{/if}
<Button style="pop" icon="tick-small" onclick={handleSave} disabled={loading} {loading}>
Save and exit
</Button>
<div bind:this={filesList} class="card files">
<div class="header" class:show-border={isCommitListScrolled}>
<h3 class="text-13 text-semibold">Commit files</h3>
<Badge>{files.length}</Badge>
</div>
<ScrollableContainer
onscroll={(e) => {
if (e.target instanceof HTMLElement) {
isCommitListScrolled = e.target.scrollTop > 0;
}
}}
>
{#each files as file (file.path)}
<div class="file">
<FileListItem
filePath={file.path}
fileStatus={file.status}
conflicted={isConflicted(file)}
onresolveclick={file.conflicted
? () => manuallyResolvedFiles.add(file.path)
: undefined}
conflictHint={file.conflictHint}
onclick={(e) => {
contextMenu?.open(e, { files: [file] });
}}
oncontextmenu={(e) => {
contextMenu?.open(e, { files: [file] });
}}
/>
</div>
{/each}
</ScrollableContainer>
</div>
{/snippet}
</ReduxResult>
</div>

<FileContextMenu
bind:this={contextMenu}
trigger={filesList}
isUnapplied={false}
branchId={undefined}
/>

<p class="text-12 text-body editmode__helptext">
Please don't make any commits while in edit mode.
<br />
To exit edit mode, use the provided actions.
</p>

<div class="editmode__actions">
<Button kind="outline" onclick={abort} disabled={loading} {loading}>Cancel</Button>
{#if conflictedFiles.length > 0}
<Button
style="neutral"
onclick={openAllConflictedFiles}
icon="open-link"
tooltip={conflictedFiles.length === 1
? 'Open the conflicted file in your editor'
: 'Open all files with conflicts in your editor'}
>
Open conflicted files
</Button>
{/if}
<Button style="pop" icon="tick-small" onclick={handleSave} disabled={loading} {loading}>
Save and exit
</Button>
</div>
</div>

<Modal
bind:this={confirmSaveModal}
Expand Down
29 changes: 3 additions & 26 deletions apps/desktop/src/lib/commits/commitService.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { Commit } from './commit';
import { ReduxTag } from '$lib/state/tags';
import { invoke } from '$lib/backend/ipc';
import { plainToInstance } from 'class-transformer';
import type { ClientState } from '$lib/state/clientState.svelte';

export class CommitService {
private api: ReturnType<typeof injectEndpoints>;

constructor(state: ClientState) {
this.api = injectEndpoints(state.backendApi);
}

find(projectId: string, commitOid: string) {
const result = $derived(this.api.endpoints.find.useQuery({ projectId, commitOid }));
return result;
async find(projectId: string, commitOid: string) {
return plainToInstance(Commit, await invoke<Commit>('find_commit', { projectId, commitOid }));
}
}

function injectEndpoints(api: ClientState['backendApi']) {
return api.injectEndpoints({
endpoints: (build) => ({
find: build.query<Commit, { projectId: string; commitOid: string }>({
query: ({ projectId, commitOid }) => ({
command: 'find_commit',
params: { projectId, commitOid }
}),
transformResponse: (response: unknown) => plainToInstance(Commit, response),
providesTags: [ReduxTag.Commit]
})
})
});
}
2 changes: 1 addition & 1 deletion apps/desktop/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
const desktopRouteService = new DesktopRoutesService();
const diffService = new DiffService(clientState);
const shortcutService = new ShortcutService(data.tauri);
const commitService = new CommitService(clientState);
const commitService = new CommitService();
shortcutService.listen();
Expand Down

0 comments on commit 831e858

Please sign in to comment.