Add new route for individual bookmarks

This commit is contained in:
Marcel Klehr 2020-08-02 08:16:08 +02:00
parent c492c42e31
commit f214df8e2a
5 changed files with 36 additions and 3 deletions

View File

@ -24,7 +24,8 @@ return [
['name' => 'web_view#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'web_view#index', 'url' => '/recent', 'verb' => 'GET', 'postfix' => 'recent'],
['name' => 'web_view#index', 'url' => '/search/{search}', 'verb' => 'GET', 'postfix' => 'search'],
['name' => 'web_view#index', 'url' => '/folder/{folder}', 'verb' => 'GET', 'postfix' => 'folder'],
['name' => 'web_view#index', 'url' => '/folders/{folder}', 'verb' => 'GET', 'postfix' => 'folder'],
['name' => 'web_view#index', 'url' => '/bookmarks/{bookmark}', 'verb' => 'GET', 'postfix' => 'bookmark'],
['name' => 'web_view#index', 'url' => '/tags/{tags}', 'verb' => 'GET', 'postfix' => 'tags'],
['name' => 'web_view#index', 'url' => '/untagged', 'verb' => 'GET', 'postfix' => 'untagged'],
['name' => 'web_view#index', 'url' => '/bookmarklet', 'verb' => 'GET', 'postfix' => 'bookmarklet'],

View File

@ -49,7 +49,7 @@ class Provider implements IProvider {
$bookmarks = $this->bookmarkMapper->findAll($user->getUID(), explode(' ', $query->getTerm()), $params);
$results = array_map(function (Bookmark $bookmark) {
$favicon = $this->url->linkToRouteAbsolute('bookmarks.internal_bookmark.get_bookmark_favicon', ['id' => $bookmark->getId()]);
$favicon = $this->url->linkToRouteAbsolute('bookmarks.web_view.indexbookmark', ['bookmark' => $bookmark->getId()]);
return new SearchResultEntry($favicon, $bookmark->getTitle(), $bookmark->getUrl(), $bookmark->getUrl());
}, $bookmarks);

View File

@ -85,6 +85,11 @@ export default {
case privateRoutes.UNTAGGED:
this.$store.dispatch(actions.FILTER_BY_UNTAGGED)
break
case privateRoutes.BOOKMARK:
await this.$store.dispatch(actions.LOAD_BOOKMARK, route.params.bookmark)
this.$store.dispatch(actions.OPEN_BOOKMARK, route.params.bookmark)
this.$store.commit(mutations.FETCH_END, { type: 'bookmarks' })
break
case privateRoutes.FOLDER:
this.$store.dispatch(actions.FILTER_BY_FOLDER, route.params.folder)
break

View File

@ -12,6 +12,7 @@ export const privateRoutes = {
RECENT: 'recent',
SEARCH: 'search',
FOLDER: 'folder',
BOOKMARK: 'bookmark',
TAGS: 'tags',
UNTAGGED: 'untagged',
BOOKMARKLET: 'bookmarklet',
@ -48,10 +49,15 @@ export default new Router({
component: ViewPrivate,
},
{
path: '/folder/:folder',
path: '/folders/:folder',
name: privateRoutes.FOLDER,
component: ViewPrivate,
},
{
path: '/bookmarks/:bookmark',
name: privateRoutes.BOOKMARK,
component: ViewPrivate,
},
{
path: '/tags/:tags',
name: privateRoutes.TAGS,

View File

@ -10,6 +10,7 @@ export const actions = {
COUNT_BOOKMARKS: 'COUNT_BOOKMARKS',
CREATE_BOOKMARK: 'CREATE_BOOKMARK',
FIND_BOOKMARK: 'FIND_BOOKMARK',
LOAD_BOOKMARK: 'LOAD_BOOKMARK',
DELETE_BOOKMARK: 'DELETE_BOOKMARK',
OPEN_BOOKMARK: 'OPEN_BOOKMARK',
SAVE_BOOKMARK: 'SAVE_BOOKMARK',
@ -82,6 +83,26 @@ export default {
throw err
}
},
async [actions.LOAD_BOOKMARK]({ commit, dispatch, state }, id) {
try {
const response = await axios.get(url(state, `/bookmark/${id}`))
const {
data: { item: bookmark, status },
} = response
if (status !== 'success') {
throw new Error(response.data)
}
commit(mutations.ADD_BOOKMARK, bookmark)
return bookmark
} catch (err) {
console.error(err)
commit(
mutations.SET_ERROR,
AppGlobal.methods.t('bookmarks', 'Failed to load bookmark')
)
throw err
}
},
async [actions.FIND_BOOKMARK]({ commit, dispatch, state }, link) {
if (state.loading.bookmarks) return
try {