2023-02-13 01:55:52 +01:00
|
|
|
import React, { ComponentType, FC } from 'react';
|
|
|
|
import dynamic from 'next/dynamic';
|
2023-05-23 03:56:44 +02:00
|
|
|
import { TabsProps } from 'antd';
|
2023-03-13 05:40:36 +01:00
|
|
|
import { ErrorBoundary } from 'react-error-boundary';
|
2023-05-12 16:00:04 +02:00
|
|
|
import classNames from 'classnames';
|
2023-02-13 01:55:52 +01:00
|
|
|
import { SocialLink } from '../../../interfaces/social-link.model';
|
|
|
|
import styles from './Content.module.scss';
|
|
|
|
import { CustomPageContent } from '../CustomPageContent/CustomPageContent';
|
|
|
|
import { ContentHeader } from '../../common/ContentHeader/ContentHeader';
|
2023-03-13 05:40:36 +01:00
|
|
|
import { ComponentError } from '../ComponentError/ComponentError';
|
2023-02-13 01:55:52 +01:00
|
|
|
|
|
|
|
export type MobileContentProps = {
|
|
|
|
name: string;
|
|
|
|
summary: string;
|
|
|
|
tags: string[];
|
|
|
|
socialHandles: SocialLink[];
|
|
|
|
extraPageContent: string;
|
|
|
|
setShowFollowModal: (show: boolean) => void;
|
|
|
|
supportFediverseFeatures: boolean;
|
2023-05-12 16:00:04 +02:00
|
|
|
online: boolean;
|
2023-02-13 01:55:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// lazy loaded components
|
|
|
|
|
|
|
|
const Tabs: ComponentType<TabsProps> = dynamic(() => import('antd').then(mod => mod.Tabs), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const FollowerCollection = dynamic(
|
|
|
|
() =>
|
|
|
|
import('../followers/FollowerCollection/FollowerCollection').then(
|
|
|
|
mod => mod.FollowerCollection,
|
|
|
|
),
|
|
|
|
{
|
|
|
|
ssr: false,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-03-13 05:40:36 +01:00
|
|
|
const ComponentErrorFallback = ({ error, resetErrorBoundary }) => (
|
|
|
|
<ComponentError
|
|
|
|
message={error}
|
|
|
|
componentName="MobileContent"
|
|
|
|
retryFunction={resetErrorBoundary}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2023-02-13 01:55:52 +01:00
|
|
|
export const MobileContent: FC<MobileContentProps> = ({
|
|
|
|
name,
|
|
|
|
summary,
|
|
|
|
tags,
|
|
|
|
socialHandles,
|
|
|
|
extraPageContent,
|
|
|
|
setShowFollowModal,
|
|
|
|
supportFediverseFeatures,
|
2023-05-12 16:00:04 +02:00
|
|
|
online,
|
2023-02-13 01:55:52 +01:00
|
|
|
}) => {
|
|
|
|
const aboutTabContent = (
|
|
|
|
<>
|
2023-02-23 03:39:37 +01:00
|
|
|
<ContentHeader name={name} summary={summary} tags={tags} links={socialHandles} logo="/logo" />
|
2023-02-28 02:39:45 +01:00
|
|
|
{!!extraPageContent && (
|
|
|
|
<div className={styles.bottomPageContentContainer}>
|
|
|
|
<CustomPageContent content={extraPageContent} />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-02-13 01:55:52 +01:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
const followersTabContent = (
|
2023-02-22 01:15:09 +01:00
|
|
|
<div className={styles.bottomPageContentContainer}>
|
|
|
|
<FollowerCollection name={name} onFollowButtonClick={() => setShowFollowModal(true)} />
|
|
|
|
</div>
|
2023-02-13 01:55:52 +01:00
|
|
|
);
|
|
|
|
|
2023-02-22 01:15:09 +01:00
|
|
|
const items = [];
|
2023-05-23 03:56:44 +02:00
|
|
|
|
|
|
|
items.push({ label: 'About', key: '0', children: aboutTabContent });
|
2023-02-22 01:15:09 +01:00
|
|
|
if (supportFediverseFeatures) {
|
2023-05-23 03:56:44 +02:00
|
|
|
items.push({ label: 'Followers', key: '1', children: followersTabContent });
|
2023-02-22 01:15:09 +01:00
|
|
|
}
|
2023-02-13 01:55:52 +01:00
|
|
|
|
|
|
|
return (
|
2023-03-13 05:40:36 +01:00
|
|
|
<ErrorBoundary
|
|
|
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
|
|
fallbackRender={({ error, resetErrorBoundary }) => (
|
|
|
|
<ComponentErrorFallback error={error} resetErrorBoundary={resetErrorBoundary} />
|
2023-02-22 01:15:09 +01:00
|
|
|
)}
|
2023-03-13 05:40:36 +01:00
|
|
|
>
|
2023-05-18 21:13:26 +02:00
|
|
|
{items.length > 1 ? (
|
|
|
|
<div className={classNames([styles.lowerSectionMobileTabbed, online && styles.online])}>
|
|
|
|
<Tabs defaultActiveKey="0" items={items} />
|
|
|
|
</div>
|
|
|
|
) : (
|
2023-05-25 17:20:03 +02:00
|
|
|
<div>{aboutTabContent}</div>
|
2023-05-18 21:13:26 +02:00
|
|
|
)}
|
2023-03-13 05:40:36 +01:00
|
|
|
</ErrorBoundary>
|
2023-02-13 01:55:52 +01:00
|
|
|
);
|
|
|
|
};
|