From 2b7a825bc51ec80cf3b78580fadcb07fc23c32f7 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 13 Jul 2024 20:22:32 +0300 Subject: [PATCH] sortfn-type --- src/components/Article/CommentsTree.tsx | 8 +++----- src/context/authors.tsx | 4 +--- src/routes/(main).tsx | 2 +- src/types/common.d.ts | 2 ++ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index ef04a3a9..13fffae5 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -1,19 +1,17 @@ import { clsx } from 'clsx' import { For, Show, createMemo, createSignal, lazy, onMount } from 'solid-js' +import { useFeed } from '~/context/feed' import { useLocalize } from '~/context/localize' import { useReactions } from '~/context/reactions' import { useSession } from '~/context/session' import { Author, Reaction, ReactionKind, ReactionSort } from '~/graphql/schema/core.gen' import { byCreated, byStat } from '~/lib/sort' +import { SortFunction } from '~/types/common' import { Button } from '../_shared/Button' import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated' - -import { Comment } from './Comment' - -import { SortFunction } from '~/context/authors' -import { useFeed } from '~/context/feed' import styles from './Article.module.scss' +import { Comment } from './Comment' const SimplifiedEditor = lazy(() => import('../Editor/SimplifiedEditor')) diff --git a/src/context/authors.tsx b/src/context/authors.tsx index 4f3d977c..8287b443 100644 --- a/src/context/authors.tsx +++ b/src/context/authors.tsx @@ -18,13 +18,11 @@ import { Topic } from '~/graphql/schema/core.gen' import { byStat } from '~/lib/sort' +import { FilterFunction, SortFunction } from '~/types/common' import { useFeed } from './feed' const TOP_AUTHORS_COUNT = 5 -type FilterFunction = (a: Author) => boolean -export type SortFunction = (a: Author, b: Author) => number - // Универсальная функция фильтрации и сортировки function filterAndSort( items: Author[], diff --git a/src/routes/(main).tsx b/src/routes/(main).tsx index acfb46d2..9a921c4c 100644 --- a/src/routes/(main).tsx +++ b/src/routes/(main).tsx @@ -4,6 +4,7 @@ import { useTopics } from '~/context/topics' import { loadShouts, loadTopics } from '~/graphql/api/public' import { LoadShoutsOptions, Shout } from '~/graphql/schema/core.gen' import { byStat } from '~/lib/sort' +import { SortFunction } from '~/types/common' import { restoreScrollPosition, saveScrollPosition } from '~/utils/scroll' import { HomeView, HomeViewProps } from '../components/Views/Home' import { Loading } from '../components/_shared/Loading' @@ -11,7 +12,6 @@ import { PageLayout } from '../components/_shared/PageLayout' import { useLocalize } from '../context/localize' export const SHOUTS_PER_PAGE = 20 -type SortFunction = (a: Shout, b: Shout) => number const fetchAllTopics = async () => { const allTopicsLoader = loadTopics() diff --git a/src/types/common.d.ts b/src/types/common.d.ts index 8397ab97..8e0f882b 100644 --- a/src/types/common.d.ts +++ b/src/types/common.d.ts @@ -6,3 +6,5 @@ export type RootSearchParams = { export type LayoutType = 'article' | 'audio' | 'video' | 'image' | 'literature'; export type FollowsFilter = 'all' | 'authors' | 'topics' | 'communities'; +export type SortFunction = (a: T, b: T) => number +export type FilterFunction = (a: T) => boolean