From 3d1841076380dd3dddf45238d45e54d0673d0d51 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 27 Dec 2023 02:28:26 +0300 Subject: [PATCH] inbox-authors-preload-2 --- src/components/Views/Inbox.tsx | 15 ++++++++++++--- src/pages/allAuthors.page.server.ts | 2 +- src/pages/allAuthors.page.tsx | 2 +- src/pages/inbox.page.tsx | 16 ++++++++++++++-- src/pages/index.page.server.ts | 9 +++------ 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 3afc8ecc..5ef7f4ad 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -8,6 +8,7 @@ import { useInbox } from '../../context/inbox' import { useLocalize } from '../../context/localize' import { useSession } from '../../context/session' import { useRouter } from '../../stores/router' +import { AuthorsSortBy, useAuthorsStore } from '../../stores/zine/authors' import { showModal } from '../../stores/ui' import { Icon } from '../_shared/Icon' import { Popover } from '../_shared/Popover' @@ -23,6 +24,7 @@ import { Modal } from '../Nav/Modal' import styles from '../../styles/Inbox.module.scss' type InboxSearchParams = { + by?: string initChat: string chat: string } @@ -35,14 +37,18 @@ const handleOpenInviteModal = () => { showModal('inviteToChat') } -export const InboxView = () => { +type Props = { + authors: Author[] + isLoaded: boolean +} + +export const InboxView = (props: Props) => { const { t } = useLocalize() const { chats, messages, actions: { loadChats, loadRecipients, getMessages, sendMessage, createChat }, } = useInbox() - const [recipients, setRecipients] = createSignal([]) const [sortByGroup, setSortByGroup] = createSignal(false) const [sortByPerToPer, setSortByPerToPer] = createSignal(false) @@ -53,7 +59,10 @@ export const InboxView = () => { const { author } = useSession() const currentUserId = createMemo(() => author()?.id) const { changeSearchParams, searchParams } = useRouter() - + const { sortedAuthors } = useAuthorsStore({ + authors: props.authors, + sortBy: (searchParams()?.by as AuthorsSortBy) || 'name', + }) const messagesContainerRef: { current: HTMLDivElement } = { current: null, } diff --git a/src/pages/allAuthors.page.server.ts b/src/pages/allAuthors.page.server.ts index de7e51ff..a8e31794 100644 --- a/src/pages/allAuthors.page.server.ts +++ b/src/pages/allAuthors.page.server.ts @@ -4,7 +4,7 @@ import type { PageContext } from '../renderer/types' import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (_pageContext: PageContext) => { - const allAuthors = await apiClient.getAllAuthors() // limit 50, offset 0 + const allAuthors = await apiClient.getAllAuthors() const pageProps: PageProps = { allAuthors, seo: { title: '' } } diff --git a/src/pages/allAuthors.page.tsx b/src/pages/allAuthors.page.tsx index 5b4b4f99..0384eb7c 100644 --- a/src/pages/allAuthors.page.tsx +++ b/src/pages/allAuthors.page.tsx @@ -17,7 +17,7 @@ export const AllAuthorsPage = (props: PageProps) => { return } - await loadAllAuthors() // default limit, offset: 60, 0 + await loadAllAuthors() setIsLoaded(true) }) diff --git a/src/pages/inbox.page.tsx b/src/pages/inbox.page.tsx index 1d09f694..76ff3050 100644 --- a/src/pages/inbox.page.tsx +++ b/src/pages/inbox.page.tsx @@ -3,15 +3,27 @@ import { ShowOnlyOnClient } from '../components/_shared/ShowOnlyOnClient' import { InboxView } from '../components/Views/Inbox' import { InboxProvider } from '../context/inbox' import { useLocalize } from '../context/localize' +import type { PageProps } from './types' +import { createSignal, onMount } from 'solid-js' +import { loadAllAuthors } from '../stores/zine/authors' -export const InboxPage = () => { +export const InboxPage = (props: PageProps) => { const { t } = useLocalize() + const [isLoaded, setIsLoaded] = createSignal(Boolean(props.allAuthors)) + onMount(async () => { + if (isLoaded()) { + return + } + + await loadAllAuthors() + setIsLoaded(true) + }) return ( - + diff --git a/src/pages/index.page.server.ts b/src/pages/index.page.server.ts index 22871dcf..a8e31794 100644 --- a/src/pages/index.page.server.ts +++ b/src/pages/index.page.server.ts @@ -1,15 +1,12 @@ import type { PageProps } from './types' import type { PageContext } from '../renderer/types' -import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Home' import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (_pageContext: PageContext) => { - const homeShouts = await apiClient.getShouts({ - filters: { published: true }, - limit: PRERENDERED_ARTICLES_COUNT, - }) - const pageProps: PageProps = { homeShouts, seo: { title: '' } } + const allAuthors = await apiClient.getAllAuthors() + + const pageProps: PageProps = { allAuthors, seo: { title: '' } } return { pageContext: {