interface.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { set, delete as del } from 'vue'
  2. const defaultState = {
  3. settingsModalState: 'hidden',
  4. settingsModalLoaded: false,
  5. settingsModalTargetTab: null,
  6. settings: {
  7. currentSaveStateNotice: null,
  8. noticeClearTimeout: null,
  9. notificationPermission: null
  10. },
  11. browserSupport: {
  12. cssFilter: window.CSS && window.CSS.supports && (
  13. window.CSS.supports('filter', 'drop-shadow(0 0)') ||
  14. window.CSS.supports('-webkit-filter', 'drop-shadow(0 0)')
  15. )
  16. },
  17. mobileLayout: false,
  18. globalNotices: [],
  19. layoutHeight: 0,
  20. lastTimeline: null
  21. }
  22. const interfaceMod = {
  23. state: defaultState,
  24. mutations: {
  25. settingsSaved (state, { success, error }) {
  26. if (success) {
  27. if (state.noticeClearTimeout) {
  28. clearTimeout(state.noticeClearTimeout)
  29. }
  30. set(state.settings, 'currentSaveStateNotice', { error: false, data: success })
  31. set(state.settings, 'noticeClearTimeout',
  32. setTimeout(() => del(state.settings, 'currentSaveStateNotice'), 2000))
  33. } else {
  34. set(state.settings, 'currentSaveStateNotice', { error: true, errorData: error })
  35. }
  36. },
  37. setNotificationPermission (state, permission) {
  38. state.notificationPermission = permission
  39. },
  40. setMobileLayout (state, value) {
  41. state.mobileLayout = value
  42. },
  43. closeSettingsModal (state) {
  44. state.settingsModalState = 'hidden'
  45. },
  46. togglePeekSettingsModal (state) {
  47. switch (state.settingsModalState) {
  48. case 'minimized':
  49. state.settingsModalState = 'visible'
  50. return
  51. case 'visible':
  52. state.settingsModalState = 'minimized'
  53. return
  54. default:
  55. throw new Error('Illegal minimization state of settings modal')
  56. }
  57. },
  58. openSettingsModal (state) {
  59. state.settingsModalState = 'visible'
  60. if (!state.settingsModalLoaded) {
  61. state.settingsModalLoaded = true
  62. }
  63. },
  64. setSettingsModalTargetTab (state, value) {
  65. state.settingsModalTargetTab = value
  66. },
  67. pushGlobalNotice (state, notice) {
  68. state.globalNotices.push(notice)
  69. },
  70. removeGlobalNotice (state, notice) {
  71. state.globalNotices = state.globalNotices.filter(n => n !== notice)
  72. },
  73. setLayoutHeight (state, value) {
  74. state.layoutHeight = value
  75. },
  76. setLastTimeline (state, value) {
  77. state.lastTimeline = value
  78. }
  79. },
  80. actions: {
  81. setPageTitle ({ rootState }, option = '') {
  82. document.title = `${option} ${rootState.instance.name}`
  83. },
  84. settingsSaved ({ commit, dispatch }, { success, error }) {
  85. commit('settingsSaved', { success, error })
  86. },
  87. setNotificationPermission ({ commit }, permission) {
  88. commit('setNotificationPermission', permission)
  89. },
  90. setMobileLayout ({ commit }, value) {
  91. commit('setMobileLayout', value)
  92. },
  93. closeSettingsModal ({ commit }) {
  94. commit('closeSettingsModal')
  95. },
  96. openSettingsModal ({ commit }) {
  97. commit('openSettingsModal')
  98. },
  99. togglePeekSettingsModal ({ commit }) {
  100. commit('togglePeekSettingsModal')
  101. },
  102. clearSettingsModalTargetTab ({ commit }) {
  103. commit('setSettingsModalTargetTab', null)
  104. },
  105. openSettingsModalTab ({ commit }, value) {
  106. commit('setSettingsModalTargetTab', value)
  107. commit('openSettingsModal')
  108. },
  109. pushGlobalNotice (
  110. { commit, dispatch },
  111. {
  112. messageKey,
  113. messageArgs = {},
  114. level = 'error',
  115. timeout = 0
  116. }) {
  117. const notice = {
  118. messageKey,
  119. messageArgs,
  120. level
  121. }
  122. if (timeout) {
  123. setTimeout(() => dispatch('removeGlobalNotice', notice), timeout)
  124. }
  125. commit('pushGlobalNotice', notice)
  126. return notice
  127. },
  128. removeGlobalNotice ({ commit }, notice) {
  129. commit('removeGlobalNotice', notice)
  130. },
  131. setLayoutHeight ({ commit }, value) {
  132. commit('setLayoutHeight', value)
  133. },
  134. setLastTimeline ({ commit }, value) {
  135. commit('setLastTimeline', value)
  136. }
  137. }
  138. }
  139. export default interfaceMod