|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { toRefs, computed } from "vue"; |
| 2 | +import { toRefs, computed, ref } from "vue"; |
3 | 3 | import type { Task, Board } from "@/types";
|
4 | 4 | import { useAlerts } from "@/stores/alerts";
|
5 | 5 | import { useQuery, useMutation } from "@vue/apollo-composable";
|
@@ -36,7 +36,20 @@ const board = computed(() => boardData.value?.board || null);
|
36 | 36 | const tasks = computed(() => board.value?.tasks?.items);
|
37 | 37 |
|
38 | 38 | // 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 | +}; |
40 | 53 |
|
41 | 54 | //handle delete board
|
42 | 55 | const { mutate: deleteBoard, onError: onErrorDeletingBoard } = useMutation(
|
@@ -100,7 +113,12 @@ onDoneCreatingTask((res) => {
|
100 | 113 | <div v-if="board">
|
101 | 114 | <div class="flex justify-between">
|
102 | 115 | <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 | + /> |
104 | 122 | </AppPageHeading>
|
105 | 123 | <BoardMenu :board="board" @deleteBoard="deleteBoardIfConfirmed" />
|
106 | 124 | </div>
|
|
0 commit comments