From ee6a55c86e6567e4e11415ea03cdc28f5819b1b1 Mon Sep 17 00:00:00 2001 From: Untone Date: Wed, 20 Dec 2023 10:45:29 +0300 Subject: [PATCH] followed-fix --- src/components/Article/FullArticle.tsx | 8 ++- src/components/Inbox/CreateModalContent.tsx | 2 +- src/components/Views/Topic.tsx | 57 ++++++++++--------- src/context/notifications.tsx | 3 +- src/graphql/client/core.ts | 2 +- .../query/core/articles-load-random-top.ts | 2 +- src/graphql/query/core/authors-followed-by.ts | 2 +- src/utils/capitalize.ts | 2 +- 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 9a4b7370..f33123d0 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -95,9 +95,11 @@ export const FullArticle = (props: Props) => { const body = createMemo(() => { if (props.article.layout === 'literature') { try { - const media = JSON.parse(props.article.media) - if (media.length > 0) { - return media[0].body + if (props.article?.media) { + const media = JSON.parse(props.article.media) + if (media.length > 0) { + return media[0].body + } } } catch (error) { console.error(error) diff --git a/src/components/Inbox/CreateModalContent.tsx b/src/components/Inbox/CreateModalContent.tsx index d6d246fa..973cb195 100644 --- a/src/components/Inbox/CreateModalContent.tsx +++ b/src/components/Inbox/CreateModalContent.tsx @@ -59,7 +59,7 @@ const CreateModalContent = (props: Props) => { const handleCreate = async () => { try { const initChat = await actions.createChat(usersId(), chatTitle()) - console.debug('[initChat]', initChat) + console.debug('[components.Inbox] create chat result: ', initChat) hideModal() await actions.loadChats() } catch (error) { diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index 02ad1353..7e377690 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -40,7 +40,7 @@ export const PRERENDERED_ARTICLES_COUNT = 28 const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3 export const TopicView = (props: Props) => { - const { t } = useLocalize() + const { t, lang } = useLocalize() const { searchParams, changeSearchParam } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) @@ -50,17 +50,22 @@ export const TopicView = (props: Props) => { const { authorsByTopic } = useAuthorsStore() - const topic = createMemo(() => topicEntities()[props.topicSlug]) - - onMount(() => { - document.title = topic().title - }) + const topic = createMemo(() => + props.topic?.slug in topicEntities() ? topicEntities()[props.topic.slug] : props.topic, + ) + const title = () => + `#${capitalize( + lang() == 'en' ? topic()?.slug.replace(/-/, ' ') : topic()?.title || topic()?.slug.replace(/-/, ' '), + true, + )}` + onMount(() => (document.title = title())) + createEffect(() => props.title(title())) const loadMore = async () => { saveScrollPosition() const { hasMore } = await loadShouts({ - filters: { topic: props.topicSlug }, + filters: { topic: topic()?.slug }, limit: LOAD_MORE_PAGE_SIZE, offset: sortedArticles().length, }) @@ -75,7 +80,7 @@ export const TopicView = (props: Props) => { } }) - const title = createMemo(() => { + const selectionTitle = createMemo(() => { const m = searchParams().by if (m === 'viewed') return t('Top viewed') if (m === 'rating') return t('Top rated') @@ -87,29 +92,27 @@ export const TopicView = (props: Props) => { splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE), ) - const pageTitle = `#${capitalize(topic().title, true)}` - createEffect(() => props.title(pageTitle)) - - const ogImage = topic().pic - ? getImageUrl(topic().pic, { width: 1200 }) - : getImageUrl('production/image/logo_image.png') - const description = topic().body - ? getDescription(topic().body) - : t('The most interesting publications on the topic', { topicName: pageTitle }) - const ogTitle = pageTitle + const ogImage = () => + topic()?.pic + ? getImageUrl(topic().pic, { width: 1200 }) + : getImageUrl('production/image/logo_image.png') + const description = () => + topic()?.body + ? getDescription(topic().body) + : t('The most interesting publications on the topic', { topicName: title() }) return (
- - + + - - - - + + + + - - + + }> @@ -170,7 +173,7 @@ export const TopicView = (props: Props) => { wrapper={'author'} /> - + { onMount(() => { addHandler((data: SSEMessage) => { if (data.entity === 'reaction' && isAuthenticated()) { + console.info(`[context.notifications] event`, data) loadNotifications({ after: after(), limit: Math.max(PAGE_SIZE, loadedNotificationsCount()) }) - } else { - console.info(`[NotificationsProvider] bypassed:`, data) } }) setAfter(now) diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index 6b544a9f..cd2b9eaf 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -55,7 +55,7 @@ export const apiClient = { if (!response.data) { console.error('[graphql.core] getRandomTopShouts error', response.error) } - return response.data.load_shouts_top_random + return response.data.load_shouts_random_top }, getUnratedShouts: async (limit = 50, offset = 0) => { diff --git a/src/graphql/query/core/articles-load-random-top.ts b/src/graphql/query/core/articles-load-random-top.ts index 20e32b27..24bb164c 100644 --- a/src/graphql/query/core/articles-load-random-top.ts +++ b/src/graphql/query/core/articles-load-random-top.ts @@ -2,7 +2,7 @@ import { gql } from '@urql/core' export default gql` query LoadRandomTopShoutsQuery($params: LoadRandomTopShoutsParams) { - load_shouts_top_random(params: $params) { + load_shouts_random_top(params: $params) { id title # lead diff --git a/src/graphql/query/core/authors-followed-by.ts b/src/graphql/query/core/authors-followed-by.ts index 8f6c1ccc..06f6f5e9 100644 --- a/src/graphql/query/core/authors-followed-by.ts +++ b/src/graphql/query/core/authors-followed-by.ts @@ -2,7 +2,7 @@ import { gql } from '@urql/core' export default gql` query AuthorsFollowedByQuery($slug: String, $user: String, $author_id: Int) { - get_author_followers(slug: $slug, user: $user, author_id: $author_id) { + get_author_followed(slug: $slug, user: $user, author_id: $author_id) { id slug name diff --git a/src/utils/capitalize.ts b/src/utils/capitalize.ts index 8e4ac45d..b97bc616 100644 --- a/src/utils/capitalize.ts +++ b/src/utils/capitalize.ts @@ -1,5 +1,5 @@ export const capitalize = (originalString: string, firstonly = false) => { - const s = originalString.trim() + const s = (originalString || '').trim() return firstonly ? s.charAt(0).toUpperCase() + s.slice(1) : s