logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

bookmark_folders.js (1749B)


  1. import { remove, find } from 'lodash'
  2. export const defaultState = {
  3. allFolders: []
  4. }
  5. export const mutations = {
  6. setBookmarkFolders (state, value) {
  7. state.allFolders = value
  8. },
  9. setBookmarkFolder (state, { id, name, emoji, emoji_url: emojiUrl }) {
  10. const entry = find(state.allFolders, { id })
  11. if (!entry) {
  12. state.allFolders.push({ id, name, emoji, emoji_url: emojiUrl })
  13. } else {
  14. entry.name = name
  15. entry.emoji = emoji
  16. entry.emoji_url = emojiUrl
  17. }
  18. },
  19. deleteBookmarkFolder (state, { folderId }) {
  20. remove(state.allFolders, folder => folder.id === folderId)
  21. }
  22. }
  23. const actions = {
  24. setBookmarkFolders ({ commit }, value) {
  25. commit('setBookmarkFolders', value)
  26. },
  27. createBookmarkFolder ({ rootState, commit }, { name, emoji }) {
  28. return rootState.api.backendInteractor.createBookmarkFolder({ name, emoji })
  29. .then((folder) => {
  30. commit('setBookmarkFolder', folder)
  31. return folder
  32. })
  33. },
  34. setBookmarkFolder ({ rootState, commit }, { folderId, name, emoji }) {
  35. return rootState.api.backendInteractor.updateBookmarkFolder({ folderId, name, emoji })
  36. .then((folder) => {
  37. commit('setBookmarkFolder', folder)
  38. return folder
  39. })
  40. },
  41. deleteBookmarkFolder ({ rootState, commit }, { folderId }) {
  42. rootState.api.backendInteractor.deleteBookmarkFolder({ folderId })
  43. commit('deleteBookmarkFolder', { folderId })
  44. }
  45. }
  46. export const getters = {
  47. findBookmarkFolderName: state => id => {
  48. const folder = state.allFolders.find(folder => folder.id === id)
  49. if (!folder) return
  50. return folder.name
  51. }
  52. }
  53. const bookmarkFolders = {
  54. state: defaultState,
  55. mutations,
  56. actions,
  57. getters
  58. }
  59. export default bookmarkFolders