2024-04-22 07:06:23 +02:00
|
|
|
import { DBSearchHistoryHandlers } from '../../../datastores/handlers/index'
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
pageBookmarks: []
|
|
|
|
}
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
getPageBookmarks: () => {
|
|
|
|
return state.pageBookmarks
|
|
|
|
},
|
|
|
|
|
|
|
|
getPageBookmarkWithRoute: (state) => (route) => {
|
|
|
|
const pageBookmark = state.pageBookmarks.find(p => p.route === route)
|
|
|
|
return pageBookmark
|
2024-04-22 17:58:47 +02:00
|
|
|
},
|
|
|
|
|
2024-04-23 03:02:36 +02:00
|
|
|
getPageBookmarksMatchingQuery: (state) => (query, routeToExclude) => {
|
|
|
|
if (query === '') {
|
2024-04-22 17:58:47 +02:00
|
|
|
return []
|
|
|
|
}
|
2024-04-23 03:02:36 +02:00
|
|
|
const queryToLower = query.toLowerCase()
|
2024-04-22 17:58:47 +02:00
|
|
|
const pageBookmarks = state.pageBookmarks.filter((pageBookmark) =>
|
2024-04-23 03:02:36 +02:00
|
|
|
pageBookmark && pageBookmark.bookmarkName.toLowerCase().includes(queryToLower) && pageBookmark.route !== routeToExclude
|
2024-04-22 17:58:47 +02:00
|
|
|
)
|
|
|
|
return pageBookmarks
|
2024-04-22 07:06:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const actions = {
|
2024-04-22 17:58:47 +02:00
|
|
|
async grabPageBookmarks({ commit }) {
|
|
|
|
try {
|
|
|
|
const results = await DBSearchHistoryHandlers.find()
|
|
|
|
commit('setPageBookmarks', results)
|
|
|
|
} catch (errMessage) {
|
|
|
|
console.error(errMessage)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-04-22 07:06:23 +02:00
|
|
|
async createPageBookmark({ commit }, pageBookmark) {
|
2024-04-22 17:58:47 +02:00
|
|
|
try {
|
|
|
|
const newPageBookmark = await DBSearchHistoryHandlers.create(pageBookmark)
|
|
|
|
commit('addPageBookmarkToList', newPageBookmark)
|
|
|
|
} catch (errMessage) {
|
|
|
|
console.error(errMessage)
|
|
|
|
}
|
2024-04-22 07:06:23 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
async updatePageBookmark({ commit }, pageBookmark) {
|
|
|
|
try {
|
|
|
|
await DBSearchHistoryHandlers.upsert(pageBookmark)
|
|
|
|
commit('upsertPageBookmarkToList', pageBookmark)
|
|
|
|
} catch (errMessage) {
|
|
|
|
console.error(errMessage)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async removePageBookmark({ commit }, route) {
|
|
|
|
try {
|
|
|
|
await DBSearchHistoryHandlers.delete(route)
|
|
|
|
commit('removePageBookmarkFromList', route)
|
|
|
|
} catch (errMessage) {
|
|
|
|
console.error(errMessage)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async removeAllPageBookmarks({ commit }) {
|
|
|
|
try {
|
|
|
|
await DBSearchHistoryHandlers.deleteAll()
|
|
|
|
commit('setPageBookmarks', [])
|
|
|
|
} catch (errMessage) {
|
|
|
|
console.error(errMessage)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations = {
|
2024-04-22 17:58:47 +02:00
|
|
|
addPageBookmarkToList(state, pageBookmark) {
|
|
|
|
state.pageBookmarks.push(pageBookmark)
|
|
|
|
},
|
|
|
|
|
2024-04-22 07:06:23 +02:00
|
|
|
setPageBookmarks(state, pageBookmarks) {
|
|
|
|
state.pageBookmarks = pageBookmarks
|
|
|
|
},
|
|
|
|
|
|
|
|
upsertPageBookmarkToList(state, updatedPageBookmark) {
|
|
|
|
const i = state.pageBookmarks.findIndex((p) => {
|
|
|
|
return p.route === updatedPageBookmark.route
|
|
|
|
})
|
|
|
|
|
|
|
|
if (i === -1) {
|
|
|
|
state.pageBookmarks.push(updatedPageBookmark)
|
|
|
|
} else {
|
|
|
|
state.pageBookmarks.splice(i, 1, updatedPageBookmark)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-04-22 17:58:47 +02:00
|
|
|
removePageBookmarkFromList(state, route) {
|
2024-04-22 07:06:23 +02:00
|
|
|
const i = state.pageBookmarks.findIndex((pageBookmark) => {
|
2024-04-22 17:58:47 +02:00
|
|
|
return pageBookmark.route === route
|
2024-04-22 07:06:23 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
state.pageBookmarks.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations
|
|
|
|
}
|