-
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.
- Loading branch information
1 parent
6a56737
commit 9889197
Showing
37 changed files
with
742 additions
and
187 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
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
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 |
---|---|---|
|
@@ -3,3 +3,9 @@ | |
align-items: center; | ||
gap: 8px; | ||
} | ||
|
||
.articleSortSelectorRedesign { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
} |
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
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
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,85 @@ | ||
import { ArticleListViewType, ArticleSortField, ArticleType } from "@/entities/Article"; | ||
import { useAppDispatch } from "@/shared/lib/hooks/useAppDispatch/useAppDispatch"; | ||
import { useDebounce } from "@/shared/lib/hooks/useDebounce/useDebounce"; | ||
import { SortOrder } from "@/shared/types/sort"; | ||
import { TabItem } from "@/shared/ui/deprecated/Tabs"; | ||
import { useCallback } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { getArticlesPageOrder, getArticlesPageSearch, getArticlesPageSort, getArticlesPageType, getArticlesPageView } from "../../model/selectors/articlesPageSelectors"; | ||
import { fetchArticlesList } from "../../model/services/fetchArticlesList/fetchArticlesList"; | ||
import { articlePageActions } from "../../model/slice/articlePageSlice"; | ||
|
||
export function useArticleFilters() { | ||
const dispatch = useAppDispatch(); | ||
|
||
const sort = useSelector(getArticlesPageSort); | ||
const order = useSelector(getArticlesPageOrder); | ||
const search = useSelector(getArticlesPageSearch); | ||
const type = useSelector(getArticlesPageType); | ||
const view = useSelector(getArticlesPageView); | ||
|
||
|
||
const fetchData = useCallback(() => { | ||
void dispatch(fetchArticlesList({ replace: true })); | ||
}, [dispatch]); | ||
|
||
const debouncedFetchData = useDebounce(fetchData, 500); | ||
|
||
|
||
const handleViewClick = useCallback( | ||
(view: ArticleListViewType) => { | ||
dispatch(articlePageActions.setView(view)); | ||
}, | ||
[dispatch], | ||
); | ||
|
||
const handleSortChange = useCallback( | ||
(newSort: ArticleSortField) => { | ||
dispatch(articlePageActions.setSort(newSort)); | ||
dispatch(articlePageActions.setPage(1)); | ||
fetchData(); | ||
}, | ||
[dispatch, fetchData], | ||
); | ||
|
||
const handleOrderChange = useCallback( | ||
(newOrder: SortOrder) => { | ||
dispatch(articlePageActions.setOrder(newOrder)); | ||
dispatch(articlePageActions.setPage(1)); | ||
fetchData(); | ||
}, | ||
[dispatch, fetchData], | ||
); | ||
|
||
const handleSearchChange = useCallback( | ||
(newSearch: string) => { | ||
dispatch(articlePageActions.setSearch(newSearch)); | ||
dispatch(articlePageActions.setPage(1)); | ||
debouncedFetchData(); | ||
}, | ||
[dispatch, debouncedFetchData], | ||
); | ||
|
||
const handleTypeChange = useCallback( | ||
(tab: TabItem<ArticleType>) => { | ||
const { value: newType } = tab; | ||
dispatch(articlePageActions.setType(newType)); | ||
dispatch(articlePageActions.setPage(1)); | ||
fetchData(); | ||
}, | ||
[dispatch, fetchData], | ||
); | ||
|
||
return { | ||
sort, | ||
order, | ||
search, | ||
type, | ||
view, | ||
handleSortChange, | ||
handleOrderChange, | ||
handleSearchChange, | ||
handleTypeChange, | ||
handleViewClick, | ||
}; | ||
} |
8 changes: 3 additions & 5 deletions
8
src/pages/ArticlesPage/ui/ArticlesPage/ArticlesPage.module.scss
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,7 +1,5 @@ | ||
.articlesPage { | ||
opacity: 1; | ||
} | ||
|
||
.articleList { | ||
margin-top: 16px; | ||
.articleList { | ||
margin-top: 16px; | ||
} | ||
} |
Oops, something went wrong.