From 59885486eb378b201f40fa9018cc12b7b933024e Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Tue, 9 Jul 2024 20:53:28 +0000 Subject: [PATCH 1/3] feat: local server starts on https://localhost = true --- app.config.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) From b677cb34938bca95eff7a96e93be598983abc66d Mon Sep 17 00:00:00 2001 From: Stepan Vladovskiy Date: Thu, 11 Jul 2024 23:00:00 +0000 Subject: [PATCH 2/3] feat: step to all authors, with debug level an dsome minor changes in memo --- .../Views/AllAuthors/AllAuthors.tsx | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/components/Views/AllAuthors/AllAuthors.tsx b/src/components/Views/AllAuthors/AllAuthors.tsx index 996811a4..a22c33a8 100644 --- a/src/components/Views/AllAuthors/AllAuthors.tsx +++ b/src/components/Views/AllAuthors/AllAuthors.tsx @@ -21,44 +21,55 @@ 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 authors = createMemo(() => { + let sortedAuthors = [...(props.authors || authorsSorted())] // Clone the array to avoid mutating the original + console.log('Before Sorting:', sortedAuthors) + if (searchParams.by === 'name') { + sortedAuthors = sortedAuthors.sort((a, b) => a.name.localeCompare(b.name)) + console.log('Sorted by Name:', sortedAuthors) + } else if (searchParams.by === 'shouts') { + sortedAuthors = sortedAuthors.sort((a, b) => (b.stat?.shouts || 0) - (a.stat?.shouts || 0)) + console.log('Sorted by Shouts:', sortedAuthors) + } + console.log('After Sorting:', sortedAuthors) + return sortedAuthors + }) + + // Log authors data and searchParams for debugging + createEffect(() => { + console.log('Authors:', props.authors) + console.log('Sorted Authors:', 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[] } ) }) @@ -91,6 +102,7 @@ export const AllAuthors = (props: Props) => { followers: 0, shouts: 0 }) + const loadMoreAuthors = () => { const by = searchParams?.by as 'followers' | 'shouts' | undefined if (!by) return @@ -116,14 +128,14 @@ export const AllAuthors = (props: Props) => { ['view-switcher__item--selected']: searchParams?.by === 'followers' })} > - {t('By popularity')} + changeSearchParams({ by: 'followers' })}>{t('By popularity')}
  • - {t('By name')} + changeSearchParams({ by: 'name' })}>{t('By name')}
  • { const [authorsSorted, setAuthorsSorted] = createSignal([]) const [sortBy, setSortBy] = createSignal>() const { feedByAuthor } = useFeed() - const setAuthorsSort = (stat: string) => setSortBy((_) => byStat(stat) as SortFunction) + const setAuthorsSort = (stat: string) => setSortBy(() => byStat(stat) as SortFunction) // Эффект для отслеживания изменений сигнала sortBy и обновления authorsSorted createEffect( @@ -64,7 +64,7 @@ export const AuthorsProvider = (props: { children: JSX.Element }) => { [sortBy, authorsEntities], ([sortfn, authorsdict]) => { if (sortfn) { - setAuthorsSorted?.([...filterAndSort(Object.values(authorsdict), sortfn)]) + setAuthorsSorted([...filterAndSort(Object.values(authorsdict), sortfn)]) } }, { defer: true } @@ -101,6 +101,17 @@ export const AuthorsProvider = (props: { children: JSX.Element }) => { } } + const loadAuthorsPaginated = async (args: QueryLoad_Authors_ByArgs): Promise => { + try { + const fetcher = await loadAuthors(args) + const data = await fetcher() + if (data) addAuthors(data as Author[]) + } catch (error) { + console.error('Error loading authors:', error) + throw error + } + } + const topAuthors = createMemo(() => { const articlesByAuthorMap = feedByAuthor?.() || {} @@ -125,17 +136,6 @@ export const AuthorsProvider = (props: { children: JSX.Element }) => { return sortedTopAuthors }) - const loadAuthorsPaginated = async (args: QueryLoad_Authors_ByArgs): Promise => { - try { - const fetcher = await loadAuthors(args) - const data = await fetcher() - if (data) addAuthors(data as Author[]) - } catch (error) { - console.error('Error loading authors:', error) - throw error - } - } - const authorsByTopic = createMemo(() => { const articlesByAuthorMap = feedByAuthor?.() || {} const result: { [topicSlug: string]: Author[] } = {}