2024-01-31 12:34:15 +00:00
|
|
|
import type { Author, Reaction, Shout, Topic } from '../../../graphql/schema/core.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
|
|
|
import { getPagePath } from '@nanostores/router'
|
2023-12-13 10:39:31 +00:00
|
|
|
import { Meta } from '@solidjs/meta'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-01-31 12:34:15 +00:00
|
|
|
import { Show, createMemo, createSignal, Switch, onMount, For, Match, createEffect, on } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-01-31 17:38:00 +00:00
|
|
|
import { useFollowing } from '../../../context/following'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { useLocalize } from '../../../context/localize'
|
2023-11-28 13:18:25 +00:00
|
|
|
import { apiClient } from '../../../graphql/client/core'
|
2023-09-16 06:26:19 +00:00
|
|
|
import { router, useRouter } from '../../../stores/router'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { loadShouts, useArticlesStore } from '../../../stores/zine/articles'
|
2023-12-25 06:52:04 +00:00
|
|
|
import { loadAuthor, useAuthorsStore } from '../../../stores/zine/authors'
|
2023-12-13 10:39:31 +00:00
|
|
|
import { getImageUrl } from '../../../utils/getImageUrl'
|
|
|
|
import { getDescription } from '../../../utils/meta'
|
2023-05-17 10:41:50 +00:00
|
|
|
import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll'
|
|
|
|
import { splitToPages } from '../../../utils/splitToPages'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Loading } from '../../_shared/Loading'
|
2023-05-17 10:41:50 +00:00
|
|
|
import { Comment } from '../../Article/Comment'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { AuthorCard } from '../../Author/AuthorCard'
|
2023-12-27 23:35:43 +00:00
|
|
|
import { AuthorShoutsRating } from '../../Author/AuthorShoutsRating'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { Row1 } from '../../Feed/Row1'
|
|
|
|
import { Row2 } from '../../Feed/Row2'
|
|
|
|
import { Row3 } from '../../Feed/Row3'
|
|
|
|
|
|
|
|
import styles from './Author.module.scss'
|
|
|
|
import stylesArticle from '../../Article/Article.module.scss'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-09-09 12:04:46 +00:00
|
|
|
type Props = {
|
2022-11-15 14:24:50 +00:00
|
|
|
shouts: Shout[]
|
2022-09-09 11:53:35 +00:00
|
|
|
author: Author
|
2022-10-05 15:11:14 +00:00
|
|
|
authorSlug: string
|
2022-09-22 09:37:49 +00:00
|
|
|
}
|
2022-10-28 21:21:47 +00:00
|
|
|
export const PRERENDERED_ARTICLES_COUNT = 12
|
2023-02-17 09:21:02 +00:00
|
|
|
const LOAD_MORE_PAGE_SIZE = 9
|
2022-10-28 21:21:47 +00:00
|
|
|
|
2023-09-09 12:04:46 +00:00
|
|
|
export const AuthorView = (props: Props) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2024-01-31 16:09:42 +00:00
|
|
|
const { loadSubscriptions } = useFollowing()
|
2023-04-20 14:01:15 +00:00
|
|
|
const { sortedArticles } = useArticlesStore({ shouts: props.shouts })
|
2022-09-28 20:16:44 +00:00
|
|
|
const { authorEntities } = useAuthorsStore({ authors: [props.author] })
|
2023-10-14 11:39:24 +00:00
|
|
|
const { page: getPage } = useRouter()
|
2022-10-28 21:21:47 +00:00
|
|
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
2023-09-06 22:58:54 +00:00
|
|
|
const [isBioExpanded, setIsBioExpanded] = createSignal(false)
|
2023-02-13 13:48:05 +00:00
|
|
|
const [followers, setFollowers] = createSignal<Author[]>([])
|
2023-09-18 16:33:22 +00:00
|
|
|
const [following, setFollowing] = createSignal<Array<Author | Topic>>([])
|
2023-09-06 22:58:54 +00:00
|
|
|
const [showExpandBioControl, setShowExpandBioControl] = createSignal(false)
|
2023-12-25 06:52:04 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
// current author
|
|
|
|
const [author, setAuthor] = createSignal<Author>()
|
|
|
|
createEffect(() => {
|
|
|
|
try {
|
|
|
|
const a = authorEntities()[props.authorSlug]
|
|
|
|
setAuthor(a)
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
createEffect(() => {
|
2023-12-27 21:04:09 +00:00
|
|
|
if (author() && author().id && !author().stat) {
|
2024-01-31 12:34:15 +00:00
|
|
|
const a = loadAuthor({ slug: '', author_id: author().id })
|
2023-12-25 07:32:53 +00:00
|
|
|
console.debug(`[AuthorView] loaded author:`, a)
|
2023-12-24 17:29:16 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-09-15 09:30:50 +00:00
|
|
|
const bioContainerRef: { current: HTMLDivElement } = { current: null }
|
2023-09-18 16:33:22 +00:00
|
|
|
const bioWrapperRef: { current: HTMLDivElement } = { current: null }
|
2024-01-31 12:34:15 +00:00
|
|
|
|
2024-02-03 07:56:11 +00:00
|
|
|
const fetchData = async (slug) => {
|
2023-04-22 14:36:38 +00:00
|
|
|
try {
|
2024-02-03 07:56:11 +00:00
|
|
|
const [subscriptionsResult, followersResult] = await Promise.all([
|
|
|
|
(async () => {
|
|
|
|
const [getAuthors, getTopics] = await Promise.all([
|
|
|
|
apiClient.getAuthorFollowingAuthors({ slug }),
|
|
|
|
apiClient.getAuthorFollowingTopics({ slug }),
|
|
|
|
])
|
|
|
|
return { authors: getAuthors, topics: getTopics }
|
|
|
|
})(),
|
|
|
|
apiClient.getAuthorFollowers({ slug }),
|
2023-05-17 10:41:50 +00:00
|
|
|
])
|
2024-02-03 07:56:11 +00:00
|
|
|
|
|
|
|
const { authors, topics } = subscriptionsResult
|
|
|
|
setFollowing([...(authors || []), ...(topics || [])])
|
|
|
|
setFollowers(followersResult || [])
|
|
|
|
|
|
|
|
console.info('[components.Author] following data loaded')
|
2023-04-22 14:36:38 +00:00
|
|
|
} catch (error) {
|
2024-02-03 07:56:11 +00:00
|
|
|
console.error('[components.Author] fetch error', error)
|
2023-04-22 14:36:38 +00:00
|
|
|
}
|
2023-05-17 10:41:50 +00:00
|
|
|
}
|
2023-04-22 14:36:38 +00:00
|
|
|
|
2023-09-06 22:58:54 +00:00
|
|
|
const checkBioHeight = () => {
|
2023-09-15 09:30:50 +00:00
|
|
|
if (bioContainerRef.current) {
|
2023-09-18 16:33:22 +00:00
|
|
|
setShowExpandBioControl(bioContainerRef.current.offsetHeight > bioWrapperRef.current.offsetHeight)
|
2023-09-06 22:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-03 07:56:11 +00:00
|
|
|
onMount(() => fetchData(props.authorSlug))
|
2023-11-14 10:45:44 +00:00
|
|
|
|
2022-10-28 21:21:47 +00:00
|
|
|
const loadMore = async () => {
|
|
|
|
saveScrollPosition()
|
2022-11-18 02:23:04 +00:00
|
|
|
const { hasMore } = await loadShouts({
|
2023-04-20 14:01:15 +00:00
|
|
|
filters: { author: props.authorSlug },
|
2022-10-28 21:21:47 +00:00
|
|
|
limit: LOAD_MORE_PAGE_SIZE,
|
2023-11-14 15:10:00 +00:00
|
|
|
offset: sortedArticles().length,
|
2022-10-28 21:21:47 +00:00
|
|
|
})
|
|
|
|
setIsLoadMoreButtonVisible(hasMore)
|
|
|
|
restoreScrollPosition()
|
|
|
|
}
|
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
onMount(() => {
|
|
|
|
checkBioHeight()
|
|
|
|
|
|
|
|
// pagination
|
|
|
|
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
|
|
|
loadMore()
|
2024-01-31 16:09:42 +00:00
|
|
|
loadSubscriptions()
|
2024-01-31 12:34:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-10-14 11:39:24 +00:00
|
|
|
const pages = createMemo<Shout[][]>(() =>
|
2023-11-14 15:10:00 +00:00
|
|
|
splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE),
|
2022-10-28 21:21:47 +00:00
|
|
|
)
|
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
const fetchComments = async (commenter: Author) => {
|
|
|
|
const data = await apiClient.getReactionsBy({
|
|
|
|
by: { comment: true, created_by: commenter.id },
|
|
|
|
})
|
|
|
|
console.debug(`[components.Author] fetched ${data.length} comments`)
|
|
|
|
setCommented(data)
|
|
|
|
}
|
2023-04-20 14:01:15 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
const [commented, setCommented] = createSignal<Reaction[]>([])
|
2024-01-31 15:15:23 +00:00
|
|
|
createEffect(() => {
|
2024-01-31 16:09:42 +00:00
|
|
|
const a = author()
|
|
|
|
if (a) {
|
|
|
|
fetchComments(a)
|
2024-01-31 15:15:23 +00:00
|
|
|
}
|
|
|
|
})
|
2023-09-09 12:04:46 +00:00
|
|
|
|
2024-01-31 12:34:15 +00:00
|
|
|
const ogImage = createMemo(() =>
|
|
|
|
author()?.pic
|
|
|
|
? getImageUrl(author()?.pic, { width: 1200 })
|
|
|
|
: getImageUrl('production/image/logo_image.png'),
|
|
|
|
)
|
|
|
|
const description = createMemo(() => getDescription(author()?.bio))
|
2023-12-13 10:39:31 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
return (
|
2023-08-27 21:21:40 +00:00
|
|
|
<div class={styles.authorPage}>
|
2024-01-31 12:34:15 +00:00
|
|
|
<Show when={author()}>
|
|
|
|
<Meta name="descprition" content={description()} />
|
|
|
|
<Meta name="og:type" content="profile" />
|
|
|
|
<Meta name="og:title" content={author().name} />
|
|
|
|
<Meta name="og:image" content={ogImage()} />
|
|
|
|
<Meta name="og:description" content={description()} />
|
|
|
|
<Meta name="twitter:card" content="summary_large_image" />
|
|
|
|
<Meta name="twitter:title" content={author().name} />
|
|
|
|
<Meta name="twitter:description" content={description()} />
|
|
|
|
<Meta name="twitter:image" content={ogImage()} />
|
|
|
|
</Show>
|
2023-02-17 09:21:02 +00:00
|
|
|
<div class="wide-container">
|
2023-10-16 10:31:10 +00:00
|
|
|
<Show when={author()} fallback={<Loading />}>
|
|
|
|
<>
|
|
|
|
<div class={styles.authorHeader}>
|
2023-10-20 16:21:40 +00:00
|
|
|
<AuthorCard author={author()} followers={followers()} following={following()} />
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
2023-10-16 10:31:10 +00:00
|
|
|
<div class={clsx(styles.groupControls, 'row')}>
|
|
|
|
<div class="col-md-16">
|
|
|
|
<ul class="view-switcher">
|
|
|
|
<li classList={{ 'view-switcher__item--selected': getPage().route === 'author' }}>
|
|
|
|
<a href={getPagePath(router, 'author', { slug: props.authorSlug })}>
|
|
|
|
{t('Publications')}
|
|
|
|
</a>
|
2023-12-24 17:29:16 +00:00
|
|
|
<Show when={author().stat}>
|
|
|
|
<span class="view-switcher__counter">{author().stat.shouts}</span>
|
|
|
|
</Show>
|
2023-10-16 10:31:10 +00:00
|
|
|
</li>
|
|
|
|
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}>
|
|
|
|
<a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}>
|
|
|
|
{t('Comments')}
|
|
|
|
</a>
|
2023-12-24 17:29:16 +00:00
|
|
|
<Show when={author().stat}>
|
|
|
|
<span class="view-switcher__counter">{author().stat.commented}</span>
|
|
|
|
</Show>
|
2023-10-16 10:31:10 +00:00
|
|
|
</li>
|
|
|
|
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}>
|
|
|
|
<a
|
|
|
|
onClick={() => checkBioHeight()}
|
|
|
|
href={getPagePath(router, 'authorAbout', { slug: props.authorSlug })}
|
|
|
|
>
|
|
|
|
{t('Profile')}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class={clsx('col-md-8', styles.additionalControls)}>
|
2023-12-27 23:35:43 +00:00
|
|
|
<Show when={props.author?.stat?.rating || props.author?.stat?.rating === 0}>
|
2023-12-27 23:14:33 +00:00
|
|
|
<div class={styles.ratingContainer}>
|
2023-12-28 00:30:09 +00:00
|
|
|
{t('All posts rating')}
|
2023-12-27 23:35:43 +00:00
|
|
|
<AuthorShoutsRating author={props.author} class={styles.ratingControl} />
|
2023-12-27 23:14:33 +00:00
|
|
|
</div>
|
|
|
|
</Show>
|
2023-10-16 10:31:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</Show>
|
2023-02-17 09:21:02 +00:00
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-05-04 19:57:02 +00:00
|
|
|
<Switch>
|
2023-10-14 11:39:24 +00:00
|
|
|
<Match when={getPage().route === 'authorAbout'}>
|
2023-02-17 09:21:02 +00:00
|
|
|
<div class="wide-container">
|
2023-09-06 22:58:54 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-20 col-lg-18">
|
|
|
|
<div
|
2023-09-18 16:33:22 +00:00
|
|
|
ref={(el) => (bioWrapperRef.current = el)}
|
2023-09-06 22:58:54 +00:00
|
|
|
class={styles.longBio}
|
|
|
|
classList={{ [styles.longBioExpanded]: isBioExpanded() }}
|
|
|
|
>
|
2023-09-15 09:30:50 +00:00
|
|
|
<div ref={(el) => (bioContainerRef.current = el)} innerHTML={author().about} />
|
2023-09-06 22:58:54 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<Show when={showExpandBioControl()}>
|
|
|
|
<button
|
|
|
|
class={clsx('button button--subscribe-topic', styles.longBioExpandedControl)}
|
|
|
|
onClick={() => setIsBioExpanded(!isBioExpanded())}
|
|
|
|
>
|
|
|
|
{t('Show more')}
|
|
|
|
</button>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-17 09:21:02 +00:00
|
|
|
</div>
|
|
|
|
</Match>
|
2023-10-14 11:39:24 +00:00
|
|
|
<Match when={getPage().route === 'authorComments'}>
|
2023-02-17 09:21:02 +00:00
|
|
|
<div class="wide-container">
|
2023-05-17 21:10:15 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-20 col-lg-18">
|
|
|
|
<ul class={stylesArticle.comments}>
|
|
|
|
<For each={commented()}>
|
|
|
|
{(comment) => <Comment comment={comment} class={styles.comment} showArticleLink />}
|
|
|
|
</For>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-17 09:21:02 +00:00
|
|
|
</div>
|
|
|
|
</Match>
|
2023-10-14 11:39:24 +00:00
|
|
|
<Match when={getPage().route === 'author'}>
|
2023-08-27 21:21:40 +00:00
|
|
|
<Show when={sortedArticles().length === 1}>
|
2023-10-10 19:45:35 +00:00
|
|
|
<Row1 article={sortedArticles()[0]} noauthor={true} nodate={true} />
|
2023-08-27 21:21:40 +00:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
<Show when={sortedArticles().length === 2}>
|
2023-10-10 19:45:35 +00:00
|
|
|
<Row2 articles={sortedArticles()} isEqual={true} noauthor={true} nodate={true} />
|
2023-08-27 21:21:40 +00:00
|
|
|
</Show>
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-08-27 21:21:40 +00:00
|
|
|
<Show when={sortedArticles().length === 3}>
|
2023-10-10 19:45:35 +00:00
|
|
|
<Row3 articles={sortedArticles()} noauthor={true} nodate={true} />
|
2023-08-27 21:21:40 +00:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
<Show when={sortedArticles().length > 3}>
|
2023-10-10 19:45:35 +00:00
|
|
|
<Row1 article={sortedArticles()[0]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={sortedArticles().slice(1, 3)} isEqual={true} noauthor={true} />
|
|
|
|
<Row1 article={sortedArticles()[3]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={sortedArticles().slice(4, 6)} isEqual={true} noauthor={true} />
|
|
|
|
<Row1 article={sortedArticles()[6]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={sortedArticles().slice(7, 9)} isEqual={true} noauthor={true} />
|
2023-08-27 21:21:40 +00:00
|
|
|
|
2023-10-14 11:39:24 +00:00
|
|
|
<For each={pages()}>
|
|
|
|
{(page) => (
|
2023-08-27 21:21:40 +00:00
|
|
|
<>
|
2023-10-14 11:39:24 +00:00
|
|
|
<Row1 article={page[0]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={page.slice(1, 3)} isEqual={true} noauthor={true} />
|
|
|
|
<Row1 article={page[3]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={page.slice(4, 6)} isEqual={true} noauthor={true} />
|
|
|
|
<Row1 article={page[6]} noauthor={true} nodate={true} />
|
|
|
|
<Row2 articles={page.slice(7, 9)} isEqual={true} noauthor={true} />
|
2023-08-27 21:21:40 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</Show>
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
<Show when={isLoadMoreButtonVisible()}>
|
|
|
|
<p class="load-more-container">
|
|
|
|
<button class="button" onClick={loadMore}>
|
|
|
|
{t('Load more')}
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</Show>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|