This commit is contained in:
Untone 2024-09-03 13:29:01 +03:00
parent 7714977391
commit 30ff30d099
3 changed files with 55 additions and 35 deletions

View File

@ -110,7 +110,7 @@ export const AuthorView = (props: AuthorViewProps) => {
}) })
const handleDeleteComment = (id: number) => { const handleDeleteComment = (id: number) => {
setCommented((prev) => (prev||[]).filter((comment) => comment.id !== id)) setCommented((prev) => (prev || []).filter((comment) => comment.id !== id))
} }
const TabNavigator = () => ( const TabNavigator = () => (
@ -154,11 +154,17 @@ export const AuthorView = (props: AuthorViewProps) => {
} }
// fx to update author's feed // fx to update author's feed
createEffect(on(feedByAuthor, (byAuthor) => { createEffect(
const feed = byAuthor[props.authorSlug] as Shout[] on(
if (!feed) return feedByAuthor,
setSortedFeed(feed) (byAuthor) => {
},{})) const feed = byAuthor[props.authorSlug] as Shout[]
if (!feed) return
setSortedFeed(feed)
},
{}
)
)
const [loadMoreCommentsHidden, setLoadMoreCommentsHidden] = createSignal(false) const [loadMoreCommentsHidden, setLoadMoreCommentsHidden] = createSignal(false)
const { commentsByAuthor, addReactions } = useReactions() const { commentsByAuthor, addReactions } = useReactions()
@ -176,14 +182,27 @@ export const AuthorView = (props: AuthorViewProps) => {
}) })
const result = await authorCommentsFetcher() const result = await authorCommentsFetcher()
result && addReactions(result) result && addReactions(result)
result && setCommented((prev) => [...new Set([...(prev||[]), ...result])]) result && setCommented((prev) => [...new Set([...(prev || []), ...result])])
restoreScrollPosition() restoreScrollPosition()
return result as LoadMoreItems return result as LoadMoreItems
} }
createEffect(() => setCurrentTab(params.tab)) createEffect(() => setCurrentTab(params.tab))
createEffect(on([author, commented], ([a, ccc]) => a && setLoadMoreCommentsHidden(ccc?.length === a.stat?.comments), {})) createEffect(
createEffect(on([author, feedByAuthor], ([a, feed]) => a && feed[props.authorSlug] && setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts), {})) on(
[author, commented],
([a, ccc]) => a && setLoadMoreCommentsHidden(ccc?.length === a.stat?.comments),
{}
)
)
createEffect(
on(
[author, feedByAuthor],
([a, feed]) =>
a && feed[props.authorSlug] && setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts),
{}
)
)
return ( return (
<div class={styles.authorPage}> <div class={styles.authorPage}>
@ -245,26 +264,29 @@ export const AuthorView = (props: AuthorViewProps) => {
</div> </div>
</Show> </Show>
<LoadMoreWrapper
<LoadMoreWrapper loadFunction={loadMoreComments} pageSize={COMMENTS_PER_PAGE} hidden={loadMoreCommentsHidden()}> loadFunction={loadMoreComments}
<div class="wide-container"> pageSize={COMMENTS_PER_PAGE}
<div class="row"> hidden={loadMoreCommentsHidden()}
<div class="col-md-20 col-lg-18"> >
<ul class={stylesArticle.comments}> <div class="wide-container">
<For each={commented()?.sort(byCreated).reverse()}> <div class="row">
{(comment) => ( <div class="col-md-20 col-lg-18">
<Comment <ul class={stylesArticle.comments}>
comment={comment} <For each={commented()?.sort(byCreated).reverse()}>
class={styles.comment} {(comment) => (
showArticleLink={true} <Comment
onDelete={(id) => handleDeleteComment(id)} comment={comment}
/> class={styles.comment}
)} showArticleLink={true}
</For> onDelete={(id) => handleDeleteComment(id)}
</ul> />
)}
</For>
</ul>
</div>
</div> </div>
</div> </div>
</div>
</LoadMoreWrapper> </LoadMoreWrapper>
</Match> </Match>
@ -276,13 +298,9 @@ export const AuthorView = (props: AuthorViewProps) => {
</Show> </Show>
<LoadMoreWrapper loadFunction={loadMore} pageSize={SHOUTS_PER_PAGE} hidden={loadMoreHidden()}> <LoadMoreWrapper loadFunction={loadMore} pageSize={SHOUTS_PER_PAGE} hidden={loadMoreHidden()}>
<For <For each={sortedFeed().filter((_, i) => i % 3 === 0)}>
each={sortedFeed()
.filter((_, i) => i % 3 === 0)}
>
{(_shout, index) => { {(_shout, index) => {
const articles = sortedFeed() const articles = sortedFeed().slice(index() * 3, index() * 3 + 3)
.slice(index() * 3, index() * 3 + 3)
return ( return (
<> <>
<Switch> <Switch>

View File

@ -68,7 +68,7 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
const newCommentsByAuthor = Object.fromEntries( const newCommentsByAuthor = Object.fromEntries(
Object.entries(newReactionsByAuthor).map(([authorId, reactions]) => [ Object.entries(newReactionsByAuthor).map(([authorId, reactions]) => [
authorId, authorId,
reactions.filter((x: Reaction) => x.kind === ReactionKind.Comment), reactions.filter((x: Reaction) => x.kind === ReactionKind.Comment)
]) ])
) )

View File

@ -105,7 +105,9 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
) )
// author's shouts // author's shouts
const authorShouts = createAsync(async () => props.data.articles as Shout[] || await fetchAuthorShouts(props.params.slug, 0)) const authorShouts = createAsync(
async () => (props.data.articles as Shout[]) || (await fetchAuthorShouts(props.params.slug, 0))
)
return ( return (
<ErrorBoundary fallback={(_err) => <FourOuFourView />}> <ErrorBoundary fallback={(_err) => <FourOuFourView />}>