-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display the author and commit title in the edit mode #4948
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { invoke } from '$lib/backend/ipc'; | ||
import { Commit } from '$lib/vbranches/types'; | ||
import { plainToInstance } from 'class-transformer'; | ||
|
||
export class RemoteCommitService { | ||
async find(projectId: string, commitOid: string): Promise<Commit | undefined> { | ||
try { | ||
const commit = await invoke<unknown>('find_commit', { projectId, commitOid }); | ||
return plainToInstance(Commit, commit); | ||
} catch (error) { | ||
console.error(error); | ||
return undefined; | ||
} | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
<script lang="ts"> | ||
// import { Project } from '$lib/backend/projects'; | ||
import { Project } from '$lib/backend/projects'; | ||
import { RemoteCommitService } from '$lib/commits/service'; | ||
import ActionView from '$lib/layout/ActionView.svelte'; | ||
import { ModeService, type EditModeMetadata } from '$lib/modes/service'; | ||
import { UncommitedFilesWatcher } from '$lib/uncommitedFiles/watcher'; | ||
import { getContext } from '$lib/utils/context'; | ||
import { Commit, type RemoteFile } from '$lib/vbranches/types'; | ||
import Button from '@gitbutler/ui/Button.svelte'; | ||
import InfoButton from '@gitbutler/ui/InfoButton.svelte'; | ||
import Avatar from '@gitbutler/ui/avatar/Avatar.svelte'; | ||
import FileListItem from '@gitbutler/ui/file/FileListItem.svelte'; | ||
import type { RemoteFile } from '$lib/vbranches/types'; | ||
import type { FileStatus } from '@gitbutler/ui/file/types'; | ||
|
||
interface Props { | ||
|
@@ -17,7 +18,8 @@ | |
|
||
const { editModeMetadata }: Props = $props(); | ||
|
||
// const project = getContext(Project); | ||
const project = getContext(Project); | ||
const remoteCommitService = getContext(RemoteCommitService); | ||
const uncommitedFileWatcher = getContext(UncommitedFilesWatcher); | ||
const modeService = getContext(ModeService); | ||
|
||
|
@@ -27,13 +29,20 @@ | |
let modeServiceSaving = $state<'inert' | 'loading' | 'completed'>('inert'); | ||
|
||
let initialFiles = $state<RemoteFile[]>([]); | ||
let commit = $state<Commit | undefined>(undefined); | ||
|
||
$effect(() => { | ||
modeService.getInitialIndexState().then((files) => { | ||
initialFiles = files; | ||
}); | ||
}); | ||
|
||
$effect(() => { | ||
remoteCommitService.find(project.id, editModeMetadata.commitOid).then((maybeCommit) => { | ||
commit = maybeCommit; | ||
}); | ||
}); | ||
|
||
Comment on lines
+40
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we should always have a commit so I'd stick with |
||
interface FileEntry { | ||
name: string; | ||
path: string; | ||
|
@@ -144,13 +153,14 @@ | |
|
||
<div class="commit-data"> | ||
<div class="card commit-card"> | ||
<h3 class="text-13 text-semibold commit-card__title">Awesome title</h3> | ||
<h3 class="text-13 text-semibold commit-card__title"> | ||
{commit?.descriptionTitle ?? 'unknown'} | ||
</h3> | ||
<div class="text-11 commit-card__details"> | ||
<span class="">{editModeMetadata.commitOid.slice(0, 7)}</span> | ||
<span class="commit-card__divider">•</span> | ||
<span class="">Author</span> | ||
<span class="">{commit?.author.name ?? 'unknown'}</span> | ||
</div> | ||
|
||
<div class="commit-card__type-indicator"></div> | ||
</div> | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,6 +110,15 @@ pub(crate) fn get_branch_data(ctx: &CommandContext, refname: &Refname) -> Result | |||||||||||||||||||||||||||||||||||||||||||||||||||
.context("failed to get branch data") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
pub(crate) fn get_commit_data(ctx: &CommandContext, sha: git2::Oid) -> Result<RemoteCommit> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
let commit = ctx | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.repository() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.find_commit(sha) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.context("failed to find commit")?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Ok(commit_to_remote_commit(&commit)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+113
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whenever you see this pattern, that an |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
pub(crate) fn branch_to_remote_branch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
branch: &git2::Branch<'_>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
remotes: &git2::string_array::StringArray, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something in my mind here is that we want to move away from using
console.error
and silently consuming errors. I figure here your intention was to represent a commit not being found, but I think with a little bit of jiggery pokery we can make it a little nicer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also know that the name "RemoteCommitSerice" is inaccurate, could we please call it "CommitService"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be keen to hear your thoughts on this, but in my mind it makes sense to try and pass as many dependencies in the constructor as possible. I would be keen to pass the project through the constructor until we had a good reason as to why that was a bad pattern, as it just adds more boilerplate to the consumers.