Skip to content

Commit 2f986a3

Browse files
use RenameModal in history list as well
1 parent c772749 commit 2f986a3

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

client/src/components/History/HistoryCard.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ const emit = defineEmits<{
143143
*/
144144
(e: "titleClick", history: AnyHistoryEntry["id"]): void;
145145
146+
/**
147+
* Emitted when the rename action is triggered
148+
* @event rename
149+
*/
150+
(e: "rename", id: string, name: string): void;
151+
146152
/**
147153
* Emitted when a tag is clicked for filtering
148154
* @event tagClick
@@ -270,7 +276,7 @@ function onKeyDown(event: KeyboardEvent) {
270276
:clickable="props.clickable"
271277
:highlighted="props.highlighted"
272278
@titleClick="onTitleClick"
273-
@rename="() => router.push(`/histories/rename?id=${history.id}`)"
279+
@rename="emit('rename', history.id, history.name)"
274280
@select="isMyHistory(history) && emit('select', history)"
275281
@tagsUpdate="(tags) => onTagsUpdate(history.id, tags)"
276282
@tagClick="(tag) => emit('tagClick', tag)"

client/src/components/History/HistoryCardList.vue

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
* @tagClick="onTagClick" />
2424
*/
2525
26-
import type { Ref } from "vue";
26+
import { reactive, type Ref, ref } from "vue";
2727
2828
import type { AnyHistoryEntry, MyHistory } from "@/api/histories";
2929
import { isMyHistory } from "@/api/histories";
30+
import { useHistoryStore } from "@/stores/historyStore";
3031
32+
import RenameModal from "@/components/Common/RenameModal.vue";
3133
import HistoryCard from "@/components/History/HistoryCard.vue";
3234
3335
interface Props {
@@ -150,6 +152,28 @@ const emit = defineEmits<{
150152
*/
151153
(e: "on-history-card-click", history: AnyHistoryEntry, event: Event): void;
152154
}>();
155+
156+
const historyStore = useHistoryStore();
157+
158+
const modalOptions = reactive({
159+
rename: {
160+
id: "",
161+
name: "",
162+
},
163+
});
164+
165+
const showRename = ref(false);
166+
167+
function onRenameClose() {
168+
showRename.value = false;
169+
emit("refreshList", true, true);
170+
}
171+
172+
function onRename(id: string, name: string) {
173+
modalOptions.rename.id = id;
174+
modalOptions.rename.name = name;
175+
showRename.value = true;
176+
}
153177
</script>
154178

155179
<template>
@@ -173,8 +197,16 @@ const emit = defineEmits<{
173197
@tagClick="(...args) => emit('tagClick', ...args)"
174198
@refreshList="(...args) => emit('refreshList', ...args)"
175199
@updateFilter="(...args) => emit('updateFilter', ...args)"
200+
@rename="onRename"
176201
@on-key-down="(...args) => emit('on-key-down', ...args)"
177202
@on-history-card-click="(...args) => emit('on-history-card-click', ...args)" />
203+
204+
<RenameModal
205+
v-if="showRename"
206+
item-type="history"
207+
:name="modalOptions.rename.name"
208+
:rename-action="(newName) => historyStore.updateHistory(modalOptions.rename.id, { name: newName })"
209+
@close="onRenameClose" />
178210
</div>
179211
</template>
180212

0 commit comments

Comments
 (0)