Working on home page and modal
This commit is contained in:
102
client/stores/forms.js
vendored
102
client/stores/forms.js
vendored
@@ -1,82 +1,36 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {useContentStore} from "~/composables/stores/useContentStore.js";
|
||||
|
||||
export const formsEndpoint = '/open/workspaces/{workspaceId}/forms'
|
||||
export let currentPage = 1
|
||||
|
||||
export const useFormsStore = defineStore('forms', {
|
||||
state: () => ({
|
||||
content: [],
|
||||
loading: false
|
||||
}),
|
||||
getters: {
|
||||
getById: (state) => (id) => {
|
||||
if (state.content.length === 0) return null
|
||||
return state.content.find(item => item.id === id)
|
||||
},
|
||||
getBySlug: (state) => (slug) => {
|
||||
if (state.content.length === 0) return null
|
||||
return state.content.find(item => item.slug === slug)
|
||||
},
|
||||
getAllTags: (state) => {
|
||||
if (state.content.length === 0) return []
|
||||
let allTags = []
|
||||
state.content.forEach(form => {
|
||||
if (form.tags && form.tags.length > 0) {
|
||||
allTags = allTags.concat(form.tags)
|
||||
export const useFormsStore = defineStore('forms', () => {
|
||||
|
||||
const contentStore = useContentStore('slug')
|
||||
contentStore.startLoading()
|
||||
const currentPage = ref(1)
|
||||
|
||||
const load = (workspaceId) => {
|
||||
contentStore.startLoading()
|
||||
return opnFetch(formsEndpoint.replace('{workspaceId}', workspaceId),{query: {page: currentPage.value}})
|
||||
.then((response) => {
|
||||
if (currentPage.value === 1) {
|
||||
contentStore.resetState()
|
||||
contentStore.save(response.data)
|
||||
} else {
|
||||
contentStore.save(response.data)
|
||||
}
|
||||
if (currentPage.value < response.meta.last_page) {
|
||||
currentPage.value++
|
||||
load(workspaceId)
|
||||
} else {
|
||||
contentStore.stopLoading()
|
||||
currentPage.value = 1
|
||||
}
|
||||
})
|
||||
return allTags.filter((item, i, ar) => ar.indexOf(item) === i)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
set(items) {
|
||||
this.content = items
|
||||
},
|
||||
append(items) {
|
||||
this.content = this.content.concat(items)
|
||||
},
|
||||
addOrUpdate(item) {
|
||||
this.content = this.content.filter((val) => val.id !== item.id)
|
||||
this.content.push(item)
|
||||
},
|
||||
remove(item) {
|
||||
this.content = this.content.filter((val) => val.id !== item.id)
|
||||
},
|
||||
startLoading() {
|
||||
this.loading = true
|
||||
},
|
||||
stopLoading() {
|
||||
this.loading = false
|
||||
},
|
||||
resetState() {
|
||||
this.set([])
|
||||
this.stopLoading()
|
||||
currentPage = 1
|
||||
},
|
||||
load(workspaceId) {
|
||||
this.startLoading()
|
||||
return useOpnApi(formsEndpoint.replace('{workspaceId}', workspaceId) + '?page=' + currentPage)
|
||||
.then(({data, error}) => {
|
||||
if (currentPage === 1) {
|
||||
this.set(data.value.data)
|
||||
} else {
|
||||
this.append(data.value.data)
|
||||
}
|
||||
if (currentPage < data.value.meta.last_page) {
|
||||
currentPage += 1
|
||||
this.load(workspaceId)
|
||||
} else {
|
||||
this.stopLoading()
|
||||
currentPage = 1
|
||||
}
|
||||
})
|
||||
},
|
||||
loadIfEmpty(workspaceId) {
|
||||
if (this.content.length === 0) {
|
||||
return this.load(workspaceId)
|
||||
}
|
||||
this.stopLoading()
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...contentStore,
|
||||
load
|
||||
}
|
||||
})
|
||||
|
||||
1
client/stores/templates.js
vendored
1
client/stores/templates.js
vendored
@@ -52,7 +52,6 @@ export const fetchAllTemplates = (options = {}) => {
|
||||
}
|
||||
|
||||
export const loadAllTemplates = async (store, options={}) => {
|
||||
console.log('in------',store, store.allLoaded)
|
||||
if (!store.allLoaded) {
|
||||
store.startLoading()
|
||||
store.initTypesAndIndustries()
|
||||
|
||||
1
client/stores/workspaces.js
vendored
1
client/stores/workspaces.js
vendored
@@ -22,7 +22,6 @@ export const useWorkspacesStore = defineStore('workspaces', () => {
|
||||
|
||||
const save = (items) => {
|
||||
contentStore.save(items)
|
||||
console.log('cookie issi', currentId.value, contentStore.length.value)
|
||||
if (currentId.value == null && contentStore.length.value) {
|
||||
setCurrentId(items[0].id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user