@fatdoge/wtree 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/routes/worktrees.ts +34 -19
- package/dist/assets/index-bLnnvz_q.css +1 -0
- package/dist/assets/index-sP_n0D3A.js +2246 -0
- package/dist/index.html +2 -2
- package/dist-node/api/routes/worktrees.js +29 -17
- package/package.json +2 -1
- package/shared/wtui-types.ts +14 -4
- package/src/components/DiffPreviewModal.tsx +318 -66
- package/src/components/Modal.tsx +3 -1
- package/src/i18n/locales/en.json +9 -7
- package/src/i18n/locales/zh.json +9 -7
- package/src/pages/Worktrees.tsx +6 -13
- package/src/stores/worktreeStore.ts +3 -3
- package/dist/assets/index-C7vu17w3.js +0 -413
- package/dist/assets/index-DsCX4t5o.css +0 -1
package/src/pages/Worktrees.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Modal from '@/components/Modal'
|
|
|
7
7
|
import DiffPreviewModal from '@/components/DiffPreviewModal'
|
|
8
8
|
import { useWorktreeStore } from '@/stores/worktreeStore'
|
|
9
9
|
import { toast } from 'sonner'
|
|
10
|
-
import type {
|
|
10
|
+
import type { WorktreeDiffInfo } from '../../shared/wtui-types'
|
|
11
11
|
|
|
12
12
|
function truncatePath(p: string) {
|
|
13
13
|
if (p.length <= 70) return p
|
|
@@ -32,8 +32,7 @@ export default function Worktrees() {
|
|
|
32
32
|
const [forceDelete, setForceDelete] = useState(false)
|
|
33
33
|
const [isDeleting, setIsDeleting] = useState(false)
|
|
34
34
|
const [diffWorktreeId, setDiffWorktreeId] = useState<string | null>(null)
|
|
35
|
-
const [
|
|
36
|
-
const [diffContent, setDiffContent] = useState('')
|
|
35
|
+
const [diffInfo, setDiffInfo] = useState<WorktreeDiffInfo | null>(null)
|
|
37
36
|
const [diffLoading, setDiffLoading] = useState(false)
|
|
38
37
|
|
|
39
38
|
const selected = useMemo(() => items.find((x) => x.id === selectedId), [items, selectedId])
|
|
@@ -52,15 +51,11 @@ export default function Worktrees() {
|
|
|
52
51
|
|
|
53
52
|
const openDiff = async (id: string) => {
|
|
54
53
|
setDiffWorktreeId(id)
|
|
55
|
-
|
|
56
|
-
setDiffContent('')
|
|
54
|
+
setDiffInfo(null)
|
|
57
55
|
setDiffLoading(true)
|
|
58
56
|
try {
|
|
59
57
|
const info = await fetchStagedDiff(id)
|
|
60
|
-
if (info)
|
|
61
|
-
setDiffFiles(info.files)
|
|
62
|
-
setDiffContent(info.diff)
|
|
63
|
-
}
|
|
58
|
+
if (info) setDiffInfo(info)
|
|
64
59
|
} finally {
|
|
65
60
|
setDiffLoading(false)
|
|
66
61
|
}
|
|
@@ -68,8 +63,7 @@ export default function Worktrees() {
|
|
|
68
63
|
|
|
69
64
|
const closeDiff = () => {
|
|
70
65
|
setDiffWorktreeId(null)
|
|
71
|
-
|
|
72
|
-
setDiffContent('')
|
|
66
|
+
setDiffInfo(null)
|
|
73
67
|
}
|
|
74
68
|
|
|
75
69
|
const handleDelete = async () => {
|
|
@@ -357,8 +351,7 @@ export default function Worktrees() {
|
|
|
357
351
|
open={Boolean(diffWorktreeId)}
|
|
358
352
|
onClose={closeDiff}
|
|
359
353
|
worktreePath={diffWorktree?.path ?? ''}
|
|
360
|
-
|
|
361
|
-
diff={diffContent}
|
|
354
|
+
diffInfo={diffInfo}
|
|
362
355
|
loading={diffLoading}
|
|
363
356
|
/>
|
|
364
357
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { create } from 'zustand'
|
|
2
|
-
import type { CreateWorktreeRequest, WorktreeItem,
|
|
2
|
+
import type { CreateWorktreeRequest, WorktreeItem, WorktreeDiffInfo } from '../../shared/wtui-types'
|
|
3
3
|
import { apiDelete, apiGet, apiPost } from '@/utils/api'
|
|
4
4
|
|
|
5
5
|
type WorktreeState = {
|
|
@@ -16,7 +16,7 @@ type WorktreeState = {
|
|
|
16
16
|
prune: () => Promise<boolean>
|
|
17
17
|
branches: string[]
|
|
18
18
|
fetchBranches: () => Promise<void>
|
|
19
|
-
fetchStagedDiff: (id: string) => Promise<
|
|
19
|
+
fetchStagedDiff: (id: string) => Promise<WorktreeDiffInfo | null>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const useWorktreeStore = create<WorktreeState>((set, get) => ({
|
|
@@ -92,7 +92,7 @@ export const useWorktreeStore = create<WorktreeState>((set, get) => ({
|
|
|
92
92
|
if (r.ok) set({ branches: r.data })
|
|
93
93
|
},
|
|
94
94
|
fetchStagedDiff: async (id: string) => {
|
|
95
|
-
const r = await apiGet<
|
|
95
|
+
const r = await apiGet<WorktreeDiffInfo>(`/api/worktrees/${encodeURIComponent(id)}/staged`)
|
|
96
96
|
if (r.ok) return r.data
|
|
97
97
|
return null
|
|
98
98
|
},
|