Merge branch 'dev' into nobootstrap
This commit is contained in:
commit
7149525aeb
|
@ -147,17 +147,31 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
const [loadMoreHidden, setLoadMoreHidden] = createSignal(false)
|
const [loadMoreHidden, setLoadMoreHidden] = createSignal(false)
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
saveScrollPosition()
|
saveScrollPosition()
|
||||||
const authorhoutsFetcher = loadShouts({
|
const authorShoutsFetcher = loadShouts({
|
||||||
filters: { author: props.authorSlug },
|
filters: { author: props.authorSlug },
|
||||||
limit: SHOUTS_PER_PAGE,
|
limit: SHOUTS_PER_PAGE,
|
||||||
offset: feedByAuthor()?.[props.authorSlug]?.length || 0
|
offset: feedByAuthor()?.[props.authorSlug]?.length || 0
|
||||||
})
|
})
|
||||||
const result = await authorhoutsFetcher()
|
const result = await authorShoutsFetcher()
|
||||||
result && addFeed(result)
|
if (result) {
|
||||||
|
addFeed(result)
|
||||||
|
}
|
||||||
restoreScrollPosition()
|
restoreScrollPosition()
|
||||||
return result as LoadMoreItems
|
return result as LoadMoreItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to chunk the sortedFeed into arrays of 3 shouts each
|
||||||
|
const chunkArray = (array: Shout[], chunkSize: number): Shout[][] => {
|
||||||
|
const chunks: Shout[][] = []
|
||||||
|
for (let i = 0; i < array.length; i += chunkSize) {
|
||||||
|
chunks.push(array.slice(i, i + chunkSize))
|
||||||
|
}
|
||||||
|
return chunks
|
||||||
|
}
|
||||||
|
|
||||||
|
// Memoize the chunked feed
|
||||||
|
const feedChunks = createMemo(() => chunkArray(sortedFeed(), 3))
|
||||||
|
|
||||||
// fx to update author's feed
|
// fx to update author's feed
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
|
@ -188,29 +202,48 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
offset: commentsByAuthor()[aid]?.length || 0
|
offset: commentsByAuthor()[aid]?.length || 0
|
||||||
})
|
})
|
||||||
const result = await authorCommentsFetcher()
|
const result = await authorCommentsFetcher()
|
||||||
result && addShoutReactions(result)
|
if (result) {
|
||||||
|
addShoutReactions(result)
|
||||||
|
}
|
||||||
restoreScrollPosition()
|
restoreScrollPosition()
|
||||||
return result as LoadMoreItems
|
return result as LoadMoreItems
|
||||||
}
|
}
|
||||||
|
|
||||||
createEffect(() => setCurrentTab(params.tab))
|
createEffect(() => setCurrentTab(params.tab))
|
||||||
|
|
||||||
|
// Update commented when author or commentsByAuthor changes
|
||||||
createEffect(
|
createEffect(
|
||||||
on([author, commentsByAuthor], ([a, ccc]) => a && ccc && ccc[a.id] && setCommented(ccc[a.id]), {})
|
on(
|
||||||
|
[author, commentsByAuthor],
|
||||||
|
([a, ccc]) => {
|
||||||
|
if (a && ccc && ccc[a.id]) {
|
||||||
|
setCommented(ccc[a.id])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
[author, commented],
|
[author, commented],
|
||||||
([a, ccc]) => a && ccc && setLoadMoreCommentsHidden((ccc || []).length === a.stat?.comments)
|
([a, ccc]) => {
|
||||||
|
if (a && ccc) {
|
||||||
|
setLoadMoreCommentsHidden((ccc || []).length === a.stat?.comments)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
[author, feedByAuthor],
|
[author, feedByAuthor],
|
||||||
([a, feed]) =>
|
([a, feed]) => {
|
||||||
a && feed[props.authorSlug] && setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts),
|
if (a && feed[props.authorSlug]) {
|
||||||
|
setLoadMoreHidden(feed[props.authorSlug]?.length === a.stat?.shouts)
|
||||||
|
}
|
||||||
|
},
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -230,7 +263,7 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
<div class={clsx(styles.groupControls, 'row')}>
|
<div class={clsx(styles.groupControls, 'row')}>
|
||||||
<TabNavigator />
|
<TabNavigator />
|
||||||
<div class={clsx('col-md-8', styles.additionalControls)}>
|
<div class={clsx('col-md-8', styles.additionalControls)}>
|
||||||
<Show when={author()?.stat?.rating || author()?.stat?.rating === 0}>
|
<Show when={typeof author()?.stat?.rating === 'number'}>
|
||||||
<div class={styles.ratingContainer}>
|
<div class={styles.ratingContainer}>
|
||||||
{t('All posts rating')}
|
{t('All posts rating')}
|
||||||
<AuthorShoutsRating author={author() as Author} class={styles.ratingControl} />
|
<AuthorShoutsRating author={author() as Author} class={styles.ratingControl} />
|
||||||
|
@ -249,8 +282,7 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
<div class="col-md-20 col-lg-18">
|
<div class="col-md-20 col-lg-18">
|
||||||
<div
|
<div
|
||||||
ref={(el) => (bioWrapperRef = el)}
|
ref={(el) => (bioWrapperRef = el)}
|
||||||
class={styles.longBio}
|
class={clsx(styles.longBio, { [styles.longBioExpanded]: isBioExpanded() })}
|
||||||
classList={{ [styles.longBioExpanded]: isBioExpanded() }}
|
|
||||||
>
|
>
|
||||||
<div ref={(el) => (bioContainerRef = el)} innerHTML={author()?.about || ''} />
|
<div ref={(el) => (bioContainerRef = el)} innerHTML={author()?.about || ''} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -260,7 +292,7 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
class={clsx('button button--subscribe-topic', styles.longBioExpandedControl)}
|
class={clsx('button button--subscribe-topic', styles.longBioExpandedControl)}
|
||||||
onClick={() => setIsBioExpanded(!isBioExpanded())}
|
onClick={() => setIsBioExpanded(!isBioExpanded())}
|
||||||
>
|
>
|
||||||
{t('Show more')}
|
{isBioExpanded() ? t('Show less') : t('Show more')}
|
||||||
</button>
|
</button>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
@ -269,7 +301,7 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
<Match when={currentTab() === 'comments'}>
|
<Match when={currentTab() === 'comments'}>
|
||||||
<Show when={me()?.slug === props.authorSlug && !me().stat?.comments}>
|
<Show when={me()?.slug === props.authorSlug && !me()?.stat?.comments}>
|
||||||
<div class="wide-container">
|
<div class="wide-container">
|
||||||
<Placeholder type={loc?.pathname} mode="profile" />
|
<Placeholder type={loc?.pathname} mode="profile" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -302,32 +334,27 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
<Match when={!currentTab()}>
|
<Match when={!currentTab()}>
|
||||||
<Show when={me()?.slug === props.authorSlug && !me().stat?.shouts}>
|
<Show when={me()?.slug === props.authorSlug && !me()?.stat?.shouts}>
|
||||||
<div class="wide-container">
|
<div class="wide-container">
|
||||||
<Placeholder type={loc?.pathname} mode="profile" />
|
<Placeholder type={loc?.pathname} mode="profile" />
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<LoadMoreWrapper loadFunction={loadMore} pageSize={SHOUTS_PER_PAGE} hidden={loadMoreHidden()}>
|
<LoadMoreWrapper loadFunction={loadMore} pageSize={SHOUTS_PER_PAGE} hidden={loadMoreHidden()}>
|
||||||
<For each={sortedFeed().filter((_, i) => i % 3 === 0)}>
|
<For each={feedChunks()}>
|
||||||
{(_shout, index) => {
|
{(articles) => (
|
||||||
const articles = sortedFeed().slice(index() * 3, index() * 3 + 3)
|
<Switch>
|
||||||
return (
|
<Match when={articles.length === 1}>
|
||||||
<>
|
<Row1 article={articles[0]} noauthor={true} nodate={true} />
|
||||||
<Switch>
|
</Match>
|
||||||
<Match when={articles.length === 1}>
|
<Match when={articles.length === 2}>
|
||||||
<Row1 article={articles[0]} noauthor={true} nodate={true} />
|
<Row2 articles={articles} noauthor={true} nodate={true} isEqual={true} />
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={articles.length === 2}>
|
<Match when={articles.length === 3}>
|
||||||
<Row2 articles={articles} noauthor={true} nodate={true} isEqual={true} />
|
<Row3 articles={articles} noauthor={true} nodate={true} />
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={articles.length === 3}>
|
</Switch>
|
||||||
<Row3 articles={articles} noauthor={true} nodate={true} />
|
)}
|
||||||
</Match>
|
|
||||||
</Switch>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
</For>
|
</For>
|
||||||
</LoadMoreWrapper>
|
</LoadMoreWrapper>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user