reafctor: normalize component formatting (#2082)

* refactor: move/rename BanUserButton file

* refactor: move/rename Chart file

* refactor: update generic component filenames to PascalCase

* refactor: update config component filenames to PascalCase

* refactor: update AdminLayout component filename to PascalCase

* refactor: update/move VideoJS component

* chore(eslint): disable bad react/require-default-props rule

* refactor: normalize ActionButton component

* refactor: normalize ActionButtonRow component

* refactor: normalize FollowButton component

* refactor: normalize NotifyButton component

* refactor: normalize ChatActionMessage component

* refactor: normalize ChatContainer component

* refactor: normalize ChatJoinMessage component

* refactor: normalize ChatModerationActionMenu component

* refactor: normalize ChatModerationDetailsModal component

* refactor: normalize ChatModeratorNotification component

* refactor: normalize ChatSocialMessage component

* refactor: normalize ChatSystemMessage component

* refactor: normalize ChatTextField component

* refactor: normalize ChatUserBadge component

* refactor: normalize ChatUserMessage component

* refactor: normalize ContentHeader component

* refactor: normalize OwncastLogo component

* refactor: normalize UserDropdown component

* chore(eslint): modify react/function-component-definition rule

* refactor: normalize CodecSelector component

* refactor: update a bunch of functional components using eslint

* refactor: update a bunch of functional components using eslint, pt2

* refactor: update a bunch of functional components using eslint, pt3

* refactor: replace all component->component default imports with named imports

* refactor: replace all component-stories->component default imports with named imports

* refactor: remove default exports from most components

* chore(eslint): add eslint config files for the components and pages dirs

* fix: use-before-define error in ChatContainer

* Fix ChatContainer import

* Only process .tsx files in Next builds

Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
James Young
2022-09-07 09:00:28 +02:00
committed by GitHub
parent ee333ef10a
commit d1f3fffe2f
178 changed files with 1258 additions and 1227 deletions

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { RecoilRoot } from 'recoil';
import AuthModal from './AuthModal';
import { AuthModal } from './AuthModal';
const Example = () => (
<div>

View File

@@ -1,12 +1,13 @@
import { Tabs } from 'antd';
import { useRecoilValue } from 'recoil';
import IndieAuthModal from '../IndieAuthModal/IndieAuthModal';
import FediAuthModal from '../FediAuthModal/FediAuthModal';
import { FC } from 'react';
import { IndieAuthModal } from '../IndieAuthModal/IndieAuthModal';
import { FediAuthModal } from '../FediAuthModal/FediAuthModal';
import FediverseIcon from '../../../assets/images/fediverse-black.png';
import IndieAuthIcon from '../../../assets/images/indieauth.png';
import s from './AuthModal.module.scss';
import styles from './AuthModal.module.scss';
import {
chatDisplayNameAtom,
chatAuthenticatedAtom,
@@ -15,10 +16,7 @@ import {
const { TabPane } = Tabs;
/* eslint-disable @typescript-eslint/no-unused-vars */
interface Props {}
export default function AuthModal(props: Props) {
export const AuthModal: FC = () => {
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
const authenticated = useRecoilValue<boolean>(chatAuthenticatedAtom);
const accessToken = useRecoilValue<string>(accessTokenAtom);
@@ -34,8 +32,8 @@ export default function AuthModal(props: Props) {
>
<TabPane
tab={
<span className={s.tabContent}>
<img className={s.icon} src={IndieAuthIcon.src} alt="IndieAuth" />
<span className={styles.tabContent}>
<img className={styles.icon} src={IndieAuthIcon.src} alt="IndieAuth" />
IndieAuth
</span>
}
@@ -49,8 +47,8 @@ export default function AuthModal(props: Props) {
</TabPane>
<TabPane
tab={
<span className={s.tabContent}>
<img className={s.icon} src={FediverseIcon.src} alt="Fediverse auth" />
<span className={styles.tabContent}>
<img className={styles.icon} src={FediverseIcon.src} alt="Fediverse auth" />
FediAuth
</span>
}
@@ -61,4 +59,4 @@ export default function AuthModal(props: Props) {
</Tabs>
</div>
);
}
};

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { RecoilRoot } from 'recoil';
import BrowserNotifyModal from './BrowserNotifyModal';
import { BrowserNotifyModal } from './BrowserNotifyModal';
import BrowserNotifyModalMock from '../../../stories/assets/mocks/notify-modal.png';
const Example = () => (

View File

@@ -1,69 +1,64 @@
import { Row, Col, Spin, Typography, Button } from 'antd';
import React, { useState } from 'react';
import React, { FC, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { accessTokenAtom, clientConfigStateAtom } from '../../stores/ClientConfigStore';
import {
registerWebPushNotifications,
saveNotificationRegistration,
} from '../../../services/notifications-service';
import s from './BrowserNotifyModal.module.scss';
import styles from './BrowserNotifyModal.module.scss';
import isPushNotificationSupported from '../../../utils/browserPushNotifications';
const { Title } = Typography;
function NotificationsNotSupported() {
return <div>Browser notifications are not supported in your browser.</div>;
}
const NotificationsNotSupported = () => (
<div>Browser notifications are not supported in your browser.</div>
);
function NotificationsEnabled() {
return <div>Notifications enabled</div>;
}
const NotificationsEnabled = () => <div>Notifications enabled</div>;
interface PermissionPopupPreviewProps {
export type PermissionPopupPreviewProps = {
start: () => void;
}
function PermissionPopupPreview(props: PermissionPopupPreviewProps) {
const { start } = props;
};
return (
<div id="browser-push-preview-box" className={s.pushPreview}>
<div className={s.inner}>
<div className={s.title}>{window.location.toString()} wants to</div>
<div className={s.permissionLine}>
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M14 12.3333V13H2V12.3333L3.33333 11V7C3.33333 4.93333 4.68667 3.11333 6.66667 2.52667C6.66667 2.46 6.66667 2.4 6.66667 2.33333C6.66667 1.97971 6.80714 1.64057 7.05719 1.39052C7.30724 1.14048 7.64638 1 8 1C8.35362 1 8.69276 1.14048 8.94281 1.39052C9.19286 1.64057 9.33333 1.97971 9.33333 2.33333C9.33333 2.4 9.33333 2.46 9.33333 2.52667C11.3133 3.11333 12.6667 4.93333 12.6667 7V11L14 12.3333ZM9.33333 13.6667C9.33333 14.0203 9.19286 14.3594 8.94281 14.6095C8.69276 14.8595 8.35362 15 8 15C7.64638 15 7.30724 14.8595 7.05719 14.6095C6.80714 14.3594 6.66667 14.0203 6.66667 13.6667"
fill="#676670"
/>
</svg>
Show notifications
</div>
<div className={s.buttonRow}>
<Button
type="primary"
className={s.allow}
onClick={() => {
start();
}}
>
Allow
</Button>
<button type="button" className={s.disabled}>
Block
</button>
</div>
const PermissionPopupPreview: FC<PermissionPopupPreviewProps> = ({ start }) => (
<div id="browser-push-preview-box" className={styles.pushPreview}>
<div className={styles.inner}>
<div className={styles.title}>{window.location.toString()} wants to</div>
<div className={styles.permissionLine}>
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M14 12.3333V13H2V12.3333L3.33333 11V7C3.33333 4.93333 4.68667 3.11333 6.66667 2.52667C6.66667 2.46 6.66667 2.4 6.66667 2.33333C6.66667 1.97971 6.80714 1.64057 7.05719 1.39052C7.30724 1.14048 7.64638 1 8 1C8.35362 1 8.69276 1.14048 8.94281 1.39052C9.19286 1.64057 9.33333 1.97971 9.33333 2.33333C9.33333 2.4 9.33333 2.46 9.33333 2.52667C11.3133 3.11333 12.6667 4.93333 12.6667 7V11L14 12.3333ZM9.33333 13.6667C9.33333 14.0203 9.19286 14.3594 8.94281 14.6095C8.69276 14.8595 8.35362 15 8 15C7.64638 15 7.30724 14.8595 7.05719 14.6095C6.80714 14.3594 6.66667 14.0203 6.66667 13.6667"
fill="#676670"
/>
</svg>
Show notifications
</div>
<div className={styles.buttonRow}>
<Button
type="primary"
className={styles.allow}
onClick={() => {
start();
}}
>
Allow
</Button>
<button type="button" className={styles.disabled}>
Block
</button>
</div>
</div>
);
}
</div>
);
export default function BrowserNotifyModal() {
export const BrowserNotifyModal = () => {
const [error, setError] = useState<string>(null);
const accessToken = useRecoilValue(accessTokenAtom);
const config = useRecoilValue(clientConfigStateAtom);
@@ -120,4 +115,4 @@ export default function BrowserNotifyModal() {
</Row>
</Spin>
);
}
};

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import FatalErrorStateModal from './FatalErrorStateModal';
import { FatalErrorStateModal } from './FatalErrorStateModal';
export default {
title: 'owncast/Modals/Global error state',

View File

@@ -1,25 +1,22 @@
import { Modal } from 'antd';
import { FC } from 'react';
interface Props {
export type FatalErrorStateModalProps = {
title: string;
message: string;
}
};
export default function FatalErrorStateModal(props: Props) {
const { title, message } = props;
return (
<Modal
title={title}
visible
footer={null}
closable={false}
keyboard={false}
width={900}
centered
className="modal"
>
<p style={{ fontSize: '1.3rem' }}>{message}</p>
</Modal>
);
}
export const FatalErrorStateModal: FC<FatalErrorStateModalProps> = ({ title, message }) => (
<Modal
title={title}
visible
footer={null}
closable={false}
keyboard={false}
width={900}
centered
className="modal"
>
<p style={{ fontSize: '1.3rem' }}>{message}</p>
</Modal>
);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import FediAuthModal from './FediAuthModal';
import { FediAuthModal } from './FediAuthModal';
import FediAuthModalMock from '../../../stories/assets/mocks/fediauth-modal.png';
const Example = () => (

View File

@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
interface Props {}
import { FC } from 'react';
export default function FediAuthModal(props: Props) {
return <div>Component goes here</div>;
}
export const FediAuthModal: FC = () => <div>Component goes here</div>;

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import FollowModal from './FollowModal';
import { FollowModal } from './FollowModal';
import FollowModalMock from '../../../stories/assets/mocks/follow-modal.png';
const Example = () => (

View File

@@ -1,15 +1,15 @@
/* eslint-disable react/no-unescaped-entities */
import { Input, Button, Alert, Spin, Space } from 'antd';
import { useState } from 'react';
import s from './FollowModal.module.scss';
import { FC, useState } from 'react';
import styles from './FollowModal.module.scss';
const ENDPOINT = '/api/remotefollow';
interface Props {
export type FollowModalProps = {
handleClose: () => void;
account: string;
name: string;
}
};
function validateAccount(a) {
const sanitized = a.replace(/^@+/, '');
@@ -18,8 +18,7 @@ function validateAccount(a) {
return regex.test(String(sanitized).toLowerCase());
}
export default function FollowModal(props: Props) {
const { handleClose, account, name } = props;
export const FollowModal: FC<FollowModalProps> = ({ handleClose, account, name }) => {
const [remoteAccount, setRemoteAccount] = useState(null);
const [valid, setValid] = useState(false);
const [loading, setLoading] = useState(false);
@@ -76,7 +75,7 @@ export default function FollowModal(props: Props) {
return (
<Space direction="vertical">
<div className={s.header}>
<div className={styles.header}>
By following this stream you'll get notified on the Fediverse when it goes live. Now is a
great time to
<a href="https://owncast.online/join-fediverse" target="_blank" rel="noreferrer">
@@ -89,16 +88,16 @@ export default function FollowModal(props: Props) {
{errorMessage && (
<Alert message="Follow Error" description={errorMessage} type="error" showIcon />
)}
<div className={s.account}>
<img src="/logo" alt="logo" className={s.logo} />
<div className={s.username}>
<div className={s.name}>{name}</div>
<div className={styles.account}>
<img src="/logo" alt="logo" className={styles.logo} />
<div className={styles.username}>
<div className={styles.name}>{name}</div>
<div>{account}</div>
</div>
</div>
<div>
<div className={s.instructions}>Enter your username @server to follow</div>
<div className={styles.instructions}>Enter your username @server to follow</div>
<Input
value={account}
size="large"
@@ -106,11 +105,11 @@ export default function FollowModal(props: Props) {
placeholder="Your fediverse account @account@server"
defaultValue={account}
/>
<div className={s.footer}>
<div className={styles.footer}>
You'll be redirected to your Fediverse server and asked to confirm the action.
</div>
</div>
<Space className={s.buttons}>
<Space className={styles.buttons}>
<Button disabled={!valid} type="primary" onClick={remoteFollowButtonPressed}>
Follow
</Button>
@@ -121,4 +120,4 @@ export default function FollowModal(props: Props) {
</Spin>
</Space>
);
}
};

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import IndieAuthModal from './IndieAuthModal';
import { IndieAuthModal } from './IndieAuthModal';
import Mock from '../../../stories/assets/mocks/indieauth-modal.png';
const Example = () => (

View File

@@ -1,19 +1,21 @@
import { Alert, Button, Input, Space, Spin, Collapse, Typography } from 'antd';
import React, { useState } from 'react';
import React, { FC, useState } from 'react';
import isValidURL from '../../../utils/urls';
const { Panel } = Collapse;
const { Link } = Typography;
interface Props {
export type IndieAuthModalProps = {
authenticated: boolean;
displayName: string;
accessToken: string;
}
export default function IndieAuthModal(props: Props) {
const { authenticated, displayName: username, accessToken } = props;
};
export const IndieAuthModal: FC<IndieAuthModalProps> = ({
authenticated,
displayName: username,
accessToken,
}) => {
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [valid, setValid] = useState(false);
@@ -153,4 +155,4 @@ export default function IndieAuthModal(props: Props) {
</Space>
</Spin>
);
}
};

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { RecoilRoot } from 'recoil';
import NameChangeModal from './NameChangeModal';
import { NameChangeModal } from './NameChangeModal';
export default {
title: 'owncast/Modals/Name change',

View File

@@ -1,4 +1,4 @@
import React, { CSSProperties, useState } from 'react';
import React, { CSSProperties, FC, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { Input, Button, Select } from 'antd';
import { MessageType } from '../../../interfaces/socket-events';
@@ -11,11 +11,11 @@ import {
const { Option } = Select;
/* eslint-disable @typescript-eslint/no-unused-vars */
interface Props {}
export type UserColorProps = {
color: number;
};
function UserColor(props: { color: number }): React.ReactElement {
const { color } = props;
const UserColor: FC<UserColorProps> = ({ color }) => {
const style: CSSProperties = {
textAlign: 'center',
backgroundColor: `var(--theme-color-users-${color})`,
@@ -23,9 +23,9 @@ function UserColor(props: { color: number }): React.ReactElement {
height: '100%',
};
return <div style={style} />;
}
};
export default function NameChangeModal(props: Props) {
export const NameChangeModal: FC = () => {
const websocketService = useRecoilValue<WebsocketService>(websocketServiceAtom);
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
const chatDisplayColor = useRecoilValue<number>(chatDisplayColorAtom) || 0;
@@ -85,4 +85,4 @@ export default function NameChangeModal(props: Props) {
</div>
</div>
);
}
};