Skip to content

Commit 3352f3f

Browse files
committed
feat: commit list
1 parent 34d8a53 commit 3352f3f

File tree

9 files changed

+388
-143
lines changed

9 files changed

+388
-143
lines changed

eslint.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import antfu from '@antfu/eslint-config'
44
export default antfu(
55
{
66
ignores: [
7-
// eslint ignore globs here
7+
'dist',
8+
'node_modules',
9+
'package-lock.json',
10+
'pnpm-lock.yaml',
11+
'yarn.lock',
12+
'generated',
813
],
914
},
1015
{

src/services/git.ts renamed to src/git/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ export class GitService {
1919
}
2020

2121
async getHistory(): Promise<LogResult> {
22-
const COMMIT_FORMAT = '%H%n%D%n%aN%n%aE%n%at%n%ct%n%P%n%B'
23-
2422
try {
25-
return await this.git.log()
23+
return await this.git.log([])
2624
}
2725
catch (error) {
2826
console.error('Error getting git history:', error)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineExtension } from 'reactive-vscode'
22
import * as vscode from 'vscode'
33

4-
import { GitPanelViewProvider } from './container/webview'
4+
import { GitPanelViewProvider } from './views/webview'
55

66
import { logger } from './utils'
77

src/services/storage.ts renamed to src/storage.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import type { ListLogLine } from 'simple-git'
12
import type * as vscode from 'vscode'
23

34
export class StorageService {
45
private static readonly COMMITS_KEY = 'git-panel.commits'
56

67
constructor(private context: vscode.ExtensionContext) {}
78

8-
saveCommits(commits: any[]) {
9+
saveCommits(commits: ListLogLine[]) {
910
this.context.globalState.update(StorageService.COMMITS_KEY, commits)
1011
}
1112

12-
getCommits(): any[] {
13-
return this.context.globalState.get<any[]>(StorageService.COMMITS_KEY) || []
13+
getCommits(): ListLogLine[] {
14+
return this.context.globalState.get<ListLogLine[]>(StorageService.COMMITS_KEY) || []
1415
}
1516

1617
clearCommits() {

src/views/App.vue

Lines changed: 58 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<script setup lang="ts">
2-
import { onMounted, ref, watch } from 'vue'
2+
import { computed, onMounted, ref, watch } from 'vue'
3+
import GitGraph from './components/GitGraph.vue'
34
45
interface Commit {
56
hash: string
67
author_name: string
78
author_email: string
89
message: string
910
body: string
11+
parents?: string[]
12+
date: string
1013
}
1114
1215
interface State {
@@ -39,173 +42,98 @@ window.addEventListener('message', (event: { data: any }) => {
3942
4043
// Save state when it changes
4144
watch([commits, selectedHash, filter], () => {
42-
const state: State = {
43-
commits: commits.value,
44-
selectedHash: selectedHash.value,
45-
filter: filter.value,
45+
try {
46+
const state: State = {
47+
commits: commits.value.map(commit => ({
48+
...commit,
49+
parents: Array.isArray(commit.parents) ? [...commit.parents] : [],
50+
})),
51+
selectedHash: selectedHash.value || '',
52+
filter: filter.value || '',
53+
}
54+
vscode.postMessage({ command: 'setState', state })
55+
}
56+
catch (err) {
57+
console.error('Failed to save state:', err)
4658
}
47-
vscode.postMessage({ command: 'setState', state })
4859
}, { deep: true })
4960
50-
function refreshHistory() {
51-
commits.value = []
52-
vscode.postMessage({ command: 'getHistory', forceRefresh: true })
53-
}
61+
// function refreshHistory() {
62+
// commits.value = []
63+
// vscode.postMessage({ command: 'getHistory', forceRefresh: true })
64+
// }
5465
5566
onMounted(() => {
5667
// Request git history
5768
vscode.postMessage({ command: 'getHistory', forceRefresh: true })
5869
})
5970
60-
function selectCommit(hash: string) {
61-
selectedHash.value = hash
62-
}
71+
const transformedCommits = computed(() => {
72+
return commits.value.map(commit => ({
73+
hash: commit.hash,
74+
message: commit.message,
75+
author: commit.author_name,
76+
date: commit.date,
77+
parents: commit.parents || [],
78+
}))
79+
})
6380
</script>
6481

6582
<template>
6683
<div class="git-panel">
6784
<div class="toolbar">
68-
<button class="refresh-button" @click="refreshHistory">
69-
<span class="codicon codicon-refresh" />
70-
Refresh
71-
</button>
85+
<input
86+
v-model="filter"
87+
type="text"
88+
placeholder="Search commits..."
89+
class="search-input"
90+
>
7291
</div>
92+
93+
<GitGraph
94+
:commits="transformedCommits"
95+
class="git-graph-container"
96+
/>
97+
7398
<div v-if="error" class="error">
7499
{{ error }}
75100
</div>
76-
<div v-else-if="commits.length === 0" class="loading">
77-
Loading git history...
78-
</div>
79-
<div v-else class="commits">
80-
<div class="filter">
81-
<input
82-
v-model="filter"
83-
type="text"
84-
placeholder="Filter commits..."
85-
class="filter-input"
86-
>
87-
</div>
88-
<div
89-
v-for="commit in commits"
90-
:key="commit.hash"
91-
class="commit"
92-
:class="{ selected: commit.hash === selectedHash }"
93-
@click="selectCommit(commit.hash)"
94-
>
95-
<div class="commit-header">
96-
<span class="commit-hash">{{ commit.hash.substring(0, 7) }}</span>
97-
<span class="commit-author">{{ commit.author_name }}</span>
98-
</div>
99-
<div class="commit-message">
100-
{{ commit.message }}
101-
</div>
102-
</div>
103-
</div>
104101
</div>
105102
</template>
106103

107104
<style scoped>
108105
.git-panel {
109-
padding: 10px;
110-
}
111-
112-
.error {
113-
color: red;
114-
padding: 10px;
115-
}
116-
117-
.loading {
118-
padding: 10px;
119-
color: #666;
106+
height: 100vh;
107+
display: flex;
108+
flex-direction: column;
109+
background-color: var(--vscode-sideBar-background);
120110
}
121111
122112
.toolbar {
123-
margin-bottom: 10px;
124-
}
125-
126-
.refresh-button {
127-
background-color: var(--vscode-button-background);
128-
color: var(--vscode-button-foreground);
129-
border: none;
130-
padding: 4px 8px;
131-
border-radius: 2px;
132-
cursor: pointer;
133-
}
134-
135-
.refresh-button:hover {
136-
background-color: var(--vscode-button-hoverBackground);
137-
}
138-
139-
.refresh-button:active {
140-
background-color: var(--vscode-button-activeBackground);
141-
}
142-
143-
.filter {
144-
margin-bottom: 10px;
113+
padding: 8px;
114+
border-bottom: 1px solid var(--vscode-panel-border);
145115
}
146116
147-
.filter-input {
117+
.search-input {
148118
width: 100%;
149119
padding: 4px 8px;
150120
border: 1px solid var(--vscode-input-border);
151-
background: var(--vscode-input-background);
121+
background-color: var(--vscode-input-background);
152122
color: var(--vscode-input-foreground);
153-
border-radius: 2px;
123+
outline: none;
154124
}
155125
156-
.filter-input:focus {
157-
outline: 1px solid var(--vscode-focusBorder);
158-
border-color: transparent;
126+
.search-input:focus {
127+
border-color: var(--vscode-focusBorder);
159128
}
160129
161-
.commits {
162-
display: flex;
163-
flex-direction: column;
164-
gap: 10px;
130+
.git-graph-container {
131+
flex: 1;
132+
overflow: auto;
165133
}
166134
167-
.commit {
135+
.error {
136+
color: var(--vscode-errorForeground);
168137
padding: 8px;
169-
border: 1px solid var(--vscode-panel-border);
170-
border-radius: 4px;
171-
cursor: pointer;
172-
transition: background-color 0.1s;
173-
}
174-
175-
.commit:hover {
176-
background-color: var(--vscode-list-hoverBackground);
177-
}
178-
179-
.commit.selected {
180-
background-color: var(--vscode-list-activeSelectionBackground);
181-
color: var(--vscode-list-activeSelectionForeground);
182-
}
183-
184-
.commit-header {
185-
display: flex;
186-
gap: 8px;
187-
margin-bottom: 4px;
188-
}
189-
190-
.commit-hash {
191-
color: var(--vscode-textLink-foreground);
192-
font-family: monospace;
193-
}
194-
195-
.commit.selected .commit-hash {
196-
color: inherit;
197-
}
198-
199-
.commit-author {
200-
color: var(--vscode-textPreformat-foreground);
201-
}
202-
203-
.commit-message {
204-
color: var(--vscode-foreground);
205-
}
206-
207-
.commit.selected .commit-message,
208-
.commit.selected .commit-author {
209-
color: inherit;
210138
}
211139
</style>

0 commit comments

Comments
 (0)