Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
fix(page): adhere to type requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Nov 6, 2022
1 parent 8f4cf2a commit ad7c49f
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions pages/tags/list.page.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<ResourceManager
j v-model:slug="slug"
v-model:slug="slug"
v-model:existence="existence"
:is-loaded="isLoaded"
:department-names="[]"
:tag-names="[]">
:department-names="[] as OptionInfo[]"
:tag-names="[] as OptionInfo[]">
<template #header>
<TabbedPageHeader title="Admin Configuration" :tab-infos="resourceTabInfos">
<template #additional-controls>
Expand All @@ -18,7 +18,7 @@ j v-model:slug="slug"
</TabbedPageHeader>
</template>
<template #resources>
<ResourceList :filtered-list="list" :may-edit="mayEdittag"/>
<ResourceList :filtered-list="list" :may-edit="mayEditTag"/>
</template>
</ResourceManager>
</template>
Expand All @@ -27,21 +27,17 @@ j v-model:slug="slug"
</style>

<script setup lang="ts">
import { inject, onMounted, ref, computed, watch } from "vue"
import { inject, ref, computed } from "vue"
import { OptionInfo } from "$@/types/component"
import type { PageContext } from "$/types/renderer"
import type { OptionInfo } from "$@/types/component"
import type { DeserializedTagResource } from "$/types/documents/tag"
import type { DeserializedDepartmentListDocument } from "$/types/documents/department"
import { tag as permissionGroup } from "$/permissions/permission_list"
import { CREATE, UPDATE, ARCHIVE_AND_RESTORE } from "$/permissions/tag_combinations"
import { DEBOUNCED_WAIT_DURATION } from "$@/constants/time"
import resourceTabInfos from "@/resource_management/resource_tab_infos"
import Fetcher from "$@/fetchers/tag"
import debounce from "$@/helpers/debounce"
import loadRemainingDepartments from "@/resource_management/load_remaining_departments"
import TabbedPageHeader from "@/helpers/tabbed_page_header.vue"
import ResourceManager from "@/resource_management/resource_manager.vue"
Expand All @@ -51,51 +47,60 @@ type RequiredExtraProps = "tags"
const pageContext = inject("pageContext") as PageContext<"deserialized", RequiredExtraProps>
const { pageProps } = pageContext
const { userProfile } = pageProps
const mayCreateTag = computed<boolean>(() => {
const roles = userProfile.data.roles.data
const isPermitted = permissionGroup.hasOneRoleAllowed(roles, [
CREATE
])
return isPermitted
})
const mayEditTag = computed<boolean>(() => {
const roles = userProfile.data.roles.data
const isPermitted = permissionGroup.hasOneRoleAllowed(roles, [
UPDATE,
ARCHIVE_AND_RESTORE
])
return isPermitted
})
const fetcher = new Fetcher()
const isLoaded = ref<boolean>(false)
const isLoaded = ref<boolean>(true)
const list = ref<DeserializedTagResource[]>(pageProps.tags.data as DeserializedTagResource[])
const slug = ref<string>("")
const existence = ref<"exists"|"archived"|"*">("exists")
async function countPostsPerTag(IDsToCount: string[]) {
await fetcher.countUsers(IDsToCount).then(response => {
const deserializedData = response.body.data
for (const identifierData of deserializedData) {
const { id, meta } = identifierData
const index = list.value.findIndex(data => data.id === id)
if (index > -1) {
list.value[index].meta = meta
}
}
})
await fetchRoleInfos()
}
async function fetchTagInfos(): Promise<number|void> {
await fetcher.list({
"filter": {
"department": chosenDepartment.value,
"existence": existence.value,
"mustHavePost": false,
"slug": slug.value
},
"page": {
"limit": 10,
"offset": list.value.length
},
"sort": [ "name" ]
}).then(response => {
}).then(({ body }) => {
const { data } = body
isLoaded.value = true
const deserializedData = response.body.data as DeserializedTagResource[]
const IDsToCount = deserializedData.map(data => data.id)
const deserializedData = data as DeserializedTagResource[]
if (deserializedData.length === 0) return Promise.resolve()
list.value = [ ...list.value, ...deserializedData ]
// eslint-disable-next-line no-use-before-define
return countPostsPerTag(IDsToCount)
return Promise.resolve()
})
}
async function refetchTags() {
isLoaded.value = false
list.value = []
await fetchTagInfos()
}
</script>

0 comments on commit ad7c49f

Please sign in to comment.