From 7573c6334cd51f5bc6f0688ada4b0c7088438e15 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 18 Jul 2024 12:22:28 +0300 Subject: [PATCH] mainpage-loadmore-hide --- app.config.ts | 2 + src/components/Views/Author/Author.tsx | 37 +++++----- src/components/Views/Feed/Feed.tsx | 16 ++++- src/context/notifications.tsx | 6 +- src/graphql/api/public.ts | 4 ++ src/intl/locales/ru/translation.json | 1 + src/routes/(main).tsx | 2 +- src/routes/[slug]/[...tab].tsx | 6 +- src/routes/author/[slug]/[...tab].tsx | 96 +++++++++++++++----------- src/routes/edit/new.tsx | 14 +++- 10 files changed, 112 insertions(+), 72 deletions(-) diff --git a/app.config.ts b/app.config.ts index 938a648a..6ef50f1f 100644 --- a/app.config.ts +++ b/app.config.ts @@ -8,6 +8,8 @@ import sassDts from 'vite-plugin-sass-dts' const isVercel = Boolean(process?.env.VERCEL) const isBun = Boolean(process.env.BUN) +console.info(`[app.config] build for ${isVercel ? 'vercel' : isBun? 'bun' : 'node'}!`) + const polyfillOptions = { include: ['path', 'stream', 'util'], exclude: ['http'], diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 5c7413cc..221370fc 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -1,9 +1,8 @@ import { A, useLocation } from '@solidjs/router' import { clsx } from 'clsx' -import { For, Match, Show, Switch, createEffect, createMemo, createSignal, on, onMount } from 'solid-js' +import { For, Match, Show, Switch, createEffect, createMemo, createSignal, on } from 'solid-js' import { Loading } from '~/components/_shared/Loading' import { useAuthors } from '~/context/authors' -import { useFeed } from '~/context/feed' import { useFollowing } from '~/context/following' import { useGraphQL } from '~/context/graphql' import { useLocalize } from '~/context/localize' @@ -28,7 +27,6 @@ type AuthorViewProps = { selectedTab: string shouts?: Shout[] author?: Author - topics?: Topic[] } export const PRERENDERED_ARTICLES_COUNT = 12 @@ -40,7 +38,6 @@ export const AuthorView = (props: AuthorViewProps) => { const loc = useLocation() const { session } = useSession() const { query } = useGraphQL() - const { sortedFeed } = useFeed() const { loadAuthor, authorsEntities } = useAuthors() const { followers: myFollowers, follows: myFollows } = useFollowing() @@ -55,7 +52,7 @@ export const AuthorView = (props: AuthorViewProps) => { // derivatives const me = createMemo(() => session()?.user?.app_data?.profile as Author) const pages = createMemo(() => - paginate(sortedFeed(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE) + paginate((props.shouts || []).slice(1), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE) ) // 1 // проверяет не собственный ли это профиль, иначе - загружает @@ -107,12 +104,11 @@ export const AuthorView = (props: AuthorViewProps) => { // event handlers let bioContainerRef: HTMLDivElement let bioWrapperRef: HTMLDivElement - const checkBioHeight = () => { - if (bioContainerRef) { - const showExpand = bioContainerRef.offsetHeight > bioWrapperRef.offsetHeight - setShowExpandBioControl(showExpand) - console.debug('[AuthorView] mounted, show expand bio container:', showExpand) - } + const checkBioHeight = (bio = bioWrapperRef) => { + if (!bio) return + const showExpand = bioContainerRef.offsetHeight > bio.offsetHeight + setShowExpandBioControl(showExpand) + console.debug('[AuthorView] mounted, show expand bio container:', showExpand) } const handleDeleteComment = (id: number) => { @@ -120,7 +116,8 @@ export const AuthorView = (props: AuthorViewProps) => { } // on load - onMount(checkBioHeight) + createEffect(on(() => bioContainerRef, checkBioHeight)) + createEffect(on(() => props.selectedTab, (tab) => tab && console.log('[views.Author] profile tab switched'))) return (
@@ -227,18 +224,18 @@ export const AuthorView = (props: AuthorViewProps) => {
- 0}> - + 0 && props.shouts[0]}> + - 1}> + 1}> - - + + - - + + - 3}> + 3}> {(page) => ( <> diff --git a/src/components/Views/Feed/Feed.tsx b/src/components/Views/Feed/Feed.tsx index d8df5169..ae1b39dd 100644 --- a/src/components/Views/Feed/Feed.tsx +++ b/src/components/Views/Feed/Feed.tsx @@ -39,6 +39,12 @@ export type FeedProps = { order?: '' | 'likes' | 'hot' } +const PERIODS = { + 'day': 24 * 60 * 60, + 'month': 30 * 24 * 60 * 60, + 'year': 365 * 24 * 60 * 60 +} + export const FeedView = (props: FeedProps) => { const { t } = useLocalize() const loc = useLocation() @@ -59,9 +65,6 @@ export const FeedView = (props: FeedProps) => { const { topAuthors } = useAuthors() const [topComments, setTopComments] = createSignal([]) const [searchParams, changeSearchParams] = useSearchParams() - const asOption = (o: string) => ({ value: o, title: t(o) }) - const asOptions = (opts: string[]) => opts.map(asOption) - const currentPeriod = createMemo(() => asOption(searchParams?.period || '')) const loadTopComments = async () => { const comments = await loadReactionsBy({ by: { comment: true }, limit: 50 }) setTopComments(comments.sort(byCreated).reverse()) @@ -94,6 +97,13 @@ export const FeedView = (props: FeedProps) => { setShareData(shared) } + const asOption = (o: string) => { + const value = Math.floor(Date.now()/1000) - PERIODS[o as keyof typeof PERIODS] + return { value, title: t(o) } + } + const asOptions = (opts: string[]) => opts.map(asOption) + const currentPeriod = createMemo(() => asOption(searchParams?.period || '')) + return (
diff --git a/src/context/notifications.tsx b/src/context/notifications.tsx index 94e103b4..e989893f 100644 --- a/src/context/notifications.tsx +++ b/src/context/notifications.tsx @@ -89,7 +89,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => { if (data.entity === 'reaction' && authorized()) { console.info('[context.notifications] event', data) loadNotificationsGrouped({ - after: after() || Date.now(), + after: after() || now, limit: Math.max(PAGE_SIZE, loadedNotificationsCount()) }) } @@ -108,14 +108,14 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => { const markSeenAll = async () => { if (authorized()) { const _resp = await mutation(markSeenAfterMutation, { after: after() }).toPromise() - await loadNotificationsGrouped({ after: after() || Date.now(), limit: loadedNotificationsCount() }) + await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() }) } } const markSeen = async (notification_id: number) => { if (authorized()) { await mutation(markSeenMutation, { notification_id }).toPromise() - await loadNotificationsGrouped({ after: after() || Date.now(), limit: loadedNotificationsCount() }) + await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() }) } } diff --git a/src/graphql/api/public.ts b/src/graphql/api/public.ts index 3d00724a..02fc58e9 100644 --- a/src/graphql/api/public.ts +++ b/src/graphql/api/public.ts @@ -58,6 +58,10 @@ export const loadShouts = (options: LoadShoutsOptions) => { } export const loadReactions = (options: QueryLoad_Reactions_ByArgs) => { + if (!options.by) { + console.debug(options) + throw new Error('[api] wrong loadReactions call') + } const kind = options.by?.comment ? 'comments' : options.by?.rating ? 'votes' : 'reactions' const allorone = options.by?.shout ? `shout-${options.by.shout}` : 'all' const page = `${options.offset || 0}-${(options?.limit || 0) + (options.offset || 0)}` diff --git a/src/intl/locales/ru/translation.json b/src/intl/locales/ru/translation.json index 47bd93b7..f1bf6452 100644 --- a/src/intl/locales/ru/translation.json +++ b/src/intl/locales/ru/translation.json @@ -45,6 +45,7 @@ "Artworks": "Артворки", "Audio": "Аудио", "Author": "Автор", + "author profile was not found": "не удалось найти профиль автора", "Authors": "Авторы", "Autotypograph": "Автотипограф", "Back": "Назад", diff --git a/src/routes/(main).tsx b/src/routes/(main).tsx index 367247a5..a2897f83 100644 --- a/src/routes/(main).tsx +++ b/src/routes/(main).tsx @@ -109,7 +109,7 @@ export default function HomePage(props: RouteSectionProps) { return ( - +