Skip to content

Commit 1327249

Browse files
committed
update board title
1 parent a06bb6f commit 1327249

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/pages/boards/[id].vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { toRefs, computed } from "vue";
2+
import { toRefs, computed, ref } from "vue";
33
import type { Task, Board } from "@/types";
44
import { useAlerts } from "@/stores/alerts";
55
import { useQuery, useMutation } from "@vue/apollo-composable";
@@ -36,7 +36,20 @@ const board = computed(() => boardData.value?.board || null);
3636
const tasks = computed(() => board.value?.tasks?.items);
3737
3838
// handle board updates
39-
const { mutate: updateBoard } = useMutation(updateBoardMutation);
39+
const updatingTitle = ref(false);
40+
const { mutate: updateBoard, onDone: onBoardUpdated } =
41+
useMutation(updateBoardMutation);
42+
onBoardUpdated(() => {
43+
if (updatingTitle.value) {
44+
alerts.success("Board successfully updated!");
45+
}
46+
});
47+
const updateBoardTitle = async (title: string) => {
48+
if (board.value.title === title) return;
49+
updatingTitle.value = true;
50+
await updateBoard({ id: boardId.value, title });
51+
updatingTitle.value = false;
52+
};
4053
4154
//handle delete board
4255
const { mutate: deleteBoard, onError: onErrorDeletingBoard } = useMutation(
@@ -100,7 +113,12 @@ onDoneCreatingTask((res) => {
100113
<div v-if="board">
101114
<div class="flex justify-between">
102115
<AppPageHeading>
103-
{{ board.title }}
116+
<input
117+
@keydown.enter="($event.target as HTMLInputElement).blur()"
118+
@blur="updateBoardTitle(($event.target as HTMLInputElement).value)"
119+
type="text"
120+
:value="board.title"
121+
/>
104122
</AppPageHeading>
105123
<BoardMenu :board="board" @deleteBoard="deleteBoardIfConfirmed" />
106124
</div>

0 commit comments

Comments
 (0)