From 9a412b0c6d68a04c59d5faabb347313be82659a6 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sat, 7 Feb 2026 05:06:13 +0700 Subject: [PATCH 01/11] ai type safe rewrite --- frontend/src/components/AddButton/index.tsx | 3 +- frontend/src/components/Gallery/index.tsx | 4 +- frontend/src/components/IdeaModal/index.tsx | 3 +- frontend/src/components/IndexBest/index.tsx | 2 +- frontend/src/components/IndexPage/index.tsx | 14 ++-- frontend/src/components/Map/index.tsx | 6 +- frontend/src/components/NewsCard/index.tsx | 2 +- frontend/src/components/NewsPage/index.tsx | 2 +- .../components/SubmissionFeed/CommentForm.tsx | 3 +- .../src/components/SubmissionFeed/Item.tsx | 2 +- .../src/components/SubmissionFeed/index.tsx | 36 ++-------- .../components/SurveyModal/CheckboxList.tsx | 2 +- .../SurveyModal/CheckboxWithOther.tsx | 6 +- frontend/src/components/SurveyModal/index.tsx | 69 ++++++++++--------- frontend/src/contexts/clientId.tsx | 10 +-- frontend/src/contexts/form.tsx | 10 ++- frontend/src/contexts/navbar.tsx | 7 +- frontend/src/pages/_app.tsx | 24 ++++--- frontend/src/pages/index.tsx | 2 +- frontend/src/pages/map.tsx | 14 ++-- frontend/src/types/index.ts | 46 +++++++++++++ frontend/src/types/submission.ts | 27 ++++++++ frontend/temp/news/[id].tsx | 6 +- frontend/tsconfig.json | 2 +- 24 files changed, 180 insertions(+), 122 deletions(-) create mode 100644 frontend/src/types/index.ts create mode 100644 frontend/src/types/submission.ts diff --git a/frontend/src/components/AddButton/index.tsx b/frontend/src/components/AddButton/index.tsx index 762413a..4453fd6 100644 --- a/frontend/src/components/AddButton/index.tsx +++ b/frontend/src/components/AddButton/index.tsx @@ -2,6 +2,7 @@ import { FormContext } from '@/contexts/form'; import { Popover, Button, Center, Box } from '@mantine/core'; import { useModals } from '@mantine/modals'; import { useCallback, useContext } from 'react'; +import { FormData } from '@/types'; export const AddButton: React.FC<{ style?: React.CSSProperties }> = ({ style = { position: 'absolute', @@ -13,7 +14,7 @@ export const AddButton: React.FC<{ style?: React.CSSProperties }> = ({ style = { const modals = useModals() const { data, setData } = useContext(FormContext) const { addMode, setAddMode } = useContext(FormContext) - const onClick = useCallback((data) => { + const onClick = useCallback((data: FormData) => { if (Object.keys(data).length == 0) { setData({}) } diff --git a/frontend/src/components/Gallery/index.tsx b/frontend/src/components/Gallery/index.tsx index 0ab7440..df28e99 100644 --- a/frontend/src/components/Gallery/index.tsx +++ b/frontend/src/components/Gallery/index.tsx @@ -25,7 +25,7 @@ const PrevButton = () => { ) } -export const Gallery = ({ galleryImages }) => { +export const Gallery = ({ galleryImages }: { galleryImages: any[] }) => { const [imageOpened, { toggle: close, open }] = useDisclosure() const [image, setImage] = useState(0) const isMobile = useMedia('(max-width: 576px)', false) @@ -44,7 +44,7 @@ export const Gallery = ({ galleryImages }) => { open() }} > - {galleryImages.map((x, i) => ( + {galleryImages.map((x: any, i: number) => ( diff --git a/frontend/src/components/IdeaModal/index.tsx b/frontend/src/components/IdeaModal/index.tsx index 8d8c661..6c44edf 100644 --- a/frontend/src/components/IdeaModal/index.tsx +++ b/frontend/src/components/IdeaModal/index.tsx @@ -8,9 +8,10 @@ import { z } from 'zod' import { zodResolver } from "@hookform/resolvers/zod" import { useSWRConfig } from 'swr' import buttonStyles from '@/styles/button.module.css' +import { IdeaModalDefaultValues } from '@/types' export type IdeaModalProps = { - defaultValues?: { [key: string]: any } + defaultValues?: IdeaModalDefaultValues } const states = { diff --git a/frontend/src/components/IndexBest/index.tsx b/frontend/src/components/IndexBest/index.tsx index a83d0bf..44d3e88 100644 --- a/frontend/src/components/IndexBest/index.tsx +++ b/frontend/src/components/IndexBest/index.tsx @@ -58,7 +58,7 @@ export const IndexBest: React.FC<{ isMobile: boolean }> = ({ isMobile }) => { className={s.masonry} columnClassName={s.masonryCol} > - {data.map(x => ( + {data.map((x: any) => ( <Title order={2} - ta={isMobile ? 'center' : null} + ta={isMobile ? 'center' : undefined} > ГРАФИК ПРОЕКТА @@ -246,7 +246,7 @@ export function IndexPage() { // pl={isMobile ? 8 : 19} style={{ width: '100%', - aspectRatio: !isMobile && '1240 / 762', + aspectRatio: !isMobile ? '1240 / 762' : undefined, backgroundSize: isMobile ? 'auto' : 'contain', }} > @@ -266,7 +266,7 @@ export function IndexPage() { order={2} c={'primary'} mb={24} - ta={isTablet ? 'center' : null} + ta={isTablet ? 'center' : undefined} w={'100%'} style={{ fontSize: isMobile ? undefined : '42px', @@ -369,7 +369,7 @@ export function IndexPage() { zIndex: 0, overflow: 'visible', }} - pb={!isTablet && 100} + pb={!isTablet ? 100 : undefined} > {/* {!isTablet && (
ЧТО ВЫ ХОТИТЕ <br /> ИЗМЕНИТЬ? diff --git a/frontend/src/components/Map/index.tsx b/frontend/src/components/Map/index.tsx index 67b78d7..03cce84 100644 --- a/frontend/src/components/Map/index.tsx +++ b/frontend/src/components/Map/index.tsx @@ -32,7 +32,7 @@ export const Map: React.FC = ({ initialCoords }) => { const modals = useModals() const { data: formData, setData, addMode, setAddMode } = useContext(FormContext) - const onClick = useCallback((event) => { + const onClick = useCallback((event: any) => { if (!addMode) return const { lngLat } = event @@ -66,7 +66,7 @@ export const Map: React.FC = ({ initialCoords }) => { const isPreview = Boolean(router.query?.preview) == true const features = (data?.items ?? []) - .filter(x => x?.feature && JSON.stringify(x?.feature) !== '{}') + .filter((x: any) => x?.feature && JSON.stringify(x?.feature) !== '{}') return ( = ({ initialCoords }) => { /> {(!isLoading && !error && data) && (!addMode) && features - .map((x, i) => ( + .map((x: any, i: number) => ( { +export const NewsCard = ({ x }: { x: any }) => { return ( { +export const NewsPage = ({ data }: { data: any }) => { return ( diff --git a/frontend/src/components/SubmissionFeed/CommentForm.tsx b/frontend/src/components/SubmissionFeed/CommentForm.tsx index bd26397..eeeafb5 100644 --- a/frontend/src/components/SubmissionFeed/CommentForm.tsx +++ b/frontend/src/components/SubmissionFeed/CommentForm.tsx @@ -5,10 +5,11 @@ import { Controller, useForm } from 'react-hook-form' import { KeyedMutator } from 'swr' import { z } from 'zod' import s from './index.module.css' +import { Submission } from '@/types/submission' type CommentFormProps = { id: string - mutate: KeyedMutator + mutate: KeyedMutator } const states = { diff --git a/frontend/src/components/SubmissionFeed/Item.tsx b/frontend/src/components/SubmissionFeed/Item.tsx index ca8f295..35c5c27 100644 --- a/frontend/src/components/SubmissionFeed/Item.tsx +++ b/frontend/src/components/SubmissionFeed/Item.tsx @@ -57,7 +57,7 @@ export const Item: React.FC = ({ data }) => { bg={'white'} onClick={() => { setDrawer(false) - map.flyTo({ + map?.flyTo({ center: data.feature.geometry.coordinates, zoom: 15, }) diff --git a/frontend/src/components/SubmissionFeed/index.tsx b/frontend/src/components/SubmissionFeed/index.tsx index c22a372..3165b30 100644 --- a/frontend/src/components/SubmissionFeed/index.tsx +++ b/frontend/src/components/SubmissionFeed/index.tsx @@ -9,37 +9,9 @@ import { useRouter } from 'next/router' import { useEffectOnce } from 'react-use' import { AddButton } from '../AddButton' import { useMediaQuery } from '@mantine/hooks' +import type { Feature, Submission, SubmissionResponse } from '@/types/submission' -export type Feature = { - type: 'Feature', - properties: {}, - geometry: { - type: 'Point', - coordinates: [ - number, - number, - ] - } -} - -export type Submission = { - id: string - content: string - feature: Feature - collectionId?: string - collectionName?: string - created?: string - isBanned?: boolean - updated?: string -} - -export type SubmissionResponse = { - page: number - perPage: number - totalPages: number - totalItems: number - items: Submission[] -} +export type { Feature, Submission, SubmissionResponse } export const SubmissionFeed: React.FC = () => { const router = useRouter() @@ -57,7 +29,7 @@ export const SubmissionFeed: React.FC = () => { } ).then(async res => await res.json()), ) - const dataFlat = (isLoading || error) + const dataFlat = (isLoading || error || !data) ? [] : data .flatMap(x => x.items) @@ -165,7 +137,7 @@ export const SubmissionFeed: React.FC = () => { data={x} /> ))} - {!isLoading && data[0]?.totalItems != dataFlat.length && ( + {!isLoading && data && data[0]?.totalItems != dataFlat.length && (