fmt
This commit is contained in:
parent
090295327f
commit
0698900f8d
|
@ -27,15 +27,21 @@ export const FullTopic = (props: Props) => {
|
|||
const [followed, setFollowed] = createSignal()
|
||||
const [title, setTitle] = createSignal('')
|
||||
|
||||
createEffect(on(() => props.topic, (tpc) => {
|
||||
if (!tpc) return
|
||||
/* FIXME: use title translation*/
|
||||
setTitle((_) => tpc?.title || '')
|
||||
return `#${capitalize(
|
||||
lang() === 'en' ? tpc.slug.replace(/-/, ' ') : tpc.title || tpc.slug.replace(/-/, ' '),
|
||||
true
|
||||
)}`
|
||||
}, {} ))
|
||||
createEffect(
|
||||
on(
|
||||
() => props.topic,
|
||||
(tpc) => {
|
||||
if (!tpc) return
|
||||
/* FIXME: use title translation*/
|
||||
setTitle((_) => tpc?.title || '')
|
||||
return `#${capitalize(
|
||||
lang() === 'en' ? tpc.slug.replace(/-/, ' ') : tpc.title || tpc.slug.replace(/-/, ' '),
|
||||
true
|
||||
)}`
|
||||
},
|
||||
{}
|
||||
)
|
||||
)
|
||||
|
||||
createEffect(() => {
|
||||
if (follows?.topics?.length !== 0) {
|
||||
|
|
|
@ -34,9 +34,11 @@ export const ABC = {
|
|||
export const AllAuthors = (props: Props) => {
|
||||
const { t, lang } = useLocalize()
|
||||
const alphabet = createMemo(() => ABC[lang()] || ABC['ru'])
|
||||
const [searchParams, ] = useSearchParams<{ by?: string }>()
|
||||
const [searchParams] = useSearchParams<{ by?: string }>()
|
||||
const { authorsSorted, setAuthorsSort, loadAuthors } = useAuthors()
|
||||
const authors = createMemo(() => (searchParams.by || searchParams.by === 'name') ? props.authors : authorsSorted())
|
||||
const authors = createMemo(() =>
|
||||
searchParams.by || searchParams.by === 'name' ? props.authors : authorsSorted()
|
||||
)
|
||||
const [loading, setLoading] = createSignal<boolean>(false)
|
||||
|
||||
// filter
|
||||
|
@ -207,7 +209,14 @@ export const AllAuthors = (props: Props) => {
|
|||
<div class="row">
|
||||
<div class="col-lg-20 col-xl-18">
|
||||
<div class={stylesAuthorList.action}>
|
||||
<Show when={searchParams.by !== 'name' && !searchParams.by && !loading() && ((authorsSorted?.() || []).length || 0) > 0}>
|
||||
<Show
|
||||
when={
|
||||
searchParams.by !== 'name' &&
|
||||
!searchParams.by &&
|
||||
!loading() &&
|
||||
((authorsSorted?.() || []).length || 0) > 0
|
||||
}
|
||||
>
|
||||
<Button value={t('Load more')} onClick={loadMoreAuthors} aria-live="polite" />
|
||||
</Show>
|
||||
<Show when={loading()}>
|
||||
|
|
|
@ -219,9 +219,9 @@ export const AuthorView = (props: AuthorViewProps) => {
|
|||
</Show>
|
||||
|
||||
<Show when={Array.isArray(props.shouts) && props.shouts.length > 0}>
|
||||
<For each={props.shouts.filter((_, i) => i % 3 === 0)}>
|
||||
<For each={props.shouts.filter((_, i) => i % 3 === 0)}>
|
||||
{(_shout, index) => {
|
||||
const articles = props.shouts.slice(index() * 3, index() * 3 + 3);
|
||||
const articles = props.shouts.slice(index() * 3, index() * 3 + 3)
|
||||
return (
|
||||
<>
|
||||
<Switch>
|
||||
|
@ -236,7 +236,7 @@ export const AuthorView = (props: AuthorViewProps) => {
|
|||
</Match>
|
||||
</Switch>
|
||||
</>
|
||||
);
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</Show>
|
||||
|
|
|
@ -62,7 +62,7 @@ export const ProfileSettings = () => {
|
|||
const { showConfirm } = useUI()
|
||||
const [clearAbout, setClearAbout] = createSignal(false)
|
||||
const { showModal, hideModal } = useUI()
|
||||
const [loading, setLoading] = createSignal(true);
|
||||
const [loading, setLoading] = createSignal(true)
|
||||
|
||||
// Используем createEffect для отслеживания данных сессии и инициализации формы
|
||||
createEffect(() => {
|
||||
|
@ -72,11 +72,11 @@ export const ProfileSettings = () => {
|
|||
if (profileData) {
|
||||
setPrevForm(profileData)
|
||||
const soc: string[] = filterNulls(profileData.links || [])
|
||||
setSocial(soc);
|
||||
setSocial(soc)
|
||||
setForm(profileData) // Инициализируем форму с данными профиля
|
||||
setIsFormInitialized(true)
|
||||
}
|
||||
setLoading(false) // Отключаем загрузку только после инициализации данных
|
||||
setLoading(false) // Отключаем загрузку только после инициализации данных
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -46,7 +46,10 @@ export const TopicView = (props: Props) => {
|
|||
|
||||
// TODO: filter + sort
|
||||
const [sortedFeed, setSortedFeed] = createSignal([] as Shout[])
|
||||
createEffect(on(([feedByTopic, () => props.topicSlug, topicEntities]), ([feed, slug, ttt]) => {
|
||||
createEffect(
|
||||
on(
|
||||
[feedByTopic, () => props.topicSlug, topicEntities],
|
||||
([feed, slug, ttt]) => {
|
||||
if (Object.values(ttt).length === 0) return
|
||||
const sss = (feed[slug] || []) as Shout[]
|
||||
sss && setSortedFeed(sss)
|
||||
|
@ -54,7 +57,10 @@ export const TopicView = (props: Props) => {
|
|||
const tpc = ttt[slug]
|
||||
console.debug('topics loaded', ttt)
|
||||
tpc && setTopic(tpc)
|
||||
}, {}))
|
||||
},
|
||||
{}
|
||||
)
|
||||
)
|
||||
|
||||
const loadTopicFollowers = async () => {
|
||||
const topicFollowersFetcher = loadFollowersByTopic(props.topicSlug)
|
||||
|
@ -101,14 +107,20 @@ export const TopicView = (props: Props) => {
|
|||
}
|
||||
|
||||
// второй этап начальной загрузки данных
|
||||
createEffect(on(topic, (tpc) => {
|
||||
createEffect(
|
||||
on(
|
||||
topic,
|
||||
(tpc) => {
|
||||
console.debug('topic loaded', tpc)
|
||||
if (!tpc) return
|
||||
loadFavoriteTopArticles()
|
||||
loadReactedTopMonthArticles()
|
||||
loadTopicAuthors()
|
||||
loadTopicFollowers()
|
||||
}, { defer: true }))
|
||||
},
|
||||
{ defer: true }
|
||||
)
|
||||
)
|
||||
|
||||
// дозагрузка
|
||||
const loadMore = async () => {
|
||||
|
@ -138,7 +150,9 @@ export const TopicView = (props: Props) => {
|
|||
return (
|
||||
<div class={styles.topicPage}>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Show when={topic()}><FullTopic topic={topic() as Topic} followers={followers()} authors={topicAuthors()} /></Show>
|
||||
<Show when={topic()}>
|
||||
<FullTopic topic={topic() as Topic} followers={followers()} authors={topicAuthors()} />
|
||||
</Show>
|
||||
<div class="wide-container">
|
||||
<div class={clsx(styles.groupControls, 'row group__controls')}>
|
||||
<div class="col-md-16">
|
||||
|
@ -218,26 +232,32 @@ export const TopicView = (props: Props) => {
|
|||
</Show>
|
||||
|
||||
<LoadMoreWrapper loadFunction={loadMore} pageSize={SHOUTS_PER_PAGE}>
|
||||
<For each={sortedFeed().slice(19).filter((_, i) => i % 3 === 0)}>
|
||||
{(_shout, index) => {
|
||||
const articles = sortedFeed().slice(19).slice(index() * 3, index() * 3 + 3);
|
||||
return (
|
||||
<>
|
||||
<Switch>
|
||||
<Match when={articles.length === 1}>
|
||||
<Row1 article={articles[0]} noauthor={true} nodate={true} />
|
||||
</Match>
|
||||
<Match when={articles.length === 2}>
|
||||
<Row2 articles={articles} noauthor={true} nodate={true} isEqual={true} />
|
||||
</Match>
|
||||
<Match when={articles.length === 3}>
|
||||
<Row3 articles={articles} noauthor={true} nodate={true} />
|
||||
</Match>
|
||||
</Switch>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
<For
|
||||
each={sortedFeed()
|
||||
.slice(19)
|
||||
.filter((_, i) => i % 3 === 0)}
|
||||
>
|
||||
{(_shout, index) => {
|
||||
const articles = sortedFeed()
|
||||
.slice(19)
|
||||
.slice(index() * 3, index() * 3 + 3)
|
||||
return (
|
||||
<>
|
||||
<Switch>
|
||||
<Match when={articles.length === 1}>
|
||||
<Row1 article={articles[0]} noauthor={true} nodate={true} />
|
||||
</Match>
|
||||
<Match when={articles.length === 2}>
|
||||
<Row2 articles={articles} noauthor={true} nodate={true} isEqual={true} />
|
||||
</Match>
|
||||
<Match when={articles.length === 3}>
|
||||
<Row3 articles={articles} noauthor={true} nodate={true} />
|
||||
</Match>
|
||||
</Switch>
|
||||
</>
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</LoadMoreWrapper>
|
||||
</Suspense>
|
||||
</div>
|
||||
|
|
|
@ -38,12 +38,13 @@ export const LoadMoreWrapper = (props: LoadMoreProps) => {
|
|||
const newItems = await props.loadFunction(offset())
|
||||
if (!Array.isArray(newItems)) return
|
||||
if (newItems.length === 0) setIsLoadMoreButtonVisible(false)
|
||||
else setItems(
|
||||
(prev) =>
|
||||
Array.from(new Set([...prev, ...newItems])).sort(
|
||||
byCreated as SortFunction<unknown>
|
||||
) as LoadMoreItems
|
||||
)
|
||||
else
|
||||
setItems(
|
||||
(prev) =>
|
||||
Array.from(new Set([...prev, ...newItems])).sort(
|
||||
byCreated as SortFunction<unknown>
|
||||
) as LoadMoreItems
|
||||
)
|
||||
setIsLoading(false)
|
||||
restoreScrollPosition()
|
||||
}
|
||||
|
|
|
@ -57,11 +57,13 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
|
|||
const { addAuthor, authorsEntities } = useAuthors()
|
||||
const [author, setAuthor] = createSignal<Author | undefined>(undefined)
|
||||
createEffect(
|
||||
on(author,
|
||||
on(
|
||||
author,
|
||||
async (profile) => {
|
||||
// update only if no profile loaded
|
||||
if (!profile) {
|
||||
const loadedAuthor = authorsEntities()[props.params.slug] || (await fetchAuthor(props.params.slug))
|
||||
const loadedAuthor =
|
||||
authorsEntities()[props.params.slug] || (await fetchAuthor(props.params.slug))
|
||||
if (loadedAuthor) {
|
||||
addAuthor(loadedAuthor)
|
||||
setAuthor(loadedAuthor)
|
||||
|
@ -107,7 +109,7 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
|
|||
const { addFeed, feedByAuthor } = useFeed()
|
||||
const [loadMoreHidden, setLoadMoreHidden] = createSignal(true)
|
||||
const authorShouts = createAsync(async () => {
|
||||
const sss: Shout[] = props.data.articles as Shout[] || feedByAuthor()[props.params.slug] || []
|
||||
const sss: Shout[] = (props.data.articles as Shout[]) || feedByAuthor()[props.params.slug] || []
|
||||
const result = sss || (await fetchAuthorShouts(props.params.slug, 0))
|
||||
if (!result) setLoadMoreHidden(true)
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue
Block a user