forked from abner/for-legacy-web
Format and automatically fix linted code.
This commit is contained in:
@@ -10,7 +10,6 @@ export default function ConditionalLink(props: Props) {
|
||||
|
||||
if (active) {
|
||||
return <a>{props.children}</a>;
|
||||
} else {
|
||||
return <Link {...linkProps} />;
|
||||
}
|
||||
return <Link {...linkProps} />;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
LeftArrowAlt,
|
||||
Trash,
|
||||
} from "@styled-icons/boxicons-regular";
|
||||
import Tooltip from "../components/common/Tooltip";
|
||||
import { Cog, UserVoice } from "@styled-icons/boxicons-solid";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import {
|
||||
@@ -61,6 +60,7 @@ import {
|
||||
} from "../context/revoltjs/hooks";
|
||||
import { takeError } from "../context/revoltjs/util";
|
||||
|
||||
import Tooltip from "../components/common/Tooltip";
|
||||
import UserStatus from "../components/common/user/UserStatus";
|
||||
import IconButton from "../components/ui/IconButton";
|
||||
import LineDivider from "../components/ui/LineDivider";
|
||||
@@ -168,7 +168,7 @@ function ContextMenus(props: Props) {
|
||||
)
|
||||
return;
|
||||
|
||||
let message =
|
||||
const message =
|
||||
data.channel.channel_type === "TextChannel"
|
||||
? data.channel.last_message
|
||||
: data.channel.last_message._id;
|
||||
@@ -292,8 +292,9 @@ function ContextMenus(props: Props) {
|
||||
const { filename } = data.attachment;
|
||||
writeClipboard(
|
||||
// ! FIXME: do from r.js
|
||||
client.generateFileURL(data.attachment) +
|
||||
`/${encodeURI(filename)}`,
|
||||
`${client.generateFileURL(
|
||||
data.attachment,
|
||||
)}/${encodeURI(filename)}`,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -376,7 +377,7 @@ function ContextMenus(props: Props) {
|
||||
|
||||
case "clear_status":
|
||||
{
|
||||
let { text, ...status } = client.user?.status ?? {};
|
||||
const { text, ...status } = client.user?.status ?? {};
|
||||
await client.users.editUser({ status });
|
||||
}
|
||||
break;
|
||||
@@ -459,7 +460,7 @@ function ContextMenus(props: Props) {
|
||||
}: ContextMenuData) => {
|
||||
const forceUpdate = useForceUpdate();
|
||||
const elements: Children[] = [];
|
||||
var lastDivider = false;
|
||||
let lastDivider = false;
|
||||
|
||||
function generateAction(
|
||||
action: Action,
|
||||
@@ -487,8 +488,8 @@ function ContextMenus(props: Props) {
|
||||
}
|
||||
|
||||
if (server_list) {
|
||||
let server = useServer(server_list, forceUpdate);
|
||||
let permissions = useServerPermission(
|
||||
const server = useServer(server_list, forceUpdate);
|
||||
const permissions = useServerPermission(
|
||||
server_list,
|
||||
forceUpdate,
|
||||
);
|
||||
@@ -742,7 +743,7 @@ function ContextMenus(props: Props) {
|
||||
}
|
||||
|
||||
if (document.activeElement?.tagName === "A") {
|
||||
let link =
|
||||
const link =
|
||||
document.activeElement.getAttribute("href");
|
||||
if (link) {
|
||||
pushDivider();
|
||||
@@ -752,7 +753,7 @@ function ContextMenus(props: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
let id = sid ?? cid ?? uid ?? message?._id;
|
||||
const id = sid ?? cid ?? uid ?? message?._id;
|
||||
if (id) {
|
||||
pushDivider();
|
||||
|
||||
@@ -876,14 +877,23 @@ function ContextMenus(props: Props) {
|
||||
<>
|
||||
<div className="header">
|
||||
<div className="main">
|
||||
<div className="username"
|
||||
onClick={() => writeClipboard(client.user!.username)}>
|
||||
<Tooltip content={<Text id="app.special.copy_username" />}>
|
||||
<div
|
||||
className="username"
|
||||
onClick={() =>
|
||||
writeClipboard(client.user!.username)
|
||||
}>
|
||||
<Tooltip
|
||||
content={
|
||||
<Text id="app.special.copy_username" />
|
||||
}>
|
||||
@{client.user!.username}
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className="status"
|
||||
onClick={() => contextClick({ action: 'set_status' })}>
|
||||
<div
|
||||
className="status"
|
||||
onClick={() =>
|
||||
contextClick({ action: "set_status" })
|
||||
}>
|
||||
<UserStatus user={client.user!} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -935,9 +945,7 @@ function ContextMenus(props: Props) {
|
||||
data={{ action: "set_status" }}
|
||||
disabled={!isOnline}>
|
||||
<UserVoice size={18} />
|
||||
<Text
|
||||
id={`app.context_menu.custom_status`}
|
||||
/>
|
||||
<Text id={`app.context_menu.custom_status`} />
|
||||
{client.user!.status?.text && (
|
||||
<IconButton>
|
||||
<MenuItem data={{ action: "clear_status" }}>
|
||||
@@ -959,7 +967,7 @@ function ContextMenus(props: Props) {
|
||||
channel,
|
||||
);
|
||||
|
||||
let elements: Children[] = [
|
||||
const elements: Children[] = [
|
||||
<MenuItem
|
||||
data={{
|
||||
action: "set_notification_state",
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function PaintCounter({
|
||||
}) {
|
||||
if (import.meta.env.PROD && !always) return null;
|
||||
|
||||
const [uniqueId] = useState("" + Math.random());
|
||||
const [uniqueId] = useState(`${Math.random()}`);
|
||||
const count = counts[uniqueId] ?? 0;
|
||||
counts[uniqueId] = count + 1;
|
||||
return (
|
||||
|
||||
@@ -74,7 +74,7 @@ export default function TextAreaAutoSize(props: TextAreaAutoSizeProps) {
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (ref.current && ghost.current) {
|
||||
ref.current.style.height = ghost.current.clientHeight + "px";
|
||||
ref.current.style.height = `${ghost.current.clientHeight}px`;
|
||||
}
|
||||
}, [ghost, props.value]);
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ export function internalSubscribe(
|
||||
event: string,
|
||||
fn: (...args: any[]) => void,
|
||||
) {
|
||||
InternalEvent.addListener(ns + "/" + event, fn);
|
||||
return () => InternalEvent.removeListener(ns + "/" + event, fn);
|
||||
InternalEvent.addListener(`${ns}/${event}`, fn);
|
||||
return () => InternalEvent.removeListener(`${ns}/${event}`, fn);
|
||||
}
|
||||
|
||||
export function internalEmit(ns: string, event: string, ...args: any[]) {
|
||||
InternalEvent.emit(ns + "/" + event, ...args);
|
||||
InternalEvent.emit(`${ns}/${event}`, ...args);
|
||||
}
|
||||
|
||||
// Event structure: namespace/event
|
||||
|
||||
@@ -46,10 +46,9 @@ function recursiveReplaceFields(input: string, fields: Fields) {
|
||||
}
|
||||
|
||||
return values.flat();
|
||||
} else {
|
||||
// base case
|
||||
return [input];
|
||||
}
|
||||
// base case
|
||||
return [input];
|
||||
}
|
||||
|
||||
export function TextReact({ id, fields }: Props) {
|
||||
@@ -57,7 +56,7 @@ export function TextReact({ id, fields }: Props) {
|
||||
|
||||
const path = id.split(".");
|
||||
let entry = intl.dictionary[path.shift()!];
|
||||
for (let key of path) {
|
||||
for (const key of path) {
|
||||
// @ts-expect-error
|
||||
entry = entry[key];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isDesktop, isMobile, isTablet } from "react-device-detect";
|
||||
|
||||
export const isTouchscreenDevice =
|
||||
(isDesktop || isTablet)
|
||||
isDesktop || isTablet
|
||||
? false
|
||||
: (typeof window !== "undefined"
|
||||
? navigator.maxTouchPoints > 0
|
||||
|
||||
@@ -74,10 +74,15 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
|
||||
async init(id: string, message_id?: string) {
|
||||
if (message_id) {
|
||||
if (this.state.type === 'RENDER') {
|
||||
let message = this.state.messages.find(x => x._id === message_id);
|
||||
if (this.state.type === "RENDER") {
|
||||
const message = this.state.messages.find(
|
||||
(x) => x._id === message_id,
|
||||
);
|
||||
if (message) {
|
||||
this.emit("scroll", { type: "ScrollToView", id: message_id });
|
||||
this.emit("scroll", {
|
||||
type: "ScrollToView",
|
||||
id: message_id,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -103,9 +108,9 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
function generateScroll(end: string): ScrollState {
|
||||
if (ref) {
|
||||
let heightRemoved = 0;
|
||||
let messageContainer = ref.children[0];
|
||||
const messageContainer = ref.children[0];
|
||||
if (messageContainer) {
|
||||
for (let child of Array.from(messageContainer.children)) {
|
||||
for (const child of Array.from(messageContainer.children)) {
|
||||
// If this child has a ulid.
|
||||
if (child.id?.length === 26) {
|
||||
// Check whether it was removed.
|
||||
@@ -127,12 +132,11 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
type: "OffsetTop",
|
||||
previousHeight: ref.scrollHeight - heightRemoved,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "OffsetTop",
|
||||
previousHeight: 0,
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "OffsetTop",
|
||||
previousHeight: 0,
|
||||
};
|
||||
}
|
||||
|
||||
await this.currentRenderer.loadTop(this, generateScroll);
|
||||
@@ -148,9 +152,9 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
function generateScroll(start: string): ScrollState {
|
||||
if (ref) {
|
||||
let heightRemoved = 0;
|
||||
let messageContainer = ref.children[0];
|
||||
const messageContainer = ref.children[0];
|
||||
if (messageContainer) {
|
||||
for (let child of Array.from(messageContainer.children)) {
|
||||
for (const child of Array.from(messageContainer.children)) {
|
||||
// If this child has a ulid.
|
||||
if (child.id?.length === 26) {
|
||||
// Check whether it was removed.
|
||||
@@ -172,11 +176,10 @@ export class SingletonRenderer extends EventEmitter3 {
|
||||
type: "ScrollTop",
|
||||
y: ref.scrollTop - heightRemoved,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type: "ScrollToBottom",
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "ScrollToBottom",
|
||||
};
|
||||
}
|
||||
|
||||
await this.currentRenderer.loadBottom(this, generateScroll);
|
||||
|
||||
@@ -8,10 +8,14 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (renderer.client!.websocket.connected) {
|
||||
if (nearby)
|
||||
renderer
|
||||
.client!.channels.fetchMessagesWithUsers(id, { nearby, limit: 100 }, true)
|
||||
.client!.channels.fetchMessagesWithUsers(
|
||||
id,
|
||||
{ nearby, limit: 100 },
|
||||
true,
|
||||
)
|
||||
.then(({ messages: data }) => {
|
||||
data.sort((a, b) => a._id.localeCompare(b._id));
|
||||
let messages = data.map((x) => mapMessage(x));
|
||||
const messages = data.map((x) => mapMessage(x));
|
||||
renderer.setState(
|
||||
id,
|
||||
{
|
||||
@@ -28,7 +32,7 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
.client!.channels.fetchMessagesWithUsers(id, {}, true)
|
||||
.then(({ messages: data }) => {
|
||||
data.reverse();
|
||||
let messages = data.map((x) => mapMessage(x));
|
||||
const messages = data.map((x) => mapMessage(x));
|
||||
renderer.setState(
|
||||
id,
|
||||
{
|
||||
@@ -72,11 +76,11 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (!channel) return;
|
||||
if (renderer.state.type !== "RENDER") return;
|
||||
|
||||
let messages = [...renderer.state.messages];
|
||||
let index = messages.findIndex((x) => x._id === id);
|
||||
const messages = [...renderer.state.messages];
|
||||
const index = messages.findIndex((x) => x._id === id);
|
||||
|
||||
if (index > -1) {
|
||||
let message = { ...messages[index], ...mapMessage(patch) };
|
||||
const message = { ...messages[index], ...mapMessage(patch) };
|
||||
messages.splice(index, 1, message);
|
||||
|
||||
renderer.setState(
|
||||
@@ -94,8 +98,8 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
if (!channel) return;
|
||||
if (renderer.state.type !== "RENDER") return;
|
||||
|
||||
let messages = [...renderer.state.messages];
|
||||
let index = messages.findIndex((x) => x._id === id);
|
||||
const messages = [...renderer.state.messages];
|
||||
const index = messages.findIndex((x) => x._id === id);
|
||||
|
||||
if (index > -1) {
|
||||
messages.splice(index, 1);
|
||||
|
||||
@@ -8,7 +8,7 @@ export type ScrollState =
|
||||
| { type: "Free" }
|
||||
| { type: "Bottom"; scrollingUntil?: number }
|
||||
| { type: "ScrollToBottom" | "StayAtBottom"; smooth?: boolean }
|
||||
| { type: "ScrollToView", id: string }
|
||||
| { type: "ScrollToView"; id: string }
|
||||
| { type: "OffsetTop"; previousHeight: number }
|
||||
| { type: "ScrollTop"; y: number };
|
||||
|
||||
|
||||
@@ -117,10 +117,10 @@ export default class Signaling extends EventEmitter<SignalingEvents> {
|
||||
this.once("close", onClose);
|
||||
const json = {
|
||||
id: this.index,
|
||||
type: type,
|
||||
type,
|
||||
data,
|
||||
};
|
||||
ws.send(JSON.stringify(json) + "\n");
|
||||
ws.send(`${JSON.stringify(json)}\n`);
|
||||
this.index++;
|
||||
});
|
||||
}
|
||||
@@ -161,7 +161,7 @@ export default class Signaling extends EventEmitter<SignalingEvents> {
|
||||
type: ProduceType,
|
||||
rtpParameters: RtpParameters,
|
||||
): Promise<string> {
|
||||
let result = await this.sendRequest(WSCommandType.StartProduce, {
|
||||
const result = await this.sendRequest(WSCommandType.StartProduce, {
|
||||
type,
|
||||
rtpParameters,
|
||||
});
|
||||
|
||||
@@ -172,7 +172,7 @@ export default class VoiceClient extends EventEmitter<VoiceEvents> {
|
||||
if (this.device === undefined || this.roomId === undefined)
|
||||
throw new ReferenceError("Voice Client is in an invalid state");
|
||||
const result = await this.signaling.authenticate(token, this.roomId);
|
||||
let [room] = await Promise.all([
|
||||
const [room] = await Promise.all([
|
||||
this.signaling.roomInfo(),
|
||||
this.device.load({ routerRtpCapabilities: result.rtpCapabilities }),
|
||||
]);
|
||||
@@ -229,7 +229,7 @@ export default class VoiceClient extends EventEmitter<VoiceEvents> {
|
||||
});
|
||||
|
||||
this.emit("ready");
|
||||
for (let user of this.participants) {
|
||||
for (const user of this.participants) {
|
||||
if (user[1].audio && user[0] !== this.userId)
|
||||
this.startConsume(user[0], "audio");
|
||||
}
|
||||
@@ -323,7 +323,7 @@ export default class VoiceClient extends EventEmitter<VoiceEvents> {
|
||||
await this.signaling.stopProduce(type);
|
||||
} catch (error) {
|
||||
if (error.error === WSErrorCode.ProducerNotFound) return;
|
||||
else throw error;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user