From 2b6de423d5a02413924f18910b1ce3538a5a1625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 24 Sep 2024 18:15:49 +0200 Subject: [PATCH] Bookmark folder editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- src/boot/routes.js | 5 +- .../bookmark_folder_card.js | 7 +- .../bookmark_folder_card.vue | 51 ++++++- .../bookmark_folder_edit.js | 65 +++++++++ .../bookmark_folder_edit.vue | 125 ++++++++++++++++++ .../bookmark_folders/bookmark_folders.vue | 2 +- .../navigation/navigation_entry.vue | 5 + src/i18n/en.json | 10 +- src/modules/bookmark_folders.js | 6 +- src/services/api/api.service.js | 4 +- 10 files changed, 269 insertions(+), 11 deletions(-) create mode 100644 src/components/bookmark_folder_edit/bookmark_folder_edit.js create mode 100644 src/components/bookmark_folder_edit/bookmark_folder_edit.vue diff --git a/src/boot/routes.js b/src/boot/routes.js index ff93bb51..f87b2ec8 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -27,6 +27,7 @@ import NavPanel from 'src/components/nav_panel/nav_panel.vue' import AnnouncementsPage from 'components/announcements_page/announcements_page.vue' import QuotesTimeline from '../components/quotes_timeline/quotes_timeline.vue' import BookmarkFolders from '../components/bookmark_folders/bookmark_folders.vue' +import BookmarkFolderEdit from '../components/bookmark_folder_edit/bookmark_folder_edit.vue' export default (store) => { const validateAuthenticatedRoute = (to, from, next) => { @@ -89,7 +90,9 @@ export default (store) => { { name: 'lists-new', path: '/lists/new', component: ListsEdit }, { name: 'edit-navigation', path: '/nav-edit', component: NavPanel, props: () => ({ forceExpand: true, forceEditMode: true }), beforeEnter: validateAuthenticatedRoute }, { name: 'bookmark-folders', path: '/bookmark_folders', component: BookmarkFolders }, - { name: 'bookmark-folder', path: '/bookmarks/:id', component: BookmarkTimeline } + { name: 'bookmark-folder-new', path: '/bookmarks/new-folder', component: BookmarkFolderEdit }, + { name: 'bookmark-folder', path: '/bookmarks/:id', component: BookmarkTimeline }, + { name: 'bookmark-folder-edit', path: '/bookmarks/:id/edit', component: BookmarkFolderEdit } ] if (store.state.instance.pleromaChatMessagesAvailable) { diff --git a/src/components/bookmark_folder_card/bookmark_folder_card.js b/src/components/bookmark_folder_card/bookmark_folder_card.js index 9df28e19..7a7206aa 100644 --- a/src/components/bookmark_folder_card/bookmark_folder_card.js +++ b/src/components/bookmark_folder_card/bookmark_folder_card.js @@ -10,7 +10,12 @@ library.add( const BookmarkFolderCard = { props: [ 'folder' - ] + ], + computed: { + firstLetter () { + return this.folder.name[0] + } + } } export default BookmarkFolderCard diff --git a/src/components/bookmark_folder_card/bookmark_folder_card.vue b/src/components/bookmark_folder_card/bookmark_folder_card.vue index 10875e78..b773c9fb 100644 --- a/src/components/bookmark_folder_card/bookmark_folder_card.vue +++ b/src/components/bookmark_folder_card/bookmark_folder_card.vue @@ -4,10 +4,28 @@ :to="{ name: 'bookmark-folder', params: { id: folder.id } }" class="bookmark-folder-name" > - {{ folder.name }} + + + + {{ folder.emoji }} + + + {{ firstLetter }}{{ folder.name }} span { + font-size: 1.5rem; + line-height: 2.5rem; + } + } + + img.iconEmoji { + padding: 0.25em; + box-sizing: border-box; + } } .bookmark-folder-name, diff --git a/src/components/bookmark_folder_edit/bookmark_folder_edit.js b/src/components/bookmark_folder_edit/bookmark_folder_edit.js new file mode 100644 index 00000000..8c5d3cfd --- /dev/null +++ b/src/components/bookmark_folder_edit/bookmark_folder_edit.js @@ -0,0 +1,65 @@ +import apiService from '../../services/api/api.service' + +const BookmarkFolderEdit = { + data () { + return { + name: '', + nameDraft: '', + emoji: '', + emojiUrl: null, + emojiDraft: '', + emojiUrlDraft: null, + reallyDelete: false + } + }, + created () { + if (!this.id) return + const credentials = this.$store.state.users.currentUser.credentials + apiService.fetchBookmarkFolders({ credentials }) + .then((folders) => { + const folder = folders.find(folder => folder.id === this.id) + if (!folder) return + + this.nameDraft = this.name = folder.name + this.emojiDraft = this.emoji = folder.emoji + this.emojiUrlDraft = this.emojiUrl = folder.emoji_url + }) + }, + computed: { + id () { + return this.$route.params.id + } + }, + methods: { + updateFolder () { + this.$store.dispatch('setBookmarkFolder', { folderId: this.id, name: this.nameDraft, emoji: this.emojiDraft }) + .then((folder) => { + this.nameDraft = this.name = folder.name + this.emojiDraft = this.emoji = folder.emoji + this.emojiUrlDraft = this.emojiUrl = folder.emoji_url + }) + }, + createFolder () { + this.$store.dispatch('createBookmarkFolder', { name: this.nameDraft, emoji: this.emojiDraft }) + .then((folder) => { + return folder.id + }) + .then((folderId) => { + this.$router.push({ name: 'bookmark-folders' }) + }) + .catch((e) => { + this.$store.dispatch('pushGlobalNotice', { + messageKey: 'bookmark_folders.error', + messageArgs: [e.message], + level: 'error' + }) + }) + }, + deleteFolder () { + this.$store.dispatch('deleteBookmarkFolder', { folderId: this.id }) + this.$router.push({ name: 'bookmark-folders' }) + } + } +} + +export default BookmarkFolderEdit diff --git a/src/components/bookmark_folder_edit/bookmark_folder_edit.vue b/src/components/bookmark_folder_edit/bookmark_folder_edit.vue new file mode 100644 index 00000000..30bbde09 --- /dev/null +++ b/src/components/bookmark_folder_edit/bookmark_folder_edit.vue @@ -0,0 +1,125 @@ + + + + + diff --git a/src/components/bookmark_folders/bookmark_folders.vue b/src/components/bookmark_folders/bookmark_folders.vue index 733e4cab..65b1a11b 100644 --- a/src/components/bookmark_folders/bookmark_folders.vue +++ b/src/components/bookmark_folders/bookmark_folders.vue @@ -5,7 +5,7 @@ {{ $t('nav.bookmark_folders') }} {{ $t("bookmark_folders.new") }} diff --git a/src/components/navigation/navigation_entry.vue b/src/components/navigation/navigation_entry.vue index 728de1be..024ee314 100644 --- a/src/components/navigation/navigation_entry.vue +++ b/src/components/navigation/navigation_entry.vue @@ -137,5 +137,10 @@ font-size: 1.5rem; } } + + img.iconEmoji { + padding: 0.25rem; + box-sizing: border-box; + } } diff --git a/src/i18n/en.json b/src/i18n/en.json index 9d10b560..5a9bee32 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1409,7 +1409,15 @@ "tooltip": "This domain contains non-ascii characters." }, "bookmark_folders": { + "create": "Create folder", + "creating_folder": "Creating bookmark folder", + "delete": "Delete folder", + "editing_folder": "Editing folder {folderName}", + "error": "Error manipulating bookmark folders: {0}", + "name": "Folder name", "new": "New Folder", - "select_folder": "Select bookmark folder" + "really_delete": "Do you really want to delete the folder?", + "select_folder": "Select bookmark folder", + "update_folder": "Save changes" } } diff --git a/src/modules/bookmark_folders.js b/src/modules/bookmark_folders.js index e5f25791..5dde58a7 100644 --- a/src/modules/bookmark_folders.js +++ b/src/modules/bookmark_folders.js @@ -8,10 +8,10 @@ export const mutations = { setBookmarkFolders (state, value) { state.allFolders = value }, - setBookmarkFolder (state, { folderId, name, emoji, emojiUrl }) { - const entry = find(state.allFolders, { id: name }) + setBookmarkFolder (state, { id, name, emoji, emojiUrl }) { + const entry = find(state.allFolders, { id }) if (!entry) { - state.allFolders.push({ id: folderId, name, emoji, emojiUrl }) + state.allFolders.push({ id, name, emoji, emojiUrl }) } else { entry.name = name entry.emoji = emoji diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 43896ae7..94c12360 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1927,9 +1927,9 @@ const updateBookmarkFolder = ({ folderId, name, emoji, credentials }) => { return fetch(url, { headers, - method: 'PUT', + method: 'PATCH', body: JSON.stringify({ name, emoji }) - }) + }).then((data) => data.json()) } const deleteBookmarkFolder = ({ folderId, credentials }) => {