2024-07-13 09:36:23 +00:00
|
|
|
import { Params, RouteSectionProps, createAsync } from '@solidjs/router'
|
2024-09-16 12:57:00 +00:00
|
|
|
import { Show, createEffect, createMemo, on } from 'solid-js'
|
2024-07-21 02:17:42 +00:00
|
|
|
import { TopicsNav } from '~/components/TopicsNav'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { Expo } from '~/components/Views/Expo'
|
|
|
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
2024-09-16 12:57:00 +00:00
|
|
|
import { EXPO_LAYOUTS, SHOUTS_PER_PAGE } from '~/context/feed'
|
2024-07-04 07:51:15 +00:00
|
|
|
import { useLocalize } from '~/context/localize'
|
|
|
|
import { loadShouts } from '~/graphql/api/public'
|
2024-07-03 21:25:03 +00:00
|
|
|
import { LoadShoutsOptions, Shout } from '~/graphql/schema/core.gen'
|
|
|
|
import { LayoutType } from '~/types/common'
|
|
|
|
|
|
|
|
const fetchExpoShouts = async (layouts: string[]) => {
|
|
|
|
const result = await loadShouts({
|
|
|
|
filters: { layouts },
|
|
|
|
limit: SHOUTS_PER_PAGE,
|
|
|
|
offset: 0
|
|
|
|
} as LoadShoutsOptions)
|
|
|
|
return result || []
|
|
|
|
}
|
|
|
|
|
|
|
|
export const route = {
|
|
|
|
load: async ({ params }: { params: Params }) => {
|
2024-09-16 12:57:00 +00:00
|
|
|
const layouts = params.layout ? [params.layout] : EXPO_LAYOUTS
|
2024-07-03 21:25:03 +00:00
|
|
|
const shoutsLoader = await fetchExpoShouts(layouts)
|
|
|
|
return (await shoutsLoader()) as Shout[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 17:23:07 +00:00
|
|
|
export default (props: RouteSectionProps<Shout[]>) => {
|
2024-07-03 21:25:03 +00:00
|
|
|
const { t } = useLocalize()
|
|
|
|
const shouts = createAsync(
|
|
|
|
async () =>
|
2024-09-16 12:57:00 +00:00
|
|
|
props.data || (await fetchExpoShouts(props.params.layout ? [props.params.layout] : EXPO_LAYOUTS))
|
2024-07-03 21:25:03 +00:00
|
|
|
)
|
2024-07-13 09:36:23 +00:00
|
|
|
const layout = createMemo(() => props.params.layout)
|
2024-07-03 21:25:03 +00:00
|
|
|
const title = createMemo(() => {
|
|
|
|
switch (layout()) {
|
|
|
|
case 'audio': {
|
|
|
|
return t('Audio')
|
|
|
|
}
|
|
|
|
case 'video': {
|
|
|
|
return t('Video')
|
|
|
|
}
|
|
|
|
case 'image': {
|
|
|
|
return t('Artworks')
|
|
|
|
}
|
|
|
|
case 'literature': {
|
|
|
|
return t('Literature')
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return t('Art')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
createEffect(on(title, (ttl) => (document.title = ttl), { defer: true }))
|
|
|
|
|
|
|
|
return (
|
2024-07-05 08:11:57 +00:00
|
|
|
<PageLayout withPadding={true} zeroBottomPadding={true} title={`${t('Discours')} :: ${title()}`}>
|
2024-07-09 09:13:13 +00:00
|
|
|
<TopicsNav />
|
2024-09-16 12:57:00 +00:00
|
|
|
<Show when={shouts()} keyed>
|
|
|
|
{(sss) => <Expo shouts={sss} layout={layout() as LayoutType} />}
|
|
|
|
</Show>
|
2024-07-03 21:25:03 +00:00
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|