This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/stores/base.ts

121 lines
2.9 KiB
TypeScript
Raw Normal View History

import {readonly, ref} from 'vue'
2022-09-24 13:20:40 +00:00
import {defineStore, acceptHMRUpdate} from 'pinia'
Add easymde & markdown preview for editing descriptions and comments (#183) Make sure no text from previous mounts is left in the editor text field Make preview not the default when rendering descrition settings Add option to show editor by default while still having the option to show preview Add option to show editor by default while still having the option to show preview Use editor component for edit labels Use editor component for edit team Use editor component for edit namespace Use editor component for edit list Use editor component for edit task Make sure we find all checkboxes Fix checking wrong checkbox Make finding and replacing checkboxes in a function actually work Add upading text with checked checkboxes Lazy load editor Remove preview since we have a better one Make easymde smaller by default Add image upload from comments Rename easymde component to editor Only show preview button if editing is currently active Make editor tabs look better when commenting Make comments meta look better Don't try to update if the value was initially set Use editor to render and edit comments Make preview optional Make tabs look better Don't switch to preview after editing Centralize attachment state Render markdown by default Fix title being "null" Fix loading attachment images Add standalone preview Fix callback url Add onsuccess callback Add file upload Fix date parsing once and for all Add more props for upload and such Fix editor border color Fix changing text after mounting Add link to guide Fix sizing of icons Add timeout for changes Add all easymde icons Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/183
2020-07-14 19:26:05 +00:00
2022-09-24 13:20:40 +00:00
import ListModel from '@/models/list'
import {checkAndSetApiUrl} from '@/helpers/checkAndSetApiUrl'
2022-09-21 01:37:39 +00:00
import {useAuthStore} from '@/stores/auth'
2022-09-24 13:20:40 +00:00
import type {IList} from '@/modelTypes/IList'
export const useBaseStore = defineStore('base', () => {
const loading = ref(false)
const ready = ref(false)
// This is used to highlight the current list in menu for all list related views
const currentList = ref<IList | null>(new ListModel({
id: 0,
isArchived: false,
}))
const hasTasks = ref(false)
const menuActive = ref(true)
const keyboardShortcutsActive = ref(false)
const quickActionsActive = ref(false)
const logoVisible = ref(true)
function setLoading(newLoading: boolean) {
loading.value = newLoading
}
function setCurrentList(newCurrentList: IList | null) {
// Server updates don't return the right. Therefore, the right is reset after updating the list which is
// confusing because all the buttons will disappear in that case. To prevent this, we're keeping the right
// when updating the list in global state.
if (
typeof currentList.value?.maxRight !== 'undefined' &&
newCurrentList !== null &&
(
typeof newCurrentList.maxRight === 'undefined' ||
newCurrentList.maxRight === null
)
) {
newCurrentList.maxRight = currentList.value.maxRight
}
currentList.value = newCurrentList
}
function setHasTasks(newHasTasks: boolean) {
hasTasks.value = newHasTasks
}
function setMenuActive(newMenuActive: boolean) {
menuActive.value = newMenuActive
}
function toggleMenu() {
menuActive.value = !menuActive.value
}
function setKeyboardShortcutsActive(value: boolean) {
keyboardShortcutsActive.value = value
}
function setQuickActionsActive(value: boolean) {
quickActionsActive.value = value
}
function setLogoVisible(visible: boolean) {
logoVisible.value = visible
}
function setReady(value: boolean) {
ready.value = value
}
function handleSetCurrentList(
{list}: {list: IList | null},
) {
if (list === null) {
setCurrentList({})
return
}
setCurrentList(list)
}
const authStore = useAuthStore()
async function loadApp() {
await checkAndSetApiUrl(window.API_URL)
await authStore.checkAuth()
ready.value = true
}
return {
loading: readonly(loading),
ready: readonly(ready),
currentList: readonly(currentList),
hasTasks: readonly(hasTasks),
menuActive: readonly(menuActive),
keyboardShortcutsActive: readonly(keyboardShortcutsActive),
quickActionsActive: readonly(quickActionsActive),
logoVisible: readonly(logoVisible),
setLoading,
setCurrentList,
setHasTasks,
setMenuActive,
toggleMenu,
setKeyboardShortcutsActive,
setQuickActionsActive,
setLogoVisible,
setReady,
handleSetCurrentList,
loadApp,
}
})
2022-09-24 13:20:40 +00:00
// support hot reloading
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useBaseStore, import.meta.hot))
}