Format and automatically fix linted code.

This commit is contained in:
Paul
2021-07-10 15:57:29 +01:00
parent 1a59bb1abd
commit b3386ade33
87 changed files with 789 additions and 563 deletions

View File

@@ -335,8 +335,7 @@ function Theme({ children, options }: Props) {
return (
<ThemeContext.Provider value={theme}>
<Helmet>
<meta name="theme-color" content={theme["background"]}
/>
<meta name="theme-color" content={theme["background"]} />
</Helmet>
<GlobalTheme theme={theme} />
{theme.css && (

View File

@@ -1,5 +1,7 @@
import { isModalClosing } from "../../components/ui/Modal";
import { internalEmit } from "../../lib/eventEmitter";
import { isModalClosing } from "../../components/ui/Modal";
import { Screen } from "./Intermediate";
import { ClipboardModal } from "./modals/Clipboard";
import { ErrorModal } from "./modals/Error";
@@ -14,7 +16,10 @@ export interface Props {
}
export default function Modals({ screen, openScreen }: Props) {
const onClose = () => isModalClosing ? openScreen({ id: "none" }) : internalEmit('Modal', 'close');
const onClose = () =>
isModalClosing
? openScreen({ id: "none" })
: internalEmit("Modal", "close");
switch (screen.id) {
case "_prompt":

View File

@@ -1,7 +1,9 @@
import { useContext } from "preact/hooks";
import { isModalClosing } from "../../components/ui/Modal";
import { internalEmit } from "../../lib/eventEmitter";
import { isModalClosing } from "../../components/ui/Modal";
import { IntermediateContext, useIntermediate } from "./Intermediate";
import { SpecialInputModal } from "./modals/Input";
import { SpecialPromptModal } from "./modals/Prompt";
@@ -16,7 +18,10 @@ export default function Popovers() {
const { screen } = useContext(IntermediateContext);
const { openScreen } = useIntermediate();
const onClose = () => isModalClosing ? openScreen({ id: "none" }) : internalEmit('Modal', 'close');
const onClose = () =>
isModalClosing
? openScreen({ id: "none" })
: internalEmit("Modal", "close");
switch (screen.id) {
case "profile":

View File

@@ -92,7 +92,7 @@ export function SpecialPromptModal(props: SpecialProps) {
block_user: ["block_user", "block"],
};
let event = EVENTS[props.type];
const event = EVENTS[props.type];
let name;
switch (props.type) {
case "unfriend_user":

View File

@@ -25,7 +25,7 @@ export function ImageViewer({ attachment, embed, onClose }: Props) {
// ! FIXME: temp code
// ! add proxy function to client
function proxyImage(url: string) {
return "https://jan.revolt.chat/proxy?url=" + encodeURIComponent(url);
return `https://jan.revolt.chat/proxy?url=${encodeURIComponent(url)}`;
}
if (attachment && attachment.metadata.type !== "Image") {

View File

@@ -55,7 +55,7 @@ export async function uploadFile(
const formData = new FormData();
formData.append("file", file);
const res = await Axios.post(autumnURL + "/" + tag, formData, {
const res = await Axios.post(`${autumnURL}/${tag}`, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
@@ -78,7 +78,7 @@ export function grabFiles(
input.onchange = async (e) => {
const files = (e.currentTarget as HTMLInputElement)?.files;
if (!files) return;
for (let file of files) {
for (const file of files) {
if (file.size > maxFileSize) {
return tooLarge();
}
@@ -139,12 +139,10 @@ export function FileUploader(props: Props) {
} else {
onClick();
}
} else if (props.previewURL) {
props.remove();
} else {
if (props.previewURL) {
props.remove();
} else {
onClick();
}
onClick();
}
}
@@ -156,7 +154,7 @@ export function FileUploader(props: Props) {
if (typeof items === "undefined") return;
if (props.behaviour !== "multi" || !props.append) return;
let files = [];
const files = [];
for (const item of items) {
if (!item.type.startsWith("text/")) {
const blob = item.getAsFile();
@@ -190,7 +188,7 @@ export function FileUploader(props: Props) {
const dropped = e.dataTransfer?.files;
if (dropped) {
let files = [];
const files = [];
for (const item of dropped) {
if (item.size > props.maxFileSize) {
openScreen({ id: "error", error: "FileTooLarge" });

View File

@@ -32,7 +32,7 @@ async function createNotification(
try {
return new Notification(title, options);
} catch (err) {
let sw = await navigator.serviceWorker.getRegistration();
const sw = await navigator.serviceWorker.getRegistration();
sw?.showNotification(title, options);
}
}
@@ -90,7 +90,7 @@ function Notifier({ options, notifs }: Props) {
let image;
if (msg.attachments) {
let imageAttachment = msg.attachments.find(
const imageAttachment = msg.attachments.find(
(x) => x.metadata.type === "Image",
);
if (imageAttachment) {
@@ -105,7 +105,7 @@ function Notifier({ options, notifs }: Props) {
body = client.markdownToText(msg.content);
icon = client.users.getAvatarURL(msg.author, { max_side: 256 });
} else {
let users = client.users;
const users = client.users;
switch (msg.content.type) {
case "user_added":
case "user_remove":
@@ -161,7 +161,7 @@ function Notifier({ options, notifs }: Props) {
}
}
let notif = await createNotification(title, {
const notif = await createNotification(title, {
icon,
image,
body,
@@ -176,7 +176,7 @@ function Notifier({ options, notifs }: Props) {
window.focus();
const id = msg.channel;
if (id !== channel_id) {
let channel = client.channels.get(id);
const channel = client.channels.get(id);
if (channel) {
if (channel.channel_type === "TextChannel") {
history.push(
@@ -218,7 +218,7 @@ function Notifier({ options, notifs }: Props) {
return;
}
let notif = await createNotification(event, {
const notif = await createNotification(event, {
icon: client.users.getAvatarURL(user._id, { max_side: 256 }),
badge: "/assets/icons/android-chrome-512x512.png",
timestamp: +new Date(),

View File

@@ -66,7 +66,7 @@ function Context({ auth, children }: Props) {
// Match sw.ts#L23
db = await openDB("state", 3, {
upgrade(db) {
for (let store of [
for (const store of [
"channels",
"servers",
"users",
@@ -150,7 +150,7 @@ function Context({ auth, children }: Props) {
ready: () =>
operations.loggedIn() && typeof client.user !== "undefined",
openDM: async (user_id: string) => {
let channel = await client.users.openDM(user_id);
const channel = await client.users.openDM(user_id);
history.push(`/channel/${channel!._id}`);
return channel!._id;
},

View File

@@ -44,10 +44,10 @@ function StateMonitor(props: Props) {
useEffect(() => {
function removeOld() {
if (!props.typing) return;
for (let channel of Object.keys(props.typing)) {
let users = props.typing[channel];
for (const channel of Object.keys(props.typing)) {
const users = props.typing[channel];
for (let user of users) {
for (const user of users) {
if (+new Date() > user.started + 5000) {
dispatch({
type: "TYPING_STOP",
@@ -61,7 +61,7 @@ function StateMonitor(props: Props) {
removeOld();
let interval = setInterval(removeOld, 1000);
const interval = setInterval(removeOld, 1000);
return () => clearInterval(interval);
}, [props.typing]);

View File

@@ -28,15 +28,15 @@ type Props = {
notifications: Notifications;
};
var lastValues: { [key in SyncKeys]?: any } = {};
const lastValues: { [key in SyncKeys]?: any } = {};
export function mapSync(
packet: Sync.UserSettings,
revision?: Record<string, number>,
) {
let update: { [key in SyncKeys]?: [number, SyncData[key]] } = {};
for (let key of Object.keys(packet)) {
let [timestamp, obj] = packet[key];
const update: { [key in SyncKeys]?: [number, SyncData[key]] } = {};
for (const key of Object.keys(packet)) {
const [timestamp, obj] = packet[key];
if (timestamp < (revision ?? {})[key] ?? 0) {
continue;
}
@@ -81,7 +81,7 @@ function SyncManager(props: Props) {
}, [status]);
function syncChange(key: SyncKeys, data: any) {
let timestamp = +new Date();
const timestamp = +new Date();
dispatch({
type: "SYNC_SET_REVISION",
key,
@@ -96,8 +96,8 @@ function SyncManager(props: Props) {
);
}
let disabled = props.sync.disabled ?? [];
for (let [key, object] of [
const disabled = props.sync.disabled ?? [];
for (const [key, object] of [
["appearance", props.settings.appearance],
["theme", props.settings.theme],
["locale", props.locale],
@@ -119,7 +119,7 @@ function SyncManager(props: Props) {
useEffect(() => {
function onPacket(packet: ClientboundNotification) {
if (packet.type === "UserSettingsUpdate") {
let update: { [key in SyncKeys]?: [number, SyncData[key]] } =
const update: { [key in SyncKeys]?: [number, SyncData[key]] } =
mapSync(packet.update, props.sync.revision);
dispatch({

View File

@@ -16,9 +16,9 @@ export function useForceUpdate(context?: HookContext): HookContext {
if (context) return context;
const H = useState(0);
var updateState: (_: number) => void;
let updateState: (_: number) => void;
if (Array.isArray(H)) {
let [, u] = H;
const [, u] = H;
updateState = u;
} else {
console.warn("Failed to construct using useState.");
@@ -124,7 +124,7 @@ export function useDMs(context?: HookContext) {
const ctx = useForceUpdate(context);
function mutation(target: string) {
let channel = ctx.client.channels.get(target);
const channel = ctx.client.channels.get(target);
if (channel) {
if (
channel.channel_type === "DirectMessage" ||
@@ -164,7 +164,7 @@ export function useUserPermission(id: string, context?: HookContext) {
return () => ctx.client.users.removeListener("update", mutation);
}, [id]);
let calculator = new PermissionCalculator(ctx.client);
const calculator = new PermissionCalculator(ctx.client);
return calculator.forUser(id);
}
@@ -206,7 +206,7 @@ export function useChannelPermission(id: string, context?: HookContext) {
};
}, [id]);
let calculator = new PermissionCalculator(ctx.client);
const calculator = new PermissionCalculator(ctx.client);
return calculator.forChannel(id);
}
@@ -227,6 +227,6 @@ export function useServerPermission(id: string, context?: HookContext) {
};
}, [id]);
let calculator = new PermissionCalculator(ctx.client);
const calculator = new PermissionCalculator(ctx.client);
return calculator.forServer(id);
}

View File

@@ -7,7 +7,7 @@ import { Children } from "../../types/Preact";
export function takeError(error: any): string {
const type = error?.response?.data?.type;
let id = type;
const id = type;
if (!type) {
if (error?.response?.status === 403) {
return "Unauthorized";
@@ -31,7 +31,7 @@ export function getChannelName(
return <Text id="app.navigation.tabs.saved" />;
if (channel.channel_type === "DirectMessage") {
let uid = client.channels.getRecipient(channel._id);
const uid = client.channels.getRecipient(channel._id);
return (
<>
{prefixType && "@"}