webapp/src/components/Nav/Topics.tsx

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-03-04 17:26:28 +00:00
import { For, Show } from 'solid-js'
2022-09-09 11:53:35 +00:00
import type { Topic } from '../../graphql/types.gen'
2022-11-14 17:41:05 +00:00
import { Icon } from '../_shared/Icon'
2022-09-09 11:53:35 +00:00
import './Topics.scss'
2023-02-17 09:21:02 +00:00
import { useLocalize } from '../../context/localize'
2022-09-09 11:53:35 +00:00
2022-09-22 09:37:49 +00:00
export const NavTopics = (props: { topics: Topic[] }) => {
2023-02-17 09:21:02 +00:00
const { t, lang } = useLocalize()
2022-09-29 11:50:48 +00:00
const tag = (topic: Topic) =>
2023-02-17 09:21:02 +00:00
/[ЁА-яё]/.test(topic.title || '') && lang() !== 'ru' ? topic.slug : topic.title
2022-09-09 11:53:35 +00:00
// TODO: something about subtopics
return (
<nav class="subnavigation wide-container text-2xl">
<ul class="topics">
2022-09-22 09:37:49 +00:00
<Show when={props.topics.length > 0}>
2022-09-09 11:53:35 +00:00
<For each={props.topics}>
2022-09-29 11:50:48 +00:00
{(topic) => (
2022-09-09 11:53:35 +00:00
<li class="item">
<a href={`/topic/${topic.slug}`}>
2022-09-29 11:50:48 +00:00
<span>#{tag(topic)}</span>
2022-09-09 11:53:35 +00:00
</a>
</li>
)}
</For>
<li class="item right">
<a href={`/topics`}>
<span>
<Icon name="arrow-right-black" style={{ height: '12px', display: 'inline-block' }} />
<small style={{ margin: '4px' }}>{t('All topics')} </small>
</span>
</a>
</li>
</Show>
</ul>
</nav>
)
}