-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathHistoryCardList.vue
More file actions
219 lines (190 loc) · 5.99 KB
/
HistoryCardList.vue
File metadata and controls
219 lines (190 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<script setup lang="ts">
/**
* HistoryCardList Component
*
* A container component that renders a collection of history items as cards.
* This component serves as a bridge between the parent HistoryList component
* and individual HistoryCard components, handling the layout and event delegation.
*
* Features:
* - Displays histories in either grid or list view mode
* - Supports different view contexts (my, shared, published, archived)
* - Handles history selection for bulk operations
* - Delegates events from individual cards to parent components
* - Responsive card layout using CSS container queries
*
* @component HistoryCardList
* @example
* <HistoryCardList
* :histories="historyItems"
* :grid-view="true"
* :selectable="true"
* @select="onHistorySelect"
* @tagClick="onTagClick" />
*/
import { reactive, type Ref, ref } from "vue";
import type { AnyHistoryEntry, MyHistory } from "@/api/histories";
import { isMyHistory } from "@/api/histories";
import { useHistoryStore } from "@/stores/historyStore";
import RenameModal from "@/components/Common/RenameModal.vue";
import HistoryCard from "@/components/History/HistoryCard.vue";
interface Props {
/**
* Array of history entries to display
* @type {AnyHistoryEntry[]}
*/
histories: AnyHistoryEntry[];
/**
* Whether to display histories in grid view mode (default: false for list view)
* @type {boolean}
* @default false
*/
gridView?: boolean;
/**
* Whether this is the published histories view
* @type {boolean}
* @default false
*/
publishedView?: boolean;
/**
* Whether this is the archived histories view
* @type {boolean}
* @default false
*/
archivedView?: boolean;
/**
* Whether this is the shared histories view
* @type {boolean}
* @default false
*/
sharedView?: boolean;
/**
* Whether individual histories can be selected for bulk operations
* @type {boolean}
* @default false
*/
selectable?: boolean;
/**
* Array of currently selected history IDs
* @type {{ id: string }[]}
* @default []
*/
selectedHistoryIds?: { id: string }[];
/**
* Whether cards are clickable for navigation
* @type {boolean}
* @default false
*/
clickable?: boolean;
/**
* Item refs for keyboard navigation
* @type {Record<string, Ref<InstanceType<typeof HistoryCard> | null>>}
* @default {}
*/
itemRefs?: Record<string, Ref<InstanceType<typeof HistoryCard> | null>>;
/**
* Range select anchor for keyboard navigation
* @type {AnyHistoryEntry | undefined}
*/
rangeSelectAnchor?: AnyHistoryEntry;
}
const props = withDefaults(defineProps<Props>(), {
gridView: false,
publishedView: false,
selectable: false,
selectedHistoryIds: () => [],
clickable: false,
itemRefs: () => ({}),
rangeSelectAnchor: undefined,
});
/**
* Events emitted to parent components
*/
const emit = defineEmits<{
/**
* Emitted when a history item is selected for bulk operations
* @event select
*/
(e: "select", history: MyHistory): void;
/**
* Emitted when a tag is clicked on a history card
* @event tagClick
*/
(e: "tagClick", tag: string): void;
/**
* Emitted when the history list needs to be refreshed
* @event refreshList
*/
(e: "refreshList", overlayLoading?: boolean, silent?: boolean): void;
/**
* Emitted when a filter needs to be updated
* @event updateFilter
*/
(e: "updateFilter", key: string, value: any): void;
/**
* Emitted when a keyboard event occurs on a history card
* @event on-key-down
*/
(e: "on-key-down", history: AnyHistoryEntry, event: KeyboardEvent): void;
/**
* Emitted when a history card is clicked
* @event on-history-card-click
*/
(e: "on-history-card-click", history: AnyHistoryEntry, event: Event): void;
}>();
const historyStore = useHistoryStore();
const modalOptions = reactive({
rename: {
id: "",
name: "",
},
});
const showRename = ref(false);
function onRenameClose() {
showRename.value = false;
emit("refreshList", true, true);
}
function onRename(id: string, name: string) {
modalOptions.rename.id = id;
modalOptions.rename.name = name;
showRename.value = true;
}
</script>
<template>
<div class="history-card-list d-flex flex-wrap overflow-auto pt-1">
<HistoryCard
v-for="history in props.histories"
:ref="props.itemRefs[history.id]"
:key="history.id"
tabindex="0"
:history="history"
:grid-view="props.gridView"
:shared-view="props.sharedView"
:published-view="props.publishedView"
:archived-view="props.archivedView"
:selectable="props.selectable"
:selected="props.selectedHistoryIds.some((selected) => selected.id === history.id)"
:clickable="props.clickable"
:highlighted="props.rangeSelectAnchor?.id === history.id"
class="history-card-in-list"
@select="isMyHistory(history) && emit('select', history)"
@tagClick="(...args) => emit('tagClick', ...args)"
@refreshList="(...args) => emit('refreshList', ...args)"
@updateFilter="(...args) => emit('updateFilter', ...args)"
@rename="onRename"
@on-key-down="(...args) => emit('on-key-down', ...args)"
@on-history-card-click="(...args) => emit('on-history-card-click', ...args)" />
<RenameModal
v-if="showRename"
item-type="history"
:name="modalOptions.rename.name"
:rename-action="(newName) => historyStore.updateHistory(modalOptions.rename.id, { name: newName })"
@close="onRenameClose" />
</div>
</template>
<style lang="scss" scoped>
@import "@/style/scss/theme/blue.scss";
.history-card-list {
container: cards-list / inline-size;
}
</style>