Scope knowledge and image libraries by brand
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { imagesApi } from '@/lib/api'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
import type { ScheduleCoverMode, ScheduleCoverRandomScope } from '@geo/shared-types'
|
||||
import { useQuery } from '@tanstack/vue-query'
|
||||
import { computed, watch } from 'vue'
|
||||
@@ -24,10 +25,12 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const companyStore = useCompanyStore()
|
||||
const currentBrandId = computed(() => companyStore.currentBrandId)
|
||||
|
||||
const foldersQuery = useQuery({
|
||||
queryKey: ['images', 'folders', 'cover-source'],
|
||||
enabled: computed(() => !props.disabled),
|
||||
queryKey: computed(() => ['images', 'folders', 'cover-source', currentBrandId.value]),
|
||||
enabled: computed(() => !props.disabled && Boolean(currentBrandId.value)),
|
||||
queryFn: () => imagesApi.listFolders(),
|
||||
})
|
||||
|
||||
@@ -38,6 +41,13 @@ const folderOptions = computed(() =>
|
||||
})),
|
||||
)
|
||||
|
||||
watch(
|
||||
currentBrandId,
|
||||
() => {
|
||||
emit('update:randomFolderId', null)
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.mode,
|
||||
(mode) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { imagesApi } from '@/lib/api'
|
||||
import { formatBytes, formatPercentage } from '@/lib/display'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
import type { ImageAssetItem } from '@geo/shared-types'
|
||||
import { useQuery } from '@tanstack/vue-query'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
@@ -20,6 +21,8 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const companyStore = useCompanyStore()
|
||||
const currentBrandId = computed(() => companyStore.currentBrandId)
|
||||
|
||||
// State
|
||||
const selectedFolderId = ref<number | null>(null)
|
||||
@@ -31,7 +34,8 @@ const selectedId = ref<number | null>(null)
|
||||
|
||||
// Queries
|
||||
const foldersQuery = useQuery({
|
||||
queryKey: ['images', 'folders'],
|
||||
queryKey: computed(() => ['images', 'folders', currentBrandId.value]),
|
||||
enabled: computed(() => Boolean(currentBrandId.value)),
|
||||
queryFn: () => imagesApi.listFolders(),
|
||||
})
|
||||
|
||||
@@ -40,6 +44,7 @@ const imagesQuery = useQuery({
|
||||
'images',
|
||||
'list',
|
||||
'picker',
|
||||
currentBrandId.value,
|
||||
{
|
||||
folder_id: selectedFolderId.value,
|
||||
q: debouncedSearch.value,
|
||||
@@ -47,6 +52,7 @@ const imagesQuery = useQuery({
|
||||
page_size: pageSize.value,
|
||||
},
|
||||
]),
|
||||
enabled: computed(() => Boolean(currentBrandId.value)),
|
||||
queryFn: () =>
|
||||
imagesApi.list({
|
||||
folder_id: selectedFolderId.value ?? undefined,
|
||||
@@ -77,6 +83,12 @@ watch(searchKeyword, () => {
|
||||
}, 300)
|
||||
})
|
||||
|
||||
watch(currentBrandId, () => {
|
||||
selectedFolderId.value = null
|
||||
selectedId.value = null
|
||||
currentPage.value = 1
|
||||
})
|
||||
|
||||
function handleSelect(image: ImageAssetItem) {
|
||||
selectedId.value = image.id
|
||||
emit('select', image)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { computed, watch } from 'vue'
|
||||
import MarkdownPreview from '@/components/MarkdownPreview.vue'
|
||||
import { knowledgeApi } from '@/lib/api'
|
||||
import { formatDateTime } from '@/lib/display'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
@@ -16,10 +17,12 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const enabled = computed(() => props.open && Boolean(props.itemId))
|
||||
const companyStore = useCompanyStore()
|
||||
const currentBrandId = computed(() => companyStore.currentBrandId)
|
||||
const enabled = computed(() => props.open && Boolean(props.itemId) && Boolean(currentBrandId.value))
|
||||
|
||||
const detailQuery = useQuery({
|
||||
queryKey: computed(() => ['knowledge', 'detail', props.itemId]),
|
||||
queryKey: computed(() => ['knowledge', 'detail', currentBrandId.value, props.itemId]),
|
||||
enabled,
|
||||
queryFn: () => knowledgeApi.detail(props.itemId as number),
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/vue-query'
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { knowledgeApi } from '@/lib/api'
|
||||
import { useCompanyStore } from '@/stores/company'
|
||||
|
||||
interface TreeNode {
|
||||
title: string
|
||||
@@ -29,8 +30,12 @@ const emit = defineEmits<{
|
||||
'update:modelValue': [value: number[]]
|
||||
}>()
|
||||
|
||||
const companyStore = useCompanyStore()
|
||||
const currentBrandId = computed(() => companyStore.currentBrandId)
|
||||
|
||||
const groupsQuery = useQuery({
|
||||
queryKey: ['knowledge', 'groups', 'selector'],
|
||||
queryKey: computed(() => ['knowledge', 'groups', 'selector', currentBrandId.value]),
|
||||
enabled: computed(() => Boolean(currentBrandId.value)),
|
||||
queryFn: () => knowledgeApi.listGroups(),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user