diff --git a/src/api/areas.ts b/src/api/areas.ts index 9252eb9..fbf9d75 100644 --- a/src/api/areas.ts +++ b/src/api/areas.ts @@ -37,3 +37,16 @@ export async function fetchAreaName(id: string): Promise { const resp = await http.get<{ id: string; name: string }>(`/areas/${id}`) return resp.data.name } + +/** + * Публичный эндпоинт (permitAll): id + parentId + name — для восстановления + * цепочки родителей при заходе по глубокой ссылке (?area=…). + */ +export async function fetchArea( + id: string, +): Promise<{ id: string; parentId: string | null; name: string }> { + const resp = await http.get<{ id: string; parentId: string | null; name: string }>( + `/areas/${id}`, + ) + return resp.data +} diff --git a/src/api/attractions.ts b/src/api/attractions.ts index eaf3da9..a8793cc 100644 --- a/src/api/attractions.ts +++ b/src/api/attractions.ts @@ -50,6 +50,32 @@ export async function uploadIcon(id: string, file: File): Promise { return resp.data } +/** Медиа ачивки: kind — сегмент эндпоинта background | audio | model. */ +async function uploadAchievementMedia( + id: string, + kind: 'background' | 'audio' | 'model', + file: File, +): Promise { + const form = new FormData() + form.append('file', file) + const resp = await http.post(`/admin/attractions/${id}/${kind}`, form, { + headers: { 'Content-Type': 'multipart/form-data' }, + }) + return resp.data +} + +export function uploadBackground(id: string, file: File): Promise { + return uploadAchievementMedia(id, 'background', file) +} + +export function uploadAudio(id: string, file: File): Promise { + return uploadAchievementMedia(id, 'audio', file) +} + +export function uploadModel(id: string, file: File): Promise { + return uploadAchievementMedia(id, 'model', file) +} + /** Публичная карточка (permitAll) — источник presigned iconUrl для превью. */ export async function fetchAttractionCard(id: string): Promise { const resp = await http.get(`/attractions/${id}`) diff --git a/src/api/types.ts b/src/api/types.ts index f00cc24..cca77c0 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -44,6 +44,10 @@ export interface Attraction { name: string /** Сырой ключ S3, не URL (для превью используется публичный эндпоинт). */ iconKey: string | null + /** Медиа ачивки — сырые ключи S3. */ + backgroundKey: string | null + audioKey: string | null + modelKey: string | null about: string | null latitude: number | null longitude: number | null @@ -145,6 +149,10 @@ export interface AttractionCard { id: string name: string iconUrl: string | null + /** Медиа ачивки — presigned GET URL (TTL 1 час). */ + backgroundUrl: string | null + audioUrl: string | null + modelUrl: string | null about: string | null latitude: number | null longitude: number | null diff --git a/src/pages/areas/AreaListPage.tsx b/src/pages/areas/AreaListPage.tsx index f1cd942..5d977b9 100644 --- a/src/pages/areas/AreaListPage.tsx +++ b/src/pages/areas/AreaListPage.tsx @@ -2,7 +2,8 @@ import { useState } from 'react' import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { Breadcrumb, Button, Empty, Form, Input, Modal, Space, Table, Typography } from 'antd' import type { ColumnsType } from 'antd/es/table' -import { createArea, fetchAreas, updateArea } from '@/api/areas' +import { useSearchParams } from 'react-router-dom' +import { createArea, fetchArea, fetchAreas, updateArea } from '@/api/areas' import { notifyApiError, notifySuccess } from '@/api/errors' import type { Area } from '@/api/types' import { AreaTreeSelect } from '@/components/AreaTreeSelect' @@ -28,8 +29,9 @@ const PAGE_SIZE = 20 export function AreaListPage() { const queryClient = useQueryClient() const isMobile = useIsMobile() - const [parentId, setParentId] = useState(null) - const [trail, setTrail] = useState([]) + const [searchParams, setSearchParams] = useSearchParams() + // Позиция синхронизирована с URL (?area=…): прямые ссылки и F5 не теряют место. + const [parentId, setParentId] = useState(searchParams.get('area')) const [page, setPage] = useState(0) const [createOpen, setCreateOpen] = useState(false) @@ -44,8 +46,29 @@ export function AreaListPage() { placeholderData: keepPreviousData, }) + // Цепочка родителей текущей зоны — восстановление по parentId вверх до корня + // (при обычной навигации имена уже в кэше, при заходе по ссылке — доходит запросами). + const ancestryQuery = useQuery({ + queryKey: ['area-ancestry', parentId], + enabled: parentId != null, + queryFn: async (): Promise => { + const chain: TrailItem[] = [] + let current: string | null = parentId + while (current != null) { + const area = await fetchArea(current) + chain.unshift({ id: area.id, name: area.name }) + current = area.parentId + } + return chain + }, + staleTime: 5 * 60 * 1000, + }) + const trail = ancestryQuery.data ?? [] + const invalidate = () => { void queryClient.invalidateQueries({ queryKey: ['admin-areas'] }) + // после переименования цепочка крошек могла устареть + void queryClient.invalidateQueries({ queryKey: ['area-ancestry'] }) } const createMutation = useMutation({ @@ -76,23 +99,15 @@ export function AreaListPage() { onError: (e) => notifyApiError(e, 'Не удалось обновить зону'), }) - const openArea = (area: Area) => { - setTrail((prev) => [...prev, { id: area.id, name: area.name }]) - setParentId(area.id) + const setParent = (value: string | null) => { + setParentId(value) setPage(0) + setSearchParams(value ? { area: value } : {}, { replace: true }) } const navigateTo = (index: number) => { // -1 — корень, иначе обрезаем путь до index включительно. - if (index < 0) { - setTrail([]) - setParentId(null) - } else { - const item = trail[index] - setTrail(trail.slice(0, index + 1)) - setParentId(item.id) - } - setPage(0) + setParent(index < 0 ? null : trail[index].id) } const columns: ColumnsType = [ @@ -101,7 +116,7 @@ export function AreaListPage() { dataIndex: 'name', key: 'name', render: (_, area) => ( - ), @@ -112,7 +127,7 @@ export function AreaListPage() { width: 200, render: (_, area) => ( - + + + JPG / PNG / WebP / SVG, до 50 МБ. Перезаписывает текущий. - + + + + + + {cardQuery.data?.audioUrl ? ( + + + + {attraction.modelKey ? ( + + {modelFormat(attraction.modelKey)} + + ) : ( + нет + )} + + + + + + GLB / glTF / USDZ / OBJ, до 50 МБ; формат — по расширению файла. В приложении + модель отдаётся только «забравшим» ачивку. + + + @@ -282,3 +400,38 @@ export function AttractionDetailPage() { ) } + +function MediaBox({ children }: { children: ReactNode }) { + return ( +
+ {children} +
+ ) +} + +function S3KeyText({ value }: { value: string | null }) { + return ( + + Ключ в S3:{' '} + + {value ?? '—'} + + + ) +} + +/** Формат 3D-модели из расширения ключа: attractions/{id}/model/{fileId}.glb -> GLB. */ +function modelFormat(modelKey: string): string { + return (modelKey.split('.').pop() ?? '').toUpperCase() +}