2024-06-24 17:50:27 +00:00
|
|
|
import { Meta } from '@solidjs/meta'
|
2024-07-03 07:02:46 +00:00
|
|
|
import { A, useSearchParams } from '@solidjs/router'
|
2024-06-28 15:05:45 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-07-05 22:24:22 +00:00
|
|
|
import { For, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { Loading } from '~/components/_shared/Loading'
|
|
|
|
import { SearchField } from '~/components/_shared/SearchField'
|
|
|
|
import { useLocalize } from '~/context/localize'
|
2024-06-28 15:05:45 +00:00
|
|
|
import { useTopics } from '~/context/topics'
|
2024-07-04 07:51:15 +00:00
|
|
|
import type { Topic } from '~/graphql/schema/core.gen'
|
2024-07-05 14:08:12 +00:00
|
|
|
import enKeywords from '~/intl/locales/en/keywords.json'
|
|
|
|
import ruKeywords from '~/intl/locales/ru/keywords.json'
|
|
|
|
import { dummyFilter } from '~/lib/dummyFilter'
|
|
|
|
import { getImageUrl } from '~/lib/getImageUrl'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { capitalize } from '~/utils/capitalize'
|
|
|
|
import { scrollHandler } from '~/utils/scroll'
|
2024-06-24 17:50:27 +00:00
|
|
|
import { TopicBadge } from '../../Topic/TopicBadge'
|
2023-10-18 10:56:41 +00:00
|
|
|
import styles from './AllTopics.module.scss'
|
|
|
|
|
2023-12-13 10:39:31 +00:00
|
|
|
type Props = {
|
2022-09-22 09:37:49 +00:00
|
|
|
topics: Topic[]
|
|
|
|
}
|
|
|
|
|
2024-06-28 15:05:45 +00:00
|
|
|
export const TOPICS_PER_PAGE = 50
|
2024-06-24 17:50:27 +00:00
|
|
|
export const ABC = {
|
|
|
|
ru: 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#',
|
2024-06-26 08:22:05 +00:00
|
|
|
en: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ#'
|
2024-06-24 17:50:27 +00:00
|
|
|
}
|
2022-11-13 19:35:57 +00:00
|
|
|
|
2024-02-08 09:11:52 +00:00
|
|
|
export const AllTopics = (props: Props) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t, lang } = useLocalize()
|
2024-06-24 17:50:27 +00:00
|
|
|
const alphabet = createMemo(() => ABC[lang()])
|
2024-06-28 15:05:45 +00:00
|
|
|
const { setTopicsSort, sortedTopics } = useTopics()
|
|
|
|
const topics = createMemo(() => sortedTopics() || props.topics)
|
2024-07-05 22:24:22 +00:00
|
|
|
const [searchParams, changeSearchParams] = useSearchParams<{ by?: string }>()
|
2024-07-05 22:24:56 +00:00
|
|
|
createEffect(on(() => searchParams?.by || 'shouts', setTopicsSort, { defer: true }))
|
|
|
|
onMount(() => setTimeout(() => !searchParams?.by && changeSearchParams({ by: 'shouts' }), 1))
|
2024-07-05 19:40:54 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
// sorted derivative
|
2022-10-05 15:56:59 +00:00
|
|
|
const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => {
|
2024-06-28 15:05:45 +00:00
|
|
|
return topics().reduce(
|
2023-09-29 12:48:58 +00:00
|
|
|
(acc, topic) => {
|
2024-06-24 17:50:27 +00:00
|
|
|
let letter = lang() === 'en' ? topic.slug[0].toUpperCase() : (topic?.title?.[0] || '').toUpperCase()
|
2023-09-29 12:48:58 +00:00
|
|
|
if (/[^ËА-яё]/.test(letter) && lang() === 'ru') letter = '#'
|
2023-12-08 11:49:50 +00:00
|
|
|
if (/[^A-z]/.test(letter) && lang() === 'en') letter = '#'
|
2023-09-29 12:48:58 +00:00
|
|
|
if (!acc[letter]) acc[letter] = []
|
|
|
|
acc[letter].push(topic)
|
|
|
|
return acc
|
|
|
|
},
|
2024-06-26 08:22:05 +00:00
|
|
|
{} as { [letter: string]: Topic[] }
|
2023-09-29 12:48:58 +00:00
|
|
|
)
|
2022-10-05 15:56:59 +00:00
|
|
|
})
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
// helper memo
|
2022-10-05 15:56:59 +00:00
|
|
|
const sortedKeys = createMemo<string[]>(() => {
|
|
|
|
const keys = Object.keys(byLetter())
|
2024-06-24 17:50:27 +00:00
|
|
|
if (keys) {
|
|
|
|
keys.sort()
|
|
|
|
const firstKey: string = keys.shift() || ''
|
|
|
|
keys.push(firstKey)
|
|
|
|
}
|
2022-10-05 15:56:59 +00:00
|
|
|
return keys
|
|
|
|
})
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
// limit/offset based pagination aka 'show more' logic
|
|
|
|
const [limit, setLimit] = createSignal(TOPICS_PER_PAGE)
|
|
|
|
const showMore = () => setLimit((oldLimit) => oldLimit + TOPICS_PER_PAGE)
|
|
|
|
|
|
|
|
// filter
|
2022-12-01 18:45:35 +00:00
|
|
|
const [searchQuery, setSearchQuery] = createSignal('')
|
2024-06-28 15:05:45 +00:00
|
|
|
const [filteredResults, setFilteredResults] = createSignal<Topic[]>([])
|
2024-06-28 15:26:00 +00:00
|
|
|
createEffect(() =>
|
|
|
|
setFilteredResults((_prev: Topic[]) => dummyFilter(topics(), searchQuery(), lang()) as Topic[])
|
|
|
|
)
|
2022-11-18 02:45:44 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
// subcomponent
|
2022-11-17 20:08:12 +00:00
|
|
|
const AllTopicsHead = () => (
|
2022-11-20 21:23:12 +00:00
|
|
|
<div class="row">
|
2024-05-03 08:49:05 +00:00
|
|
|
<div class="col-lg-18 col-xl-15">
|
2022-11-20 21:23:12 +00:00
|
|
|
<h1>{t('Topics')}</h1>
|
|
|
|
<p>{t('Subscribe what you like to tune your personal feed')}</p>
|
|
|
|
|
2023-05-22 22:01:04 +00:00
|
|
|
<ul class="view-switcher">
|
2024-06-24 17:50:27 +00:00
|
|
|
<li classList={{ 'view-switcher__item--selected': searchParams?.by === 'shouts' }}>
|
2024-07-03 21:25:03 +00:00
|
|
|
<A href="/topic?by=shouts">{t('By shouts')}</A>
|
2022-11-20 21:23:12 +00:00
|
|
|
</li>
|
2024-06-24 17:50:27 +00:00
|
|
|
<li classList={{ 'view-switcher__item--selected': searchParams?.by === 'authors' }}>
|
2024-07-03 21:25:03 +00:00
|
|
|
<A href="/topic?by=authors">{t('By authors')}</A>
|
2022-11-20 21:23:12 +00:00
|
|
|
</li>
|
2024-06-24 17:50:27 +00:00
|
|
|
<li classList={{ 'view-switcher__item--selected': searchParams?.by === 'title' }}>
|
2024-07-03 21:25:03 +00:00
|
|
|
<A href="/topic?by=title">{t('By title')}</A>
|
2022-11-20 21:23:12 +00:00
|
|
|
</li>
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={searchParams?.by !== 'title'}>
|
2022-11-27 08:15:03 +00:00
|
|
|
<li class="view-switcher__search">
|
2022-12-01 18:45:35 +00:00
|
|
|
<SearchField onChange={(value) => setSearchQuery(value)} />
|
2022-11-27 08:15:03 +00:00
|
|
|
</li>
|
|
|
|
</Show>
|
2022-11-20 21:23:12 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2022-11-17 20:08:12 +00:00
|
|
|
</div>
|
|
|
|
)
|
2022-11-19 08:09:52 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
// meta
|
2023-12-13 10:39:31 +00:00
|
|
|
const ogImage = getImageUrl('production/image/logo_image.png')
|
|
|
|
const ogTitle = t('Themes and plots')
|
|
|
|
const description = t(
|
2024-06-26 08:22:05 +00:00
|
|
|
'Thematic table of contents of the magazine. Here you can find all the topics that the community authors wrote about'
|
2023-12-13 10:39:31 +00:00
|
|
|
)
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
return (
|
2022-11-19 13:04:42 +00:00
|
|
|
<div class={clsx(styles.allTopicsPage, 'wide-container')}>
|
2023-12-13 10:39:31 +00:00
|
|
|
<Meta name="descprition" content={description} />
|
2024-07-03 17:38:43 +00:00
|
|
|
<Meta name="keywords" content={lang() === 'ru' ? ruKeywords[''] : enKeywords['']} />
|
2023-12-13 10:39:31 +00:00
|
|
|
<Meta name="og:type" content="article" />
|
|
|
|
<Meta name="og:title" content={ogTitle} />
|
|
|
|
<Meta name="og:image" content={ogImage} />
|
|
|
|
<Meta name="twitter:image" content={ogImage} />
|
|
|
|
<Meta name="og:description" content={description} />
|
|
|
|
<Meta name="twitter:card" content="summary_large_image" />
|
|
|
|
<Meta name="twitter:title" content={ogTitle} />
|
|
|
|
<Meta name="twitter:description" content={description} />
|
2024-06-28 15:05:45 +00:00
|
|
|
<Show when={Boolean(filteredResults())} fallback={<Loading />}>
|
2023-12-13 10:39:31 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-19 offset-md-5">
|
|
|
|
<AllTopicsHead />
|
|
|
|
|
|
|
|
<Show when={filteredResults().length > 0}>
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={searchParams?.by === 'title'}>
|
2024-05-03 08:49:05 +00:00
|
|
|
<div class="col-lg-18 col-xl-15">
|
2023-12-13 10:39:31 +00:00
|
|
|
<ul class={clsx('nodash', styles.alphabet)}>
|
2024-06-24 17:50:27 +00:00
|
|
|
<For each={Array.from(alphabet())}>
|
2023-12-13 10:39:31 +00:00
|
|
|
{(letter, index) => (
|
|
|
|
<li>
|
|
|
|
<Show when={letter in byLetter()} fallback={letter}>
|
2024-07-03 07:02:46 +00:00
|
|
|
<A
|
2024-07-03 21:25:03 +00:00
|
|
|
href={`/topic?by=title#letter-${index()}`}
|
2023-12-13 10:39:31 +00:00
|
|
|
onClick={(event) => {
|
|
|
|
event.preventDefault()
|
|
|
|
scrollHandler(`letter-${index()}`)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{letter}
|
2024-07-03 07:02:46 +00:00
|
|
|
</A>
|
2023-12-13 10:39:31 +00:00
|
|
|
</Show>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<For each={sortedKeys()}>
|
|
|
|
{(letter) => (
|
|
|
|
<div class={clsx(styles.group, 'group')}>
|
2024-06-24 17:50:27 +00:00
|
|
|
<h2 id={`letter-${alphabet().indexOf(letter)}`}>{letter}</h2>
|
2023-12-13 10:39:31 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-20">
|
|
|
|
<div class="row">
|
|
|
|
<For each={byLetter()[letter]}>
|
|
|
|
{(topic) => (
|
|
|
|
<div class={clsx(styles.topic, 'topic col-sm-12 col-md-8')}>
|
2024-07-03 07:02:46 +00:00
|
|
|
<A href={`/topic/${topic.slug}`}>
|
2023-12-18 00:26:56 +00:00
|
|
|
{lang() === 'en'
|
|
|
|
? capitalize(topic.slug.replaceAll('-', ' '))
|
|
|
|
: topic.title}
|
2024-07-03 07:02:46 +00:00
|
|
|
</A>
|
2024-06-24 17:50:27 +00:00
|
|
|
<span class={styles.articlesCounter}>{topic.stat?.shouts || 0}</span>
|
2023-12-13 10:39:31 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
2022-11-14 21:58:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-05 15:56:59 +00:00
|
|
|
</div>
|
2023-12-13 10:39:31 +00:00
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Show>
|
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={searchParams?.by && searchParams?.by !== 'title'}>
|
2023-12-13 10:39:31 +00:00
|
|
|
<div class="row">
|
2024-05-03 08:49:05 +00:00
|
|
|
<div class="col-lg-18 col-xl-15 py-4">
|
2023-12-13 10:39:31 +00:00
|
|
|
<For each={filteredResults().slice(0, limit())}>
|
|
|
|
{(topic) => (
|
|
|
|
<>
|
2024-03-15 15:24:33 +00:00
|
|
|
<TopicBadge topic={topic} showStat={true} />
|
2023-12-13 10:39:31 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</For>
|
2022-11-11 10:22:07 +00:00
|
|
|
</div>
|
2023-05-17 20:27:24 +00:00
|
|
|
</div>
|
2023-12-13 10:39:31 +00:00
|
|
|
</Show>
|
2023-03-10 17:42:48 +00:00
|
|
|
|
2024-06-24 17:50:27 +00:00
|
|
|
<Show when={filteredResults().length > limit() && searchParams?.by !== 'title'}>
|
2023-12-13 10:39:31 +00:00
|
|
|
<div class={clsx(styles.loadMoreContainer, 'col-24 col-md-20 col-lg-14 offset-md-2')}>
|
|
|
|
<button class={clsx('button', styles.loadMoreButton)} onClick={showMore}>
|
|
|
|
{t('Load more')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2023-03-10 17:42:48 +00:00
|
|
|
</Show>
|
2023-12-13 10:39:31 +00:00
|
|
|
</div>
|
2023-03-10 17:42:48 +00:00
|
|
|
</div>
|
2023-12-13 10:39:31 +00:00
|
|
|
</Show>
|
2022-09-14 11:28:43 +00:00
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
)
|
|
|
|
}
|