feat: router/author/slug with err_ in console , and Placeholder handle undefinde in slug for users with empty slug

This commit is contained in:
Stepan Vladovskiy 2024-09-14 16:30:47 +00:00
parent d003df96f2
commit bef13a9bde
3 changed files with 24 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.devcontainer .devcontainer
.pnpm-store
dist/ dist/
node_modules/ node_modules/
npm-debug.log* npm-debug.log*

View File

@ -89,7 +89,19 @@ export const Placeholder = (props: PlaceholderProps) => {
const { t } = useLocalize() const { t } = useLocalize()
const { session } = useSession() const { session } = useSession()
const placeholderData = createMemo(() => data[props.type]) // dufok + mem for placeholder data without a fallback, it will be `undefined` if not found
const placeholderData = createMemo(() => {
const dataForType = data[props.type];
if (!dataForType) {
console.warn(`No placeholder data found for type: ${props.type}`);
}
return dataForType; // No fallback to ensure it is empty when data is missing
});
// Return null if no placeholder data is found
if (!placeholderData()) {
return null;
}
return ( return (
<div <div
@ -100,17 +112,17 @@ export const Placeholder = (props: PlaceholderProps) => {
)} )}
> >
<div class={styles.placeholderCover}> <div class={styles.placeholderCover}>
<img src={`/${placeholderData().image}`} alt={placeholderData().header} /> <img src={`/${placeholderData()?.image}`} alt={placeholderData()?.header} />
</div> </div>
<div class={styles.placeholderContent}> <div class={styles.placeholderContent}>
<div> <div>
<h3 innerHTML={t(placeholderData().header)} /> <h3 innerHTML={t(placeholderData()?.header)} />
<p innerHTML={t(placeholderData().text)} /> <p innerHTML={t(placeholderData()?.text)} />
</div> </div>
<Show when={placeholderData().profileLinks}> <Show when={placeholderData()?.profileLinks}>
<div class={styles.bottomLinks}> <div class={styles.bottomLinks}>
<For each={placeholderData().profileLinks}> <For each={placeholderData()?.profileLinks}>
{(link) => ( {(link) => (
<a href={link.href}> <a href={link.href}>
<Icon name="link-white" class={styles.icon} /> <Icon name="link-white" class={styles.icon} />
@ -133,7 +145,7 @@ export const Placeholder = (props: PlaceholderProps) => {
</a> </a>
} }
> >
<a class={styles.button} href={placeholderData().href}> <a class={styles.button} href={placeholderData()?.href}>
{t( {t(
session()?.access_token session()?.access_token
? placeholderData()?.buttonLabelAuthor || '' ? placeholderData()?.buttonLabelAuthor || ''

View File

@ -133,7 +133,10 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
) )
return ( return (
<ErrorBoundary fallback={(_err) => <FourOuFourView />}> <ErrorBoundary fallback={(_err) => {
console.error('ErrorBoundary caught an error', _err)
return <FourOuFourView />
}}>
<Suspense fallback={<Loading />}> <Suspense fallback={<Loading />}>
<PageLayout <PageLayout
title={title()} title={title()}