diff --git a/app.config.ts b/app.config.ts index 5c758d8d..b2f15b04 100644 --- a/app.config.ts +++ b/app.config.ts @@ -9,7 +9,8 @@ export default defineConfig({ ssr: true, server: { preset: isVercel ? 'vercel_edge' : isBun ? 'bun' : 'node', - port: 3000 + port: 3000, + https: true }, devOverlay: true, build: { @@ -43,6 +44,9 @@ export default defineConfig({ build: { chunkSizeWarningLimit: 1024, target: 'esnext' + }, + server: { + https: true } } } as SolidStartInlineConfig) diff --git a/src/app.tsx b/src/app.tsx index c47709f8..9f431cce 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -11,6 +11,7 @@ import { LocalizeProvider } from './context/localize' import { SessionProvider } from './context/session' import { TopicsProvider } from './context/topics' import { UIProvider } from './context/ui' // snackbar included +import { AuthorsProvider } from './context/authors' import '~/styles/app.scss' export const Providers = (props: { children?: JSX.Element }) => { @@ -24,7 +25,9 @@ export const Providers = (props: { children?: JSX.Element }) => { - }>{props.children} + + }>{props.children} + diff --git a/src/components/Views/AllAuthors/AllAuthors.tsx b/src/components/Views/AllAuthors/AllAuthors.tsx index 996811a4..8f068977 100644 --- a/src/components/Views/AllAuthors/AllAuthors.tsx +++ b/src/components/Views/AllAuthors/AllAuthors.tsx @@ -21,44 +21,64 @@ type Props = { authorsByShouts?: Author[] isLoaded: boolean } + export const AUTHORS_PER_PAGE = 20 export const ABC = { ru: 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ#', en: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ#' } -// useAuthors sorted from context, set filter/sort - export const AllAuthors = (props: Props) => { const { t, lang } = useLocalize() const alphabet = createMemo(() => ABC[lang()] || ABC['ru']) const [searchParams, changeSearchParams] = useSearchParams<{ by?: string }>() const { authorsSorted, setAuthorsSort, loadAuthors } = useAuthors() - const authors = createMemo(() => props.authors || authorsSorted()) const [loading, setLoading] = createSignal(false) + const [currentAuthors, setCurrentAuthors] = createSignal([]) + + // UPDATE Fetch authors initially and when searchParams.by changes + createEffect(() => { + fetchAuthors(searchParams.by || 'name', 0) + }) + + const authors = createMemo(() => { + let sortedAuthors = [...(props.authors || authorsSorted())] // Clone the array to avoid mutating the original + console.log('Before Sorting:', sortedAuthors.slice(0, 5)) // Log the first 5 authors for comparison + if (searchParams.by === 'name') { + sortedAuthors = sortedAuthors.sort((a, b) => a.name.localeCompare(b.name)) + console.log('Sorted by Name:', sortedAuthors.slice(0, 5)) + } else if (searchParams.by === 'shouts') { + sortedAuthors = sortedAuthors.sort((a, b) => (b.stat?.shouts || 0) - (a.stat?.shouts || 0)) + console.log('Sorted by Shouts:', sortedAuthors.slice(0, 5)) + } else if (searchParams.by === 'followers') { + sortedAuthors = sortedAuthors.sort((a, b) => (b.stat?.followers || 0) - (a.stat?.followers || 0)); + console.log('Sorted by Followers:', sortedAuthors.slice(0, 5)); + } + console.log('After Sorting:', sortedAuthors.slice(0, 5)) + return sortedAuthors + }) + + // Log authors data and searchParams for debugging + createEffect(() => { + console.log('Authors:', props.authors.slice(0, 5)) // Log the first 5 authors + console.log('Sorted Authors:', authors().slice(0, 5)) // Log the first 5 sorted authors + console.log('Search Params "by":', searchParams.by) + }) // filter const [searchQuery, setSearchQuery] = createSignal('') const [filteredAuthors, setFilteredAuthors] = createSignal([]) - createEffect( - () => - authors() && - setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[]) + createEffect(() => + authors() && setFilteredAuthors(dummyFilter(authors(), searchQuery(), lang()) as Author[]) ) - // sort by - onMount(() => !searchParams?.by && changeSearchParams({ by: 'name' })) - createEffect(on(() => searchParams?.by || 'name', setAuthorsSort || ((_) => null), {})) - // store by first char const byLetterFiltered = createMemo<{ [letter: string]: Author[] }>(() => { if (!(filteredAuthors()?.length > 0)) return {} console.debug('[components.AllAuthors] update byLetterFiltered', filteredAuthors()?.length) - return ( - filteredAuthors()?.reduce( - (acc, author: Author) => authorLetterReduce(acc, author, lang()), - {} as { [letter: string]: Author[] } - ) || {} + return filteredAuthors().reduce( + (acc, author: Author) => authorLetterReduce(acc, author, lang()), + {} as { [letter: string]: Author[] } ) }) @@ -81,21 +101,25 @@ export const AllAuthors = (props: Props) => { limit: AUTHORS_PER_PAGE, offset }) + // UPDATE authors to currentAuthors state + setCurrentAuthors((prev) => [...prev, ...authorsSorted()]) } catch (error) { console.error('[components.AuthorsList] error fetching authors:', error) } finally { setLoading(false) } } + const [currentPage, setCurrentPage] = createSignal<{ followers: number; shouts: number }>({ followers: 0, shouts: 0 }) + const loadMoreAuthors = () => { - const by = searchParams?.by as 'followers' | 'shouts' | undefined - if (!by) return - const nextPage = currentPage()[by] + 1 - fetchAuthors(by, nextPage).then(() => setCurrentPage({ ...currentPage(), [by]: nextPage })) + const by = searchParams?.by as 'followers' | 'shouts' | undefined; + if (!by) return; + const nextPage = currentPage()[by] + 1; + fetchAuthors(by, nextPage).then(() => setCurrentPage({ ...currentPage(), [by]: nextPage })); } const TabNavigator = () => ( @@ -109,21 +133,21 @@ export const AllAuthors = (props: Props) => { ['view-switcher__item--selected']: !searchParams?.by || searchParams?.by === 'shouts' })} > - {t('By shouts')} + changeSearchParams({ by: 'shouts' })}>{t('By shouts')}
  • - {t('By popularity')} + changeSearchParams({ by: 'followers' })}>{t('By popularity')}
  • - {t('By name')} + changeSearchParams({ by: 'name' })}>{t('By name')}