Cleanup unused Javascript (#3027)

* chore(js): be stricter about dead code warnings

* chore(js): remove dead code and unused exports

* rebase

* chore: remove unused files

* chore(deps): remove unused prop-types dep

* chore(js): remove unused function

* chore(deps): remove + check unused deps

* chore(js): remove unused exports. Closes #3036
This commit is contained in:
Gabe Kangas
2023-05-20 21:15:25 -07:00
committed by GitHub
parent 429289d508
commit e50b23d081
55 changed files with 1187 additions and 1071 deletions

View File

@@ -1,71 +0,0 @@
// Note: references to "yp" in the app are likely related to Owncast Directory
import React, { useState, useContext, useEffect, FC } from 'react';
import { Typography } from 'antd';
import { ToggleSwitch } from './ToggleSwitch';
import { ServerStatusContext } from '../../utils/server-status-context';
import { FIELD_PROPS_NSFW, FIELD_PROPS_YP } from '../../utils/config-constants';
const { Title } = Typography;
// eslint-disable-next-line import/prefer-default-export
export const EditYPDetails: FC = () => {
const [formDataValues, setFormDataValues] = useState(null);
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig } = serverStatusData || {};
const { yp, instanceDetails } = serverConfig;
const { nsfw } = instanceDetails;
const { enabled, instanceUrl } = yp;
useEffect(() => {
setFormDataValues({
...yp,
enabled,
nsfw,
});
}, [yp, instanceDetails]);
const hasInstanceUrl = instanceUrl !== '';
if (!formDataValues) {
return null;
}
return (
<div className="config-directory-details-form">
<Title level={3} className="section-title">
Owncast Directory Settings
</Title>
<p className="description">
Would you like to appear in the{' '}
<a href="https://directory.owncast.online" target="_blank" rel="noreferrer">
<strong>Owncast Directory</strong>
</a>
?
</p>
<p style={{ backgroundColor: 'black', fontSize: '.75rem', padding: '5px' }}>
<em>
NOTE: You will need to have a URL specified in the <code>Instance URL</code> field to be
able to use this.
</em>
</p>
<div className="config-yp-container">
<ToggleSwitch
fieldName="enabled"
{...FIELD_PROPS_YP}
checked={formDataValues.enabled}
disabled={!hasInstanceUrl}
/>
<ToggleSwitch
fieldName="nsfw"
{...FIELD_PROPS_NSFW}
checked={formDataValues.nsfw}
disabled={!hasInstanceUrl}
/>
</div>
</div>
);
};

View File

@@ -1,27 +0,0 @@
import { Tooltip } from 'antd';
import dynamic from 'next/dynamic';
import { FC } from 'react';
// Lazy loaded components
const InfoCircleOutlined = dynamic(() => import('@ant-design/icons/InfoCircleOutlined'), {
ssr: false,
});
export type InfoTipProps = {
tip: string | null;
};
export const InfoTip: FC<InfoTipProps> = ({ tip }) => {
if (tip === '' || tip === null) {
return null;
}
return (
<span className="info-tip">
<Tooltip title={tip}>
<InfoCircleOutlined />
</Tooltip>
</span>
);
};

View File

@@ -1,31 +0,0 @@
import { Table, Typography } from 'antd';
import { FC } from 'react';
const { Title } = Typography;
export type KeyValueTableProps = {
title: string;
data: any;
};
export const KeyValueTable: FC<KeyValueTableProps> = ({ title, data }) => {
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
},
];
return (
<>
<Title level={2}>{title}</Title>
<Table pagination={false} columns={columns} dataSource={data} rowKey="name" />
</>
);
};

View File

@@ -174,4 +174,3 @@ export const Offline: FC<OfflineProps> = ({ logs = [], config }) => {
</>
);
};
export default Offline;

View File

@@ -212,7 +212,6 @@ export const TextField: FC<TextFieldProps> = ({
</div>
);
};
export default TextField;
TextField.defaultProps = {
className: '',

View File

@@ -14,9 +14,6 @@ import { ServerStatusContext } from '../../utils/server-status-context';
import { FormStatusIndicator } from './FormStatusIndicator';
import { TextField, TextFieldProps } from './TextField';
export const TEXTFIELD_TYPE_TEXT = 'default';
export const TEXTFIELD_TYPE_PASSWORD = 'password'; // Input.Password
export const TEXTFIELD_TYPE_NUMBER = 'numeric';
export const TEXTFIELD_TYPE_TEXTAREA = 'textarea';
export const TEXTFIELD_TYPE_URL = 'url';

View File

@@ -106,7 +106,6 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
</div>
);
};
export default ToggleSwitch;
ToggleSwitch.defaultProps = {
apiPath: '',

View File

@@ -1,15 +1,10 @@
import { Table } from 'antd';
import format from 'date-fns/format';
import { SortOrder } from 'antd/lib/table/interface';
import { formatDistanceToNow } from 'date-fns';
import { FC } from 'react';
import { User } from '../../types/chat';
import { formatUAstring } from '../../utils/format';
export function formatDisplayDate(date: string | Date) {
return format(new Date(date), 'MMM d H:mma');
}
export type ViewerTableProps = {
data: User[];
};

View File

@@ -214,7 +214,7 @@ export default function EditSocialLinks() {
title: 'Social Link',
dataIndex: '',
key: 'combo',
render: (data, record) => {
render: (_, record) => {
const { platform, url } = record;
const platformInfo = isPredefinedSocial(platform);
@@ -251,7 +251,7 @@ export default function EditSocialLinks() {
title: '',
dataIndex: '',
key: 'edit',
render: (data, record, index) => (
render: (_, _record, index) => (
<div className="actions">
<Button
size="small"

View File

@@ -19,7 +19,7 @@ import { FormStatusIndicator } from '../FormStatusIndicator';
const { Title } = Typography;
export const ConfigNotify = () => {
export const BrowserNotify = () => {
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
const { notifications } = serverConfig || {};
@@ -127,4 +127,3 @@ export const ConfigNotify = () => {
</>
);
};
export default ConfigNotify;

View File

@@ -19,7 +19,7 @@ import { UpdateArgs } from '../../../types/config-section';
const { Title } = Typography;
export const ConfigNotify = () => {
export const DiscordNotify = () => {
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
const { notifications } = serverConfig || {};
@@ -151,4 +151,3 @@ export const ConfigNotify = () => {
</>
);
};
export default ConfigNotify;

View File

@@ -5,7 +5,7 @@ import { ServerStatusContext } from '../../../utils/server-status-context';
const { Title } = Typography;
export const ConfigNotify = () => {
export const FediverseNotify = () => {
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig } = serverStatusData || {};
const { federation } = serverConfig || {};
@@ -49,4 +49,3 @@ export const ConfigNotify = () => {
</>
);
};
export default ConfigNotify;

View File

@@ -139,7 +139,7 @@ export const ChatModerationDetailsModal: FC<ChatModerationDetailsModalProps> = (
{
title: 'Delete',
key: 'delete',
render: (text, record) => (
render: (_text, record) => (
<Button
type="primary"
ghost

View File

@@ -1,8 +1,5 @@
import { convertToText } from '../chat';
import { getDiffInDaysFromNow } from '../../../utils/helpers';
const convertToMarkup = (str = '') => convertToText(str).replace(/\n/g, '<p></p>');
export function formatTimestamp(sentAt: Date) {
const now = new Date(sentAt);
if (Number.isNaN(now)) return '';
@@ -18,14 +15,3 @@ export function formatTimestamp(sentAt: Date) {
return `${now.toLocaleTimeString()}`;
}
/*
You would call this when receiving a plain text
value back from an API, and before inserting the
text into the `contenteditable` area on a page.
*/
export function formatMessageText(message: string) {
const formattedText = convertToMarkup(message);
return formattedText;
}

View File

@@ -1,142 +0,0 @@
// import {
// CHAT_INITIAL_PLACEHOLDER_TEXT,
// CHAT_PLACEHOLDER_TEXT,
// CHAT_PLACEHOLDER_OFFLINE,
// } from './constants.js';
// Taken from https://stackoverflow.com/a/46902361
export function getCaretPosition(node) {
const selection = window.getSelection();
if (selection.rangeCount === 0) {
return 0;
}
const range = selection.getRangeAt(0);
const preCaretRange = range.cloneRange();
const tempElement = document.createElement('div');
preCaretRange.selectNodeContents(node);
preCaretRange.setEnd(range.endContainer, range.endOffset);
tempElement.appendChild(preCaretRange.cloneContents());
return tempElement.innerHTML.length;
}
// Might not need this anymore
// Pieced together from parts of https://stackoverflow.com/questions/6249095/how-to-set-caretcursor-position-in-contenteditable-element-div
export function setCaretPosition(editableDiv, position) {
const range = document.createRange();
const sel = window.getSelection();
range.selectNode(editableDiv);
range.setStart(editableDiv.childNodes[0], position);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
// export function generatePlaceholderText(isEnabled, hasSentFirstChatMessage) {
// if (isEnabled) {
// return hasSentFirstChatMessage
// ? CHAT_PLACEHOLDER_TEXT
// : CHAT_INITIAL_PLACEHOLDER_TEXT;
// }
// return CHAT_PLACEHOLDER_OFFLINE;
// }
export function extraUserNamesFromMessageHistory(messages) {
const list = [];
if (messages) {
messages
.filter(m => m.user && m.user.displayName)
.forEach(message => {
if (!list.includes(message.user.displayName)) {
list.push(message.user.displayName);
}
});
}
return list;
}
// utils from https://gist.github.com/nathansmith/86b5d4b23ed968a92fd4
/*
You would call this after getting an element's
`.innerHTML` value, while the user is typing.
*/
export function convertToText(str = '') {
// Ensure string.
let value = String(str);
// Convert encoding.
value = value.replace(/&nbsp;/gi, ' ');
value = value.replace(/&amp;/gi, '&');
// Replace `<br>`.
value = value.replace(/<br>/gi, '\n');
// Replace `<div>` (from Chrome).
value = value.replace(/<div>/gi, '\n');
// Replace `<p>` (from IE).
value = value.replace(/<p>/gi, '\n');
// Cleanup the emoji titles.
value = value.replace(/\u200C{2}/gi, '');
// Trim each line.
value = value
.split('\n')
.map((line = '') => line.trim())
.join('\n');
// No more than 2x newline, per "paragraph".
value = value.replace(/\n\n+/g, '\n\n');
// Clean up spaces.
value = value.replace(/[ ]+/g, ' ');
value = value.trim();
// Expose string.
return value;
}
export function createEmojiMarkup(data, isCustom) {
const emojiUrl = isCustom ? data.emoji : data.url;
const emojiName = (
isCustom ? data.name : data.url.split('\\').pop().split('/').pop().split('.').shift()
).toLowerCase();
return `<img class="emoji" alt=":${emojiName}:" title=":${emojiName}:" src="${emojiUrl}"/>`;
}
// trim html white space characters from ends of messages for more accurate counting
export function trimNbsp(html) {
return html.replace(/^(?:&nbsp;|\s)+|(?:&nbsp;|\s)+$/gi, '');
}
export function emojify(HTML, emojiList) {
const textValue = convertToText(HTML);
// eslint-disable-next-line no-plusplus
for (let lastPos = textValue.length; lastPos >= 0; lastPos--) {
const endPos = textValue.lastIndexOf(':', lastPos);
if (endPos <= 0) {
break;
}
const startPos = textValue.lastIndexOf(':', endPos - 1);
if (startPos === -1) {
break;
}
const typedEmoji = textValue.substring(startPos + 1, endPos).trim();
const emojiIndex = emojiList.findIndex(
emojiItem => emojiItem.name.toLowerCase() === typedEmoji.toLowerCase(),
);
if (emojiIndex !== -1) {
const emojiImgElement = createEmojiMarkup(emojiList[emojiIndex], true);
// eslint-disable-next-line no-param-reassign
HTML = HTML.replace(`:${typedEmoji}:`, emojiImgElement);
}
}
return HTML;
}

View File

@@ -34,7 +34,7 @@ export default {
} as ComponentMeta<typeof BrowserNotifyModal>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Template: ComponentStory<typeof BrowserNotifyModal> = args => (
const Template: ComponentStory<typeof BrowserNotifyModal> = () => (
<RecoilRoot>
<Example />
</RecoilRoot>

View File

@@ -32,7 +32,7 @@ export default {
} as ComponentMeta<typeof FollowModal>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Template: ComponentStory<typeof FollowModal> = args => <Example />;
const Template: ComponentStory<typeof FollowModal> = () => <Example />;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const Basic = Template.bind({});

View File

@@ -22,7 +22,7 @@ export default {
} as ComponentMeta<typeof IndieAuthModal>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Template: ComponentStory<typeof IndieAuthModal> = args => <Example />;
const Template: ComponentStory<typeof IndieAuthModal> = () => <Example />;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const Basic = Template.bind({});

View File

@@ -55,7 +55,7 @@ export const NameChangeModal: FC = () => {
};
const maxColor = 8; // 0...n
const colorOptions = [...Array(maxColor)].map((e, i) => i);
const colorOptions = [...Array(maxColor)].map((_, i) => i);
const saveButton = (
<Button

View File

@@ -23,9 +23,9 @@ import {
FediverseEvent,
} from '../../interfaces/socket-events';
import { mergeMeta } from '../../utils/helpers';
import handleConnectedClientInfoMessage from './eventhandlers/connected-client-info-handler';
import { handleConnectedClientInfoMessage } from './eventhandlers/connected-client-info-handler';
import { ServerStatusServiceContext } from '../../services/status-service';
import handleNameChangeEvent from './eventhandlers/handleNameChangeEvent';
import { handleNameChangeEvent } from './eventhandlers/handleNameChangeEvent';
import { DisplayableError } from '../../types/displayable-error';
RecoilEnv.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED = false;
@@ -108,7 +108,7 @@ export const clockSkewAtom = atom<Number>({
default: 0.0,
});
export const removedMessageIdsAtom = atom<string[]>({
const removedMessageIdsAtom = atom<string[]>({
key: 'removedMessageIds',
default: [],
});

View File

@@ -16,4 +16,3 @@ export function handleConnectedClientInfoMessage(
isModerator: scopes?.includes('MODERATOR'),
});
}
export default handleConnectedClientInfoMessage;

View File

@@ -3,4 +3,3 @@ import { ChatEvent } from '../../../interfaces/socket-events';
export function handleNameChangeEvent(message: ChatEvent, setChatMessages) {
setChatMessages(currentState => [...currentState, message]);
}
export default handleNameChangeEvent;

View File

@@ -308,4 +308,3 @@ export const Content: FC = () => {
</>
);
};
export default Content;

View File

@@ -70,7 +70,6 @@ export const CrossfadeImage: FC<CrossfadeImageProps> = ({
</span>
);
};
export default CrossfadeImage;
CrossfadeImage.defaultProps = {
objectFit: 'fill',

View File

@@ -33,4 +33,3 @@ export const Footer: FC<FooterProps> = ({ dynamicPaddingValue }) => {
</footer>
);
};
export default Footer;

View File

@@ -12,4 +12,3 @@ export const Logo: FC<LogoProps> = ({ src }) => (
</div>
</div>
);
export default Logo;

View File

@@ -1,29 +0,0 @@
import { CSSProperties, FC } from 'react';
export type ModIconProps = {
style?: CSSProperties;
fill?: string;
stroke?: string;
};
export const ModIcon: FC<ModIconProps> = ({
style = { width: '1rem', height: '1rem' },
fill = 'none',
stroke = 'var(--color-owncast-gray-300)',
}: ModIconProps) => (
<svg
fill={fill}
stroke={stroke}
style={style}
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<title>This user has moderation rights</title>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"
/>
</svg>
);

View File

@@ -84,7 +84,6 @@ export const Statusbar: FC<StatusbarProps> = ({
</div>
);
};
export default Statusbar;
Statusbar.defaultProps = {
lastConnectTime: null,

View File

@@ -9,7 +9,7 @@ import { VideoPoster } from '../VideoPoster/VideoPoster';
import { getLocalStorage, setLocalStorage } from '../../../utils/localStorage';
import { isVideoPlayingAtom, clockSkewAtom } from '../../stores/ClientConfigStore';
import PlaybackMetrics from '../metrics/playback';
import createVideoSettingsMenuButton from '../settings-menu';
import { createVideoSettingsMenuButton } from '../settings-menu';
import LatencyCompensator from '../latencyCompensator';
import styles from './OwncastPlayer.module.scss';
import { VideoSettingsServiceContext } from '../../../services/video-settings-service';

View File

@@ -58,5 +58,3 @@ export const VideoJS: FC<VideoJSProps> = ({ options, onReady }) => {
</div>
);
};
export default VideoJS;

View File

@@ -111,5 +111,3 @@ export function createVideoSettingsMenuButton(player, videojs, qualities, latenc
// eslint-disable-next-line consistent-return
return menuButton;
}
export default createVideoSettingsMenuButton;