This commit is contained in:
cracklesparkle
2025-01-30 12:36:39 +09:00
parent e6b3dc05d3
commit 0788a401ca
43 changed files with 3710 additions and 1724 deletions

View File

@ -2,14 +2,17 @@ import { useState } from 'react'
import useSWR from 'swr'
import { fetcher } from '../../http/axiosInstance'
import { BASE_URL } from '../../constants'
import { Accordion, NavLink, Text } from '@mantine/core';
import { setCurrentObjectId, useObjectsStore } from '../../store/objects';
import { NavLink, Stack, Text } from '@mantine/core';
import { IconChevronDown } from '@tabler/icons-react';
import { setSelectedObjectType } from '../../store/map';
import { setCurrentObjectId, useObjectsStore } from '../../store/objects';
const ObjectTree = () => {
const { selectedDistrict, selectedYear } = useObjectsStore()
const ObjectTree = ({
map_id
}: {
map_id: string,
}) => {
const { selectedYear, selectedDistrict } = useObjectsStore().id[map_id]
const [existingCount, setExistingCount] = useState(0)
const [planningCount, setPlanningCount] = useState(0)
@ -49,10 +52,10 @@ const ObjectTree = () => {
if (selectedDistrict) {
return (
<Accordion multiple chevronPosition='left'>
<TypeTree label='Существующие' value={'existing'} count={existingCount} objectList={existingObjectsList} planning={0} />
<TypeTree label='Планируемые' value={'planning'} count={planningCount} objectList={planningObjectsList} planning={1} />
</Accordion>
<Stack gap={0}>
<TypeTree map_id={map_id} label='Существующие' value={'existing'} count={existingCount} objectList={existingObjectsList} planning={0} />
<TypeTree map_id={map_id} label='Планируемые' value={'planning'} count={planningCount} objectList={planningObjectsList} planning={1} />
</Stack>
)
} else {
return (
@ -69,19 +72,21 @@ interface TypeTreeProps {
count: number;
objectList: unknown;
planning: number;
map_id: string;
}
const TypeTree = ({
label,
objectList,
count,
planning
planning,
map_id
}: TypeTreeProps) => {
return (
<NavLink p={0} label={`${label} ${count ? `(${count})` : ''}`}>
{Array.isArray(objectList) && objectList.map(list => (
<ObjectList key={list.id} label={list.name} id={list.id} planning={planning} count={list.count} />
<ObjectList map_id={map_id} key={list.id} label={list.name} id={list.id} planning={planning} count={list.count} />
))}
</NavLink>
)
@ -92,20 +97,22 @@ interface IObjectList {
id: number;
planning: number;
count: number;
map_id: string;
}
const ObjectList = ({
label,
id,
planning,
count
count,
map_id
}: IObjectList) => {
const { selectedDistrict, selectedYear } = useObjectsStore()
const { selectedDistrict, selectedYear } = useObjectsStore().id[map_id]
const { data } = useSWR(
selectedDistrict && selectedYear ? `/general/objects/list?type=${id}&city_id=${selectedDistrict}&year=${selectedYear}&planning=${planning}` : null,
(url) => fetcher(url, BASE_URL.ems),
{
{
revalidateOnFocus: false,
revalidateIfStale: false
}
@ -113,10 +120,10 @@ const ObjectList = ({
return (
<NavLink onClick={() => {
setSelectedObjectType(id)
setSelectedObjectType(map_id, id)
}} rightSection={<IconChevronDown size={14} />} p={0} label={`${label} ${count ? `(${count})` : ''}`}>
{Array.isArray(data) && data.map((type) => (
<NavLink key={type.object_id} label={type.caption ? type.caption : 'Без названия'} p={0} onClick={() => setCurrentObjectId(type.object_id)} />
<NavLink key={type.object_id} label={type.caption ? type.caption : 'Без названия'} p={0} onClick={() => setCurrentObjectId(map_id, type.object_id)} />
))}
</NavLink>
)