Skip to content

Commit 9344407

Browse files
committed
fix
1 parent c3baa0b commit 9344407

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ import {diffTreeStore} from '../modules/stores.ts';
44
import {computed, nextTick, ref, watch} from 'vue';
55
import type {Item, DirItem, File, FileStatus} from '../utils/filetree.ts';
66
7+
// ------------------------------------------------------------
8+
// Component Props
9+
// ------------------------------------------------------------
710
const props = defineProps<{
811
item: Item,
912
setViewed?:(val: boolean) => void,
1013
}>();
1114
15+
// ------------------------------------------------------------
16+
// Reactive State & Refs
17+
// ------------------------------------------------------------
18+
const store = diffTreeStore();
1219
const count = ref(0);
1320
let pendingUpdate = 0;
1421
let pendingTimer: Promise<void> | undefined;
15-
22+
// ------------------------------------------------------------
23+
// Batch Update Mechanism
24+
// ------------------------------------------------------------
25+
/**
26+
* Handles batched updates to count value
27+
* Prevents multiple updates within the same tick
28+
*/
1629
const setCount = (isViewed: boolean) => {
1730
pendingUpdate += (isViewed ? 1 : -1);
1831
@@ -25,10 +38,24 @@ const setCount = (isViewed: boolean) => {
2538
}
2639
};
2740
41+
// ------------------------------------------------------------
42+
// Computed Properties
43+
// ------------------------------------------------------------
44+
/**
45+
* Determines viewed state based on item type:
46+
* - Files: Directly use IsViewed property
47+
* - Directories: Compare children count with viewed count
48+
*/
2849
const isViewed = computed(() => {
2950
return props.item.isFile ? props.item.file.IsViewed : (props.item as DirItem).children.length === count.value;
3051
});
31-
52+
// ------------------------------------------------------------
53+
// Watchers & Side Effects
54+
// ------------------------------------------------------------
55+
/**
56+
* Propagate viewed state changes to parent component
57+
* Using post flush to ensure DOM updates are complete
58+
*/
3259
watch(
3360
() => isViewed.value,
3461
(newVal) => {
@@ -39,12 +66,14 @@ watch(
3966
{immediate: true, flush: 'post'},
4067
);
4168
42-
const store = diffTreeStore();
43-
69+
// ------------------------------------------------------------
70+
// Collapse Behavior Documentation
71+
// ------------------------------------------------------------
4472
/**
45-
* Behavior:
46-
* - Viewed folders collapse on initial load (based on `isViewed` state)
47-
* - Manual expand/collapse via clicks remains enabled
73+
* Collapse behavior rules:
74+
* - Viewed folders start collapsed initially
75+
* - Manual expand/collapse takes precedence over automatic behavior
76+
* - State persists after manual interaction
4877
*/
4978
const collapsed = ref(isViewed.value);
5079
@@ -92,11 +121,11 @@ function fileIcon(file: File) {
92121
class="text primary"
93122
:name="collapsed ? 'octicon-file-directory-fill' : 'octicon-file-directory-open-fill'"
94123
/>
95-
<span class="gt-ellipsis">{{ item.name }} {{ count }}</span>
124+
<span class="gt-ellipsis">{{ item.name }}</span>
96125
</div>
97126

98127
<div v-show="!collapsed" class="sub-items">
99-
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" :setViewed="setCount"/>
128+
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" :set-viewed="setCount"/>
100129
</div>
101130
</template>
102131
</template>

0 commit comments

Comments
 (0)