followed-fix

This commit is contained in:
Untone 2023-12-20 10:45:29 +03:00
parent cde041a047
commit ee6a55c86e
8 changed files with 41 additions and 37 deletions

View File

@ -95,9 +95,11 @@ export const FullArticle = (props: Props) => {
const body = createMemo(() => { const body = createMemo(() => {
if (props.article.layout === 'literature') { if (props.article.layout === 'literature') {
try { try {
const media = JSON.parse(props.article.media) if (props.article?.media) {
if (media.length > 0) { const media = JSON.parse(props.article.media)
return media[0].body if (media.length > 0) {
return media[0].body
}
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)

View File

@ -59,7 +59,7 @@ const CreateModalContent = (props: Props) => {
const handleCreate = async () => { const handleCreate = async () => {
try { try {
const initChat = await actions.createChat(usersId(), chatTitle()) const initChat = await actions.createChat(usersId(), chatTitle())
console.debug('[initChat]', initChat) console.debug('[components.Inbox] create chat result: ', initChat)
hideModal() hideModal()
await actions.loadChats() await actions.loadChats()
} catch (error) { } catch (error) {

View File

@ -40,7 +40,7 @@ export const PRERENDERED_ARTICLES_COUNT = 28
const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3 const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3
export const TopicView = (props: Props) => { export const TopicView = (props: Props) => {
const { t } = useLocalize() const { t, lang } = useLocalize()
const { searchParams, changeSearchParam } = useRouter<TopicsPageSearchParams>() const { searchParams, changeSearchParam } = useRouter<TopicsPageSearchParams>()
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
@ -50,17 +50,22 @@ export const TopicView = (props: Props) => {
const { authorsByTopic } = useAuthorsStore() const { authorsByTopic } = useAuthorsStore()
const topic = createMemo(() => topicEntities()[props.topicSlug]) const topic = createMemo(() =>
props.topic?.slug in topicEntities() ? topicEntities()[props.topic.slug] : props.topic,
onMount(() => { )
document.title = topic().title 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 () => { const loadMore = async () => {
saveScrollPosition() saveScrollPosition()
const { hasMore } = await loadShouts({ const { hasMore } = await loadShouts({
filters: { topic: props.topicSlug }, filters: { topic: topic()?.slug },
limit: LOAD_MORE_PAGE_SIZE, limit: LOAD_MORE_PAGE_SIZE,
offset: sortedArticles().length, offset: sortedArticles().length,
}) })
@ -75,7 +80,7 @@ export const TopicView = (props: Props) => {
} }
}) })
const title = createMemo(() => { const selectionTitle = createMemo(() => {
const m = searchParams().by const m = searchParams().by
if (m === 'viewed') return t('Top viewed') if (m === 'viewed') return t('Top viewed')
if (m === 'rating') return t('Top rated') 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), splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE),
) )
const pageTitle = `#${capitalize(topic().title, true)}` const ogImage = () =>
createEffect(() => props.title(pageTitle)) topic()?.pic
? getImageUrl(topic().pic, { width: 1200 })
const ogImage = topic().pic : getImageUrl('production/image/logo_image.png')
? getImageUrl(topic().pic, { width: 1200 }) const description = () =>
: getImageUrl('production/image/logo_image.png') topic()?.body
const description = topic().body ? getDescription(topic().body)
? getDescription(topic().body) : t('The most interesting publications on the topic', { topicName: title() })
: t('The most interesting publications on the topic', { topicName: pageTitle })
const ogTitle = pageTitle
return ( return (
<div class={styles.topicPage}> <div class={styles.topicPage}>
<Meta name="descprition" content={description} /> <Meta name="descprition" content={description()} />
<Meta name="keywords" content={t('topicKeywords', { topic: topic().title })} /> <Meta name="keywords" content={t('topicKeywords', { topic: title() })} />
<Meta name="og:type" content="article" /> <Meta name="og:type" content="article" />
<Meta name="og:title" content={ogTitle} /> <Meta name="og:title" content={title()} />
<Meta name="og:image" content={ogImage} /> <Meta name="og:image" content={ogImage()} />
<Meta name="twitter:image" content={ogImage} /> <Meta name="twitter:image" content={ogImage()} />
<Meta name="og:description" content={description} /> <Meta name="og:description" content={description()} />
<Meta name="twitter:card" content="summary_large_image" /> <Meta name="twitter:card" content="summary_large_image" />
<Meta name="twitter:title" content={ogTitle} /> <Meta name="twitter:title" content={title()} />
<Meta name="twitter:description" content={description} /> <Meta name="twitter:description" content={description()} />
<Show when={props.isLoaded} fallback={<Loading />}> <Show when={props.isLoaded} fallback={<Loading />}>
<Show when={topic()}> <Show when={topic()}>
<FullTopic topic={topic()} /> <FullTopic topic={topic()} />
@ -170,7 +173,7 @@ export const TopicView = (props: Props) => {
wrapper={'author'} wrapper={'author'}
/> />
<ArticleCardSwiper title={title()} slides={sortedArticles().slice(5, 11)} /> <ArticleCardSwiper title={selectionTitle()} slides={sortedArticles().slice(5, 11)} />
<Beside <Beside
beside={sortedArticles()[12]} beside={sortedArticles()[12]}

View File

@ -72,9 +72,8 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
onMount(() => { onMount(() => {
addHandler((data: SSEMessage) => { addHandler((data: SSEMessage) => {
if (data.entity === 'reaction' && isAuthenticated()) { if (data.entity === 'reaction' && isAuthenticated()) {
console.info(`[context.notifications] event`, data)
loadNotifications({ after: after(), limit: Math.max(PAGE_SIZE, loadedNotificationsCount()) }) loadNotifications({ after: after(), limit: Math.max(PAGE_SIZE, loadedNotificationsCount()) })
} else {
console.info(`[NotificationsProvider] bypassed:`, data)
} }
}) })
setAfter(now) setAfter(now)

View File

@ -55,7 +55,7 @@ export const apiClient = {
if (!response.data) { if (!response.data) {
console.error('[graphql.core] getRandomTopShouts error', response.error) 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) => { getUnratedShouts: async (limit = 50, offset = 0) => {

View File

@ -2,7 +2,7 @@ import { gql } from '@urql/core'
export default gql` export default gql`
query LoadRandomTopShoutsQuery($params: LoadRandomTopShoutsParams) { query LoadRandomTopShoutsQuery($params: LoadRandomTopShoutsParams) {
load_shouts_top_random(params: $params) { load_shouts_random_top(params: $params) {
id id
title title
# lead # lead

View File

@ -2,7 +2,7 @@ import { gql } from '@urql/core'
export default gql` export default gql`
query AuthorsFollowedByQuery($slug: String, $user: String, $author_id: Int) { 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 id
slug slug
name name

View File

@ -1,5 +1,5 @@
export const capitalize = (originalString: string, firstonly = false) => { export const capitalize = (originalString: string, firstonly = false) => {
const s = originalString.trim() const s = (originalString || '').trim()
return firstonly return firstonly
? s.charAt(0).toUpperCase() + s.slice(1) ? s.charAt(0).toUpperCase() + s.slice(1)
: s : s