diff --git a/src/components/Views/AllAuthors.tsx b/src/components/Views/AllAuthors.tsx index 7ef9f0ac..d624ac8b 100644 --- a/src/components/Views/AllAuthors.tsx +++ b/src/components/Views/AllAuthors.tsx @@ -11,6 +11,7 @@ import { useSession } from '../../context/session' import { locale } from '../../stores/ui' import { translit } from '../../utils/ru2en' import { SearchField } from '../_shared/SearchField' +import { scrollHandler } from '../../utils/scroll' type AllAuthorsPageSearchParams = { by: '' | 'name' | 'shouts' | 'rating' @@ -21,7 +22,7 @@ type Props = { } const PAGE_SIZE = 20 -const ALPHABET = Array.from('@АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ') +const ALPHABET = [...'@АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'] export const AllAuthorsView = (props: Props) => { const { sortedAuthors } = useAuthorsStore({ authors: props.authors }) @@ -77,16 +78,6 @@ export const AllAuthorsView = (props: Props) => { ) - const scrollHandler = (elemId) => { - const anchor = document.querySelector('#' + elemId) - // console.debug(elemId) - if (anchor) { - window.scrollTo({ - top: anchor.getBoundingClientRect().top - 100, - behavior: 'smooth' - }) - } - } const [searchResults, setSearchResults] = createSignal([]) // eslint-disable-next-line sonarjs/cognitive-complexity const searchAuthors = (value) => { diff --git a/src/components/Views/AllTopics.tsx b/src/components/Views/AllTopics.tsx index 7db22a7c..45d1f00b 100644 --- a/src/components/Views/AllTopics.tsx +++ b/src/components/Views/AllTopics.tsx @@ -10,6 +10,7 @@ import { locale } from '../../stores/ui' import { translit } from '../../utils/ru2en' import styles from '../../styles/AllTopics.module.scss' import { SearchField } from '../_shared/SearchField' +import { scrollHandler } from '../../utils/scroll' type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' @@ -20,7 +21,7 @@ type AllTopicsViewProps = { } const PAGE_SIZE = 20 -const ALPHABET = Array.from('#АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ') +const ALPHABET = [...'#АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'] export const AllTopicsView = (props: AllTopicsViewProps) => { const { searchParams, changeSearchParam } = useRouter() @@ -114,16 +115,6 @@ export const AllTopicsView = (props: AllTopicsViewProps) => { ) - const scrollHandler = (elemId) => { - const anchor = document.querySelector('#' + elemId) - // console.debug(elemId) - if (anchor) { - window.scrollTo({ - top: anchor.getBoundingClientRect().top - 100, - behavior: 'smooth' - }) - } - } return (
diff --git a/src/graphql/client.ts b/src/graphql/client.ts index 97a4eb57..3cf12b35 100644 --- a/src/graphql/client.ts +++ b/src/graphql/client.ts @@ -13,8 +13,8 @@ export const initClient = (options) => { console.info('[graphql] devmode detected') return localClient(options) } else return createClient(options) - } catch (e) { - console.error(e) + } catch (error) { + console.error(error) return localClient(options) } } diff --git a/src/utils/scroll.ts b/src/utils/scroll.ts index e3f2d240..42ef1723 100644 --- a/src/utils/scroll.ts +++ b/src/utils/scroll.ts @@ -14,3 +14,14 @@ export const restoreScrollPosition = () => { left: scrollPosition.left }) } + +export const scrollHandler = (elemId) => { + const anchor = document.querySelector('#' + elemId) + // console.debug(elemId) + if (anchor) { + window.scrollTo({ + top: anchor.getBoundingClientRect().top - 100, + behavior: 'smooth' + }) + } +}