import { createEffect, createMemo, For, Show } from 'solid-js' import type { Topic } from '../../graphql/types.gen' import { Icon } from '../Nav/Icon' import { t } from '../../utils/intl' import { setTopicsSort, useTopicsStore } from '../../stores/zine/topics' import { handleClientRouteLinkClick, useRouter } from '../../stores/router' import { TopicCard } from '../Topic/Card' import { useAuthStore } from '../../stores/auth' import styles from '../../styles/AllTopics.module.scss' import cardStyles from '../Topic/Card.module.scss' import { clsx } from 'clsx' type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' } type AllTopicsViewProps = { topics: Topic[] } export const AllTopicsView = (props: AllTopicsViewProps) => { const { searchParams, changeSearchParam } = useRouter() const { sortedTopics } = useTopicsStore({ topics: props.topics, sortBy: searchParams().by || 'shouts' }) const { session } = useAuthStore() createEffect(() => { setTopicsSort(searchParams().by || 'shouts') }) const byLetter = createMemo<{ [letter: string]: Topic[] }>(() => { return sortedTopics().reduce((acc, topic) => { const letter = topic.title[0].toUpperCase() if (!acc[letter]) { acc[letter] = [] } acc[letter].push(topic) return acc }, {} as { [letter: string]: Topic[] }) }) const sortedKeys = createMemo(() => { const keys = Object.keys(byLetter()) keys.sort() return keys }) const subscribed = (s) => Boolean(session()?.news?.topics && session()?.news?.topics?.includes(s || '')) return (
0}>
( {(topic) => } )} > {(letter) => (

{letter}

{(topic) => ( )}
)}
) }