Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Make bookmark store returns a UNKNOWN bookmark object instead of a null value if not found

天舟c80d100da768
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index dd00549892..5b9b55fc93 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -54,7 +54,7 @@
@click.prevent="toggleBookmark"
>
<svg
- v-if="bookmarked"
+ v-if="isBookmarked"
class="h-5 w-5 text-yellow-400 hover:text-yellow-600"
x-description="Heroicon name: star"
xmlns="http://www.w3.org/2000/svg"
@@ -87,7 +87,7 @@
import { reactive, computed, ComputedRef } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
-import { RouterSlug, User, Bookmark } from "../types";
+import { RouterSlug, User, Bookmark, UNKNOWN_ID } from "../types";
import { idFromSlug } from "../utils";
import database from "../store/modules/database";
@@ -107,13 +107,17 @@ export default {
store.getters["auth/currentUser"]()
);
- const bookmarked: ComputedRef<Bookmark> = computed(() =>
+ const bookmark: ComputedRef<Bookmark> = computed(() =>
store.getters["bookmark/bookmarkByUserAndLink"](
currentUser.value.id,
currentRoute.value.path
)
);
+ const isBookmarked: ComputedRef<Boolean> = computed(
+ () => bookmark.value.id != UNKNOWN_ID
+ );
+
const allowBookmark = computed(() => currentRoute.value.meta.allowBookmark);
const breadcrumbList = computed(() => {
@@ -158,9 +162,9 @@ export default {
});
const toggleBookmark = () => {
- if (bookmarked.value) {
+ if (isBookmarked.value) {
store
- .dispatch("bookmark/deleteBookmark", bookmarked.value)
+ .dispatch("bookmark/deleteBookmark", bookmark.value)
.catch((error) => {
console.log(error);
});
@@ -185,7 +189,8 @@ export default {
return {
allowBookmark,
- bookmarked,
+ bookmark,
+ isBookmarked,
breadcrumbList,
toggleBookmark,
};
diff --git a/frontend/src/store/modules/bookmark.ts b/frontend/src/store/modules/bookmark.ts
index f1fabd343e..31c9ffa44c 100644
--- a/frontend/src/store/modules/bookmark.ts
+++ b/frontend/src/store/modules/bookmark.ts
@@ -5,6 +5,7 @@ import {
BookmarkNew,
BookmarkState,
ResourceObject,
+ unknown,
} from "../../types";
function convert(bookmark: ResourceObject): Bookmark {
@@ -24,15 +25,15 @@ const getters = {
): Bookmark[] => {
return state.bookmarkListByUser.get(userId) || [];
},
- bookmarkByUserAndLink: (state: BookmarkState) => (
+ bookmarkByUserAndLink: (state: BookmarkState, getters: any) => (
userId: UserId,
link: string
- ): Bookmark | undefined => {
- const list = state.bookmarkListByUser.get(userId);
- if (list) {
- return list.find((item: Bookmark) => item.link == link);
- }
- return undefined;
+ ): Bookmark => {
+ const list = getters["bookmarkListByUser"](userId);
+ return (
+ list.find((item: Bookmark) => item.link == link) ||
+ (unknown("BOOKMARK") as Bookmark)
+ );
},
};