logo

pleroma-fe

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

interface.js (5369B)


  1. const defaultState = {
  2. themeApplied: false,
  3. settingsModalState: 'hidden',
  4. settingsModalLoadedUser: false,
  5. settingsModalLoadedAdmin: false,
  6. settingsModalTargetTab: null,
  7. settingsModalMode: 'user',
  8. settings: {
  9. currentSaveStateNotice: null,
  10. noticeClearTimeout: null,
  11. notificationPermission: null
  12. },
  13. browserSupport: {
  14. cssFilter: window.CSS && window.CSS.supports && (
  15. window.CSS.supports('filter', 'drop-shadow(0 0)') ||
  16. window.CSS.supports('-webkit-filter', 'drop-shadow(0 0)')
  17. )
  18. },
  19. layoutType: 'normal',
  20. globalNotices: [],
  21. layoutHeight: 0,
  22. lastTimeline: null
  23. }
  24. const interfaceMod = {
  25. state: defaultState,
  26. mutations: {
  27. settingsSaved (state, { success, error }) {
  28. if (success) {
  29. if (state.noticeClearTimeout) {
  30. clearTimeout(state.noticeClearTimeout)
  31. }
  32. state.settings.currentSaveStateNotice = { error: false, data: success }
  33. state.settings.noticeClearTimeout = setTimeout(() => delete state.settings.currentSaveStateNotice, 2000)
  34. } else {
  35. state.settings.currentSaveStateNotice = { error: true, errorData: error }
  36. }
  37. },
  38. setThemeApplied (state) {
  39. state.themeApplied = true
  40. },
  41. setNotificationPermission (state, permission) {
  42. state.notificationPermission = permission
  43. },
  44. setLayoutType (state, value) {
  45. state.layoutType = value
  46. },
  47. closeSettingsModal (state) {
  48. state.settingsModalState = 'hidden'
  49. },
  50. togglePeekSettingsModal (state) {
  51. switch (state.settingsModalState) {
  52. case 'minimized':
  53. state.settingsModalState = 'visible'
  54. return
  55. case 'visible':
  56. state.settingsModalState = 'minimized'
  57. return
  58. default:
  59. throw new Error('Illegal minimization state of settings modal')
  60. }
  61. },
  62. openSettingsModal (state, value) {
  63. state.settingsModalMode = value
  64. state.settingsModalState = 'visible'
  65. if (value === 'user') {
  66. if (!state.settingsModalLoadedUser) {
  67. state.settingsModalLoadedUser = true
  68. }
  69. } else if (value === 'admin') {
  70. if (!state.settingsModalLoadedAdmin) {
  71. state.settingsModalLoadedAdmin = true
  72. }
  73. }
  74. },
  75. setSettingsModalTargetTab (state, value) {
  76. state.settingsModalTargetTab = value
  77. },
  78. pushGlobalNotice (state, notice) {
  79. state.globalNotices.push(notice)
  80. },
  81. removeGlobalNotice (state, notice) {
  82. state.globalNotices = state.globalNotices.filter(n => n !== notice)
  83. },
  84. setLayoutHeight (state, value) {
  85. state.layoutHeight = value
  86. },
  87. setLayoutWidth (state, value) {
  88. state.layoutWidth = value
  89. },
  90. setLastTimeline (state, value) {
  91. state.lastTimeline = value
  92. }
  93. },
  94. actions: {
  95. setPageTitle ({ rootState }, option = '') {
  96. document.title = `${option} ${rootState.instance.name}`
  97. },
  98. settingsSaved ({ commit, dispatch }, { success, error }) {
  99. commit('settingsSaved', { success, error })
  100. },
  101. setNotificationPermission ({ commit }, permission) {
  102. commit('setNotificationPermission', permission)
  103. },
  104. closeSettingsModal ({ commit }) {
  105. commit('closeSettingsModal')
  106. },
  107. openSettingsModal ({ commit }, value = 'user') {
  108. commit('openSettingsModal', value)
  109. },
  110. togglePeekSettingsModal ({ commit }) {
  111. commit('togglePeekSettingsModal')
  112. },
  113. clearSettingsModalTargetTab ({ commit }) {
  114. commit('setSettingsModalTargetTab', null)
  115. },
  116. openSettingsModalTab ({ commit }, value) {
  117. commit('setSettingsModalTargetTab', value)
  118. commit('openSettingsModal', 'user')
  119. },
  120. pushGlobalNotice (
  121. { commit, dispatch, state },
  122. {
  123. messageKey,
  124. messageArgs = {},
  125. level = 'error',
  126. timeout = 0
  127. }) {
  128. const notice = {
  129. messageKey,
  130. messageArgs,
  131. level
  132. }
  133. commit('pushGlobalNotice', notice)
  134. // Adding a new element to array wraps it in a Proxy, which breaks the comparison
  135. // TODO: Generate UUID or something instead or relying on !== operator?
  136. const newNotice = state.globalNotices[state.globalNotices.length - 1]
  137. if (timeout) {
  138. setTimeout(() => dispatch('removeGlobalNotice', newNotice), timeout)
  139. }
  140. return newNotice
  141. },
  142. removeGlobalNotice ({ commit }, notice) {
  143. commit('removeGlobalNotice', notice)
  144. },
  145. setLayoutHeight ({ commit }, value) {
  146. commit('setLayoutHeight', value)
  147. },
  148. // value is optional, assuming it was cached prior
  149. setLayoutWidth ({ commit, state, rootGetters, rootState }, value) {
  150. let width = value
  151. if (value !== undefined) {
  152. commit('setLayoutWidth', value)
  153. } else {
  154. width = state.layoutWidth
  155. }
  156. const mobileLayout = width <= 800
  157. const normalOrMobile = mobileLayout ? 'mobile' : 'normal'
  158. const { thirdColumnMode } = rootGetters.mergedConfig
  159. if (thirdColumnMode === 'none' || !rootState.users.currentUser) {
  160. commit('setLayoutType', normalOrMobile)
  161. } else {
  162. const wideLayout = width >= 1300
  163. commit('setLayoutType', wideLayout ? 'wide' : normalOrMobile)
  164. }
  165. },
  166. setLastTimeline ({ commit }, value) {
  167. commit('setLastTimeline', value)
  168. }
  169. }
  170. }
  171. export default interfaceMod