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(
on(
feedByAuthor,
(byAuthor) => {
const feed = byAuthor[props.authorSlug] as Shout[] const feed = byAuthor[props.authorSlug] as Shout[]
if (!feed) return if (!feed) return
setSortedFeed(feed) 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,8 +264,11 @@ export const AuthorView = (props: AuthorViewProps) => {
</div> </div>
</Show> </Show>
<LoadMoreWrapper
<LoadMoreWrapper loadFunction={loadMoreComments} pageSize={COMMENTS_PER_PAGE} hidden={loadMoreCommentsHidden()}> loadFunction={loadMoreComments}
pageSize={COMMENTS_PER_PAGE}
hidden={loadMoreCommentsHidden()}
>
<div class="wide-container"> <div class="wide-container">
<div class="row"> <div class="row">
<div class="col-md-20 col-lg-18"> <div class="col-md-20 col-lg-18">
@ -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 />}>