This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: фильтрация на странице поиска (#64)
Co-authored-by: Ruslan Kutliakhmetov <[email protected]>
- Loading branch information
1 parent
8f9896f
commit fba891c
Showing
24 changed files
with
361 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ui'; | ||
export * from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { create } from 'zustand'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
import { SelectOptions } from '~/shared/types'; | ||
|
||
export interface FilterType { | ||
specs: string[]; | ||
skills: SelectOptions[]; | ||
date: string; | ||
} | ||
|
||
export const defaultFilter: FilterType = { | ||
specs: [], | ||
skills: [], | ||
date: '', | ||
}; | ||
|
||
interface FilterStore { | ||
filter: FilterType; | ||
updateFilter: (filter: Partial<FilterType>) => void; | ||
removeFilter: () => void; | ||
} | ||
|
||
export const useFilterStore = create( | ||
persist<FilterStore>( | ||
(set) => ({ | ||
filter: defaultFilter, | ||
updateFilter: (value: Partial<FilterType>) => { | ||
set((state) => ({ | ||
filter: { ...state.filter, ...value }, | ||
})); | ||
}, | ||
removeFilter: () => { | ||
set(() => ({ filter: defaultFilter })); | ||
}, | ||
}), | ||
{ | ||
name: 'filter', | ||
}, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './filter'; | ||
export * from './search'; | ||
export * from './add'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { SearchInput } from '~/shared/ui/SearchInput'; | ||
|
||
export const SearchProject = () => { | ||
const handleSumbit = (value: string) => { | ||
console.log(value); | ||
}; | ||
return <SearchInput onChange={handleSumbit} placeholder="Найти проект" />; | ||
interface SearchProjectProps { | ||
onChange: (value: string) => void; | ||
} | ||
|
||
export const SearchProject = ({ onChange }: SearchProjectProps) => { | ||
return <SearchInput onChange={onChange} placeholder="Найти проект" />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import { | ||
Flex, | ||
SimpleGrid, | ||
Heading, | ||
Container, | ||
Box, | ||
Skeleton, | ||
Image, | ||
Text, | ||
Button, | ||
} from '@chakra-ui/react'; | ||
import { QueryFunctionContext, QueryKey, useInfiniteQuery } from '@tanstack/react-query'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { Link, generatePath, useNavigate } from 'react-router-dom'; | ||
|
||
import { ProjectCard } from '~/widgets/project-card'; | ||
|
||
import { AddProject } from '~/features/project'; | ||
|
||
import { AvatarsGroup } from '~/entities/project'; | ||
|
||
import { useApi } from '~/shared/hooks'; | ||
import { PATHS } from '~/shared/lib/router'; | ||
import { STag } from '~/shared/ui/STag'; | ||
|
||
import NotAuth from './NotAuth.svg'; | ||
|
||
interface ProjectPageProps { | ||
userId: string; | ||
} | ||
|
||
export const ProjectsBase = ({ userId }: ProjectPageProps) => { | ||
const targetRef = useRef<HTMLDivElement>(null); | ||
const { projectsApi } = useApi(); | ||
const [isEmptyData, setEmptyData] = useState<boolean>(false); | ||
const navigate = useNavigate(); | ||
const dummyAvatars = [ | ||
{ firstName: 'Alex', lastName: 'Gordon', img: 'https://bit.ly/ryan-florence' }, | ||
{ firstName: 'Игорь', lastName: 'Крутой', img: 'https://bit.ly/sage-adebayo' }, | ||
{ firstName: 'Джек', lastName: 'Воробей', img: 'https://bit.ly/kent-c-dodds' }, | ||
{ firstName: 'Кларк', lastName: 'Кент', img: 'https://bit.ly/prosper-baba' }, | ||
{ firstName: 'Джеймс', lastName: 'Бонд', img: 'https://bit.ly/code-beast' }, | ||
{ firstName: 'Бернд', lastName: 'Шнайдер', img: 'https://bit.ly/dan-abramov' }, | ||
]; | ||
|
||
const { data, isLoading, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({ | ||
queryKey: ['getAllProjects', userId], | ||
queryFn: ({ pageParam = 1 }: QueryFunctionContext<QueryKey, number>) => | ||
projectsApi.getAllProjects({ page: pageParam, owner_id: userId }), | ||
// getNextPageParam: (lastPage) => lastPage.page + 1, | ||
onSuccess: (response) => { | ||
setEmptyData(!response.pages[0].data.length); | ||
}, | ||
staleTime: 5000, | ||
}); | ||
|
||
useEffect(() => { | ||
const options = { | ||
root: null, | ||
rootMargin: '0px', | ||
threshold: 1.0, | ||
}; | ||
|
||
const observer = new IntersectionObserver((entries: IntersectionObserverEntry[]) => { | ||
const [entry] = entries; | ||
if (entry.isIntersecting) { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
fetchNextPage(); | ||
} | ||
}, options); | ||
|
||
if (targetRef.current) observer.observe(targetRef.current); | ||
|
||
return () => { | ||
if (targetRef.current) observer.unobserve(targetRef.current); | ||
}; | ||
}, [data]); | ||
|
||
return ( | ||
<Container maxW="md" mb={4}> | ||
<Flex justifyContent="space-between" alignItems="center" my={4} h={42}> | ||
<Heading variant="h1" as="h1"> | ||
Проекты | ||
</Heading> | ||
<Flex gap={4} alignItems="baseline"> | ||
<AddProject /> | ||
</Flex> | ||
</Flex> | ||
|
||
{isLoading ? ( | ||
<> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
</> | ||
) : ( | ||
<SimpleGrid gap={4}> | ||
{isEmptyData ? ( | ||
<Flex | ||
bg="white" | ||
my={6} | ||
borderRadius="2xl" | ||
p={5} | ||
direction="column" | ||
alignItems="center" | ||
gap={5} | ||
> | ||
<Image src={NotAuth} /> | ||
<Text fontSize="md" fontWeight="medium" mt={1}> | ||
Нет проектов | ||
</Text> | ||
<Text color="gray.700" textAlign="center"> | ||
Здесь будут отображаться все ваши проекты в качестве участника и | ||
организатора | ||
</Text> | ||
<Button | ||
type="button" | ||
onClick={() => { | ||
navigate(PATHS.addProject); | ||
}} | ||
fontSize="sm" | ||
fontWeight="600" | ||
w="full" | ||
> | ||
Создать свой проект | ||
</Button> | ||
</Flex> | ||
) : ( | ||
<> | ||
{data?.pages.map((group, i) => ( | ||
<React.Fragment key={i}> | ||
{group.data.map((project) => { | ||
return ( | ||
<Link | ||
key={project.id} | ||
to={generatePath(PATHS.project, { id: project.id })} | ||
> | ||
<ProjectCard | ||
status={project.status} | ||
title={project.name} | ||
date={project.deadline} | ||
description={project.description} | ||
> | ||
<Flex justifyContent="space-between" alignItems="center"> | ||
<STag mainTags={['Организатор']} /> | ||
<AvatarsGroup avatars={dummyAvatars} /> | ||
</Flex> | ||
</ProjectCard> | ||
</Link> | ||
); | ||
})} | ||
</React.Fragment> | ||
))} | ||
</> | ||
)} | ||
|
||
{isFetchingNextPage && ( | ||
<> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
<Skeleton height="200px" borderRadius="2xl" mb={3} /> | ||
</> | ||
)} | ||
<Box ref={targetRef}></Box> | ||
</SimpleGrid> | ||
)} | ||
</Container> | ||
); | ||
}; |
Oops, something went wrong.