mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 07:02:10 -05:00
chore(refactor): delete context/revoltjs
folder
This commit is contained in:
parent
e37140dcd0
commit
c51b024329
30 changed files with 77 additions and 161 deletions
|
@ -31,15 +31,14 @@ import {
|
|||
import { useApplicationState } from "../../../mobx/State";
|
||||
import { Reply } from "../../../mobx/stores/MessageQueue";
|
||||
|
||||
import { emojiDictionary } from "../../../assets/emojis";
|
||||
import { useClient } from "../../../controllers/client/ClientController";
|
||||
import { takeError } from "../../../controllers/client/jsx/error";
|
||||
import {
|
||||
FileUploader,
|
||||
grabFiles,
|
||||
uploadFile,
|
||||
} from "../../../context/revoltjs/FileUploads";
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { emojiDictionary } from "../../../assets/emojis";
|
||||
import { useClient } from "../../../controllers/client/ClientController";
|
||||
} from "../../../controllers/client/jsx/legacy/FileUploads";
|
||||
import { modalController } from "../../../controllers/modals/ModalController";
|
||||
import AutoComplete, { useAutoComplete } from "../AutoComplete";
|
||||
import Emoji from "../Emoji";
|
||||
|
|
|
@ -11,13 +11,13 @@ import { Button, Category, Preloader } from "@revoltchat/ui";
|
|||
import { isTouchscreenDevice } from "../../../../lib/isTouchscreenDevice";
|
||||
|
||||
import { I18nError } from "../../../../context/Locale";
|
||||
import { takeError } from "../../../../context/revoltjs/util";
|
||||
|
||||
import ServerIcon from "../../../../components/common/ServerIcon";
|
||||
import {
|
||||
useClient,
|
||||
useSession,
|
||||
} from "../../../../controllers/client/ClientController";
|
||||
import { takeError } from "../../../../controllers/client/jsx/error";
|
||||
|
||||
const EmbedInviteBase = styled.div`
|
||||
width: 400px;
|
||||
|
|
|
@ -7,9 +7,8 @@ import { useCallback, useEffect, useState } from "preact/hooks";
|
|||
|
||||
import { Category, CategoryButton, Error, Tip } from "@revoltchat/ui";
|
||||
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { useSession } from "../../../controllers/client/ClientController";
|
||||
import { takeError } from "../../../controllers/client/jsx/error";
|
||||
import { modalController } from "../../../controllers/modals/ModalController";
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
hello do not touch `intermediate` or `revoltjs` folders
|
||||
they are being rewritten
|
|
@ -1,80 +0,0 @@
|
|||
export const _ = "";
|
||||
|
||||
/*export function registerEvents(
|
||||
state: State,
|
||||
setStatus: StateUpdater<ClientStatus>,
|
||||
client: Client,
|
||||
) {
|
||||
if (!client) return;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let listeners: Record<string, (...args: any[]) => void> = {
|
||||
connecting: () => setStatus(ClientStatus.CONNECTING),
|
||||
dropped: () => setStatus(ClientStatus.DISCONNECTED),
|
||||
|
||||
ready: () => {
|
||||
resetMemberSidebarFetched();
|
||||
setStatus(ClientStatus.ONLINE);
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
state.auth.logout();
|
||||
state.reset();
|
||||
setStatus(ClientStatus.READY);
|
||||
},
|
||||
|
||||
"channel/delete": (channel_id: string) => {
|
||||
deleteRenderer(channel_id);
|
||||
},
|
||||
|
||||
"server/delete": (_, server: Server) => {
|
||||
if (server) {
|
||||
for (const channel_id of server.channel_ids) {
|
||||
deleteRenderer(channel_id);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
listeners = new Proxy(listeners, {
|
||||
get:
|
||||
(target, listener) =>
|
||||
(...args: unknown[]) => {
|
||||
console.debug(`Calling ${listener.toString()} with`, args);
|
||||
Reflect.get(target, listener)(...args);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: clean this a bit and properly handle types
|
||||
for (const listener in listeners) {
|
||||
client.addListener(listener, listeners[listener]);
|
||||
}
|
||||
|
||||
const online = () => {
|
||||
setStatus(ClientStatus.RECONNECTING);
|
||||
client.options.autoReconnect = false;
|
||||
client.websocket.connect();
|
||||
};
|
||||
|
||||
const offline = () => {
|
||||
client.options.autoReconnect = false;
|
||||
client.websocket.disconnect();
|
||||
};
|
||||
|
||||
window.addEventListener("online", online);
|
||||
window.addEventListener("offline", offline);
|
||||
|
||||
return () => {
|
||||
for (const listener in listeners) {
|
||||
client.removeListener(
|
||||
listener,
|
||||
listeners[listener as keyof typeof listeners],
|
||||
);
|
||||
}
|
||||
|
||||
window.removeEventListener("online", online);
|
||||
window.removeEventListener("offline", offline);
|
||||
};
|
||||
}*/
|
34
src/controllers/client/jsx/ChannelName.tsx
Normal file
34
src/controllers/client/jsx/ChannelName.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
// ! This should be moved into @revoltchat/ui
|
||||
import { Channel } from "revolt.js";
|
||||
|
||||
import { Text } from "preact-i18n";
|
||||
|
||||
interface Props {
|
||||
channel?: Channel;
|
||||
prefix?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel display name
|
||||
*/
|
||||
export function ChannelName({ channel, prefix }: Props) {
|
||||
if (!channel) return <></>;
|
||||
|
||||
if (channel.channel_type === "SavedMessages")
|
||||
return <Text id="app.navigation.tabs.saved" />;
|
||||
|
||||
if (channel.channel_type === "DirectMessage") {
|
||||
return (
|
||||
<>
|
||||
{prefix && "@"}
|
||||
{channel.recipient!.username}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (channel.channel_type === "TextChannel" && prefix) {
|
||||
return <>{`#${channel.name}`}</>;
|
||||
}
|
||||
|
||||
return <>{channel.name}</>;
|
||||
}
|
|
@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
|
|||
|
||||
import { Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { clientController } from "../../controllers/client/ClientController";
|
||||
import { clientController } from "../ClientController";
|
||||
|
||||
interface Props {
|
||||
auth?: boolean;
|
|
@ -1,7 +1,3 @@
|
|||
import { Channel } from "revolt.js";
|
||||
|
||||
import { Text } from "preact-i18n";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function takeError(error: any): string {
|
||||
if (error.response) {
|
||||
|
@ -31,26 +27,3 @@ export function takeError(error: any): string {
|
|||
export function mapError(error: any): never {
|
||||
throw takeError(error);
|
||||
}
|
||||
|
||||
export function getChannelName(
|
||||
channel: Channel,
|
||||
prefixType?: boolean,
|
||||
): Children {
|
||||
if (channel.channel_type === "SavedMessages")
|
||||
return <Text id="app.navigation.tabs.saved" />;
|
||||
|
||||
if (channel.channel_type === "DirectMessage") {
|
||||
return (
|
||||
<>
|
||||
{prefixType && "@"}
|
||||
{channel.recipient!.username}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (channel.channel_type === "TextChannel" && prefixType) {
|
||||
return <>#{channel.name}</>;
|
||||
}
|
||||
|
||||
return <>{channel.name}</>;
|
||||
}
|
|
@ -9,11 +9,11 @@ import { useEffect, useState } from "preact/hooks";
|
|||
|
||||
import { IconButton, Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { determineFileSize } from "../../lib/fileSize";
|
||||
import { determineFileSize } from "../../../../lib/fileSize";
|
||||
|
||||
import { useClient } from "../../controllers/client/ClientController";
|
||||
import { modalController } from "../../controllers/modals/ModalController";
|
||||
import { takeError } from "./util";
|
||||
import { modalController } from "../../../modals/ModalController";
|
||||
import { useClient } from "../../ClientController";
|
||||
import { takeError } from "../error";
|
||||
|
||||
type BehaviourType =
|
||||
| { behaviour: "ask"; onChange: (file: File) => void }
|
|
@ -4,9 +4,8 @@ import { Text } from "preact-i18n";
|
|||
|
||||
import { ModalForm } from "@revoltchat/ui";
|
||||
|
||||
import { mapError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { useClient } from "../../client/ClientController";
|
||||
import { mapError } from "../../client/jsx/error";
|
||||
import { ModalProps } from "../types";
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,8 +7,7 @@ import { ModalForm } from "@revoltchat/ui";
|
|||
|
||||
import { noopAsync } from "../../../lib/js";
|
||||
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { takeError } from "../../client/jsx/error";
|
||||
import { modalController } from "../ModalController";
|
||||
import { ModalProps } from "../types";
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@ import { Text } from "preact-i18n";
|
|||
|
||||
import { ModalForm } from "@revoltchat/ui";
|
||||
|
||||
import { mapError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { useClient } from "../../client/ClientController";
|
||||
import { mapError } from "../../client/jsx/error";
|
||||
import { ModalProps } from "../types";
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,10 +7,9 @@ import { Category, Error, Modal } from "@revoltchat/ui";
|
|||
|
||||
import { noopTrue } from "../../../lib/js";
|
||||
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import FormField from "../../../pages/login/FormField";
|
||||
import { useClient } from "../../client/ClientController";
|
||||
import { takeError } from "../../client/jsx/error";
|
||||
import { ModalProps } from "../types";
|
||||
|
||||
interface FormInputs {
|
||||
|
|
|
@ -19,8 +19,7 @@ import {
|
|||
|
||||
import { noop } from "../../../lib/js";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
|
||||
import { FileUploader } from "../../client/jsx/legacy/FileUploads";
|
||||
import { ModalProps } from "../types";
|
||||
|
||||
const Preview = styled(Centred)`
|
||||
|
|
|
@ -9,10 +9,10 @@ import { Category, Modal } from "@revoltchat/ui";
|
|||
import { noopTrue } from "../../../../lib/js";
|
||||
|
||||
import { I18nError } from "../../../../context/Locale";
|
||||
import { takeError } from "../../../../context/revoltjs/util";
|
||||
|
||||
import FormField from "../../../../pages/login/FormField";
|
||||
import { useClient } from "../../../client/ClientController";
|
||||
import { takeError } from "../../../client/jsx/error";
|
||||
import { modalController } from "../../ModalController";
|
||||
import { ModalProps } from "../../types";
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@ import { useState } from "preact/hooks";
|
|||
|
||||
import { Button, Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { takeError } from "../../../../context/revoltjs/util";
|
||||
|
||||
import wideSVG from "/assets/wide.svg";
|
||||
|
||||
import FormField from "../../../../pages/login/FormField";
|
||||
import { takeError } from "../../../client/jsx/error";
|
||||
import { ModalProps } from "../../types";
|
||||
|
||||
interface FormInputs {
|
||||
|
|
|
@ -26,12 +26,12 @@ import { useApplicationState } from "../mobx/State";
|
|||
import { QueuedMessage } from "../mobx/stores/MessageQueue";
|
||||
import { NotificationState } from "../mobx/stores/NotificationOptions";
|
||||
|
||||
import { takeError } from "../context/revoltjs/util";
|
||||
import CMNotifications from "./contextmenu/CMNotifications";
|
||||
|
||||
import Tooltip from "../components/common/Tooltip";
|
||||
import UserStatus from "../components/common/user/UserStatus";
|
||||
import { useSession } from "../controllers/client/ClientController";
|
||||
import { takeError } from "../controllers/client/jsx/error";
|
||||
import { modalController } from "../controllers/modals/ModalController";
|
||||
import { internalEmit } from "./eventEmitter";
|
||||
import { getRenderer } from "./renderer/Singleton";
|
||||
|
|
|
@ -7,8 +7,8 @@ import { Masks, Preloader } from "@revoltchat/ui";
|
|||
import ErrorBoundary from "../lib/ErrorBoundary";
|
||||
|
||||
import Context from "../context";
|
||||
import { CheckAuth } from "../context/revoltjs/CheckAuth";
|
||||
|
||||
import { CheckAuth } from "../controllers/client/jsx/CheckAuth";
|
||||
import Invite from "./invite/Invite";
|
||||
|
||||
const Login = lazy(() => import("./login/Login"));
|
||||
|
|
|
@ -6,12 +6,11 @@ import styled from "styled-components/macro";
|
|||
|
||||
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
||||
|
||||
import { getChannelName } from "../../context/revoltjs/util";
|
||||
|
||||
import { useStatusColour } from "../../components/common/user/UserIcon";
|
||||
import UserStatus from "../../components/common/user/UserStatus";
|
||||
import Markdown from "../../components/markdown/Markdown";
|
||||
import { PageHeader } from "../../components/ui/Header";
|
||||
import { ChannelName } from "../../controllers/client/jsx/ChannelName";
|
||||
import { modalController } from "../../controllers/modals/ModalController";
|
||||
import HeaderActions from "./actions/HeaderActions";
|
||||
|
||||
|
@ -64,7 +63,6 @@ const Info = styled.div`
|
|||
`;
|
||||
|
||||
export default observer(({ channel }: ChannelHeaderProps) => {
|
||||
const name = getChannelName(channel);
|
||||
let icon, recipient: User | undefined;
|
||||
switch (channel.channel_type) {
|
||||
case "SavedMessages":
|
||||
|
@ -85,7 +83,9 @@ export default observer(({ channel }: ChannelHeaderProps) => {
|
|||
return (
|
||||
<PageHeader icon={icon} withTransparency>
|
||||
<Info>
|
||||
<span className="name">{name}</span>
|
||||
<span className="name">
|
||||
<ChannelName channel={channel} />
|
||||
</span>
|
||||
{isTouchscreenDevice &&
|
||||
channel.channel_type === "DirectMessage" && (
|
||||
<>
|
||||
|
|
|
@ -4,7 +4,7 @@ import styled from "styled-components/macro";
|
|||
|
||||
import { Text } from "preact-i18n";
|
||||
|
||||
import { getChannelName } from "../../../context/revoltjs/util";
|
||||
import { ChannelName } from "../../../controllers/client/jsx/ChannelName";
|
||||
|
||||
const StartBase = styled.div`
|
||||
margin: 18px 16px 10px 16px;
|
||||
|
@ -28,7 +28,9 @@ interface Props {
|
|||
export default observer(({ channel }: Props) => {
|
||||
return (
|
||||
<StartBase>
|
||||
<h1>{getChannelName(channel, true)}</h1>
|
||||
<h1>
|
||||
<ChannelName channel={channel} prefix />
|
||||
</h1>
|
||||
<h4>
|
||||
<Text id="app.main.channel.start.group" />
|
||||
</h4>
|
||||
|
|
|
@ -12,8 +12,6 @@ import { TextReact } from "../../lib/i18n";
|
|||
|
||||
import { useApplicationState } from "../../mobx/State";
|
||||
|
||||
import { takeError } from "../../context/revoltjs/util";
|
||||
|
||||
import ServerIcon from "../../components/common/ServerIcon";
|
||||
import UserIcon from "../../components/common/user/UserIcon";
|
||||
import {
|
||||
|
@ -21,6 +19,7 @@ import {
|
|||
useSession,
|
||||
} from "../../controllers/client/ClientController";
|
||||
import RequiresOnline from "../../controllers/client/jsx/RequiresOnline";
|
||||
import { takeError } from "../../controllers/client/jsx/error";
|
||||
|
||||
export default function Invite() {
|
||||
const history = useHistory();
|
||||
|
|
|
@ -9,11 +9,11 @@ import { useState } from "preact/hooks";
|
|||
import { Button, Category, Preloader, Tip } from "@revoltchat/ui";
|
||||
|
||||
import { I18nError } from "../../../context/Locale";
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import WaveSVG from "../../settings/assets/wave.svg";
|
||||
|
||||
import { clientController } from "../../../controllers/client/ClientController";
|
||||
import { takeError } from "../../../controllers/client/jsx/error";
|
||||
import FormField from "../FormField";
|
||||
import { CaptchaBlock, CaptchaProps } from "./CaptchaBlock";
|
||||
import { MailProvider } from "./MailProvider";
|
||||
|
|
|
@ -5,9 +5,9 @@ import { useEffect, useState } from "preact/hooks";
|
|||
import { Category, Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { I18nError } from "../../../context/Locale";
|
||||
import { takeError } from "../../../context/revoltjs/util";
|
||||
|
||||
import { useApi } from "../../../controllers/client/ClientController";
|
||||
import { takeError } from "../../../controllers/client/jsx/error";
|
||||
import { Form } from "./Form";
|
||||
|
||||
export function FormResend() {
|
||||
|
|
|
@ -4,9 +4,8 @@ import { Route, Switch, useHistory, useParams } from "react-router-dom";
|
|||
|
||||
import { Text } from "preact-i18n";
|
||||
|
||||
import { getChannelName } from "../../context/revoltjs/util";
|
||||
|
||||
import { useClient } from "../../controllers/client/ClientController";
|
||||
import { ChannelName } from "../../controllers/client/jsx/ChannelName";
|
||||
import { GenericSettings } from "./GenericSettings";
|
||||
import Overview from "./channel/Overview";
|
||||
import Permissions from "./channel/Permissions";
|
||||
|
@ -47,7 +46,7 @@ export default function ChannelSettings() {
|
|||
<GenericSettings
|
||||
pages={[
|
||||
{
|
||||
category: <div>{getChannelName(channel, true)}</div>,
|
||||
category: <ChannelName channel={channel} prefix />,
|
||||
id: "overview",
|
||||
icon: <InfoCircle size={20} />,
|
||||
title: (
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Button, Checkbox, InputBox } from "@revoltchat/ui";
|
|||
|
||||
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads";
|
||||
|
||||
interface Props {
|
||||
channel: Channel;
|
||||
|
|
|
@ -23,8 +23,6 @@ import { internalEmit } from "../../../lib/eventEmitter";
|
|||
import { useTranslation } from "../../../lib/i18n";
|
||||
import { stopPropagation } from "../../../lib/stopPropagation";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
|
||||
import AutoComplete, {
|
||||
useAutoComplete,
|
||||
} from "../../../components/common/AutoComplete";
|
||||
|
@ -32,6 +30,7 @@ import CollapsibleSection from "../../../components/common/CollapsibleSection";
|
|||
import Tooltip from "../../../components/common/Tooltip";
|
||||
import UserIcon from "../../../components/common/user/UserIcon";
|
||||
import { useClient } from "../../../controllers/client/ClientController";
|
||||
import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads";
|
||||
import { modalController } from "../../../controllers/modals/ModalController";
|
||||
|
||||
interface Data {
|
||||
|
|
|
@ -12,12 +12,11 @@ import { Button, LineDivider, Tip } from "@revoltchat/ui";
|
|||
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
||||
import { useTranslation } from "../../../lib/i18n";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
|
||||
import AutoComplete, {
|
||||
useAutoComplete,
|
||||
} from "../../../components/common/AutoComplete";
|
||||
import { useSession } from "../../../controllers/client/ClientController";
|
||||
import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads";
|
||||
import { UserProfile } from "../../../controllers/modals/components/legacy/UserProfile";
|
||||
|
||||
export const Profile = observer(() => {
|
||||
|
|
|
@ -9,10 +9,9 @@ import { useEffect, useState } from "preact/hooks";
|
|||
|
||||
import { IconButton, Preloader } from "@revoltchat/ui";
|
||||
|
||||
import { getChannelName } from "../../../context/revoltjs/util";
|
||||
|
||||
import UserIcon from "../../../components/common/user/UserIcon";
|
||||
import { Username } from "../../../components/common/user/UserShort";
|
||||
import { ChannelName } from "../../../controllers/client/jsx/ChannelName";
|
||||
|
||||
interface InnerProps {
|
||||
invite: API.Invite;
|
||||
|
@ -33,7 +32,9 @@ const Inner = observer(({ invite, server, removeSelf }: InnerProps) => {
|
|||
<UserIcon target={user} size={24} />{" "}
|
||||
<Username user={user} showServerIdentity="both" />
|
||||
</span>
|
||||
<span>{channel ? getChannelName(channel, true) : "#??"}</span>
|
||||
<span>
|
||||
<ChannelName channel={channel} prefix />
|
||||
</span>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setDelete(true);
|
||||
|
|
|
@ -12,8 +12,8 @@ import { Button, ComboBox, InputBox } from "@revoltchat/ui";
|
|||
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
||||
import { noop } from "../../../lib/js";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
import { getChannelName } from "../../../context/revoltjs/util";
|
||||
import { ChannelName } from "../../../controllers/client/jsx/ChannelName";
|
||||
import { FileUploader } from "../../../controllers/client/jsx/legacy/FileUploads";
|
||||
|
||||
interface Props {
|
||||
server: Server;
|
||||
|
@ -172,7 +172,7 @@ export const Overview = observer(({ server }: Props) => {
|
|||
)
|
||||
.map((channel) => (
|
||||
<option key={channel!._id} value={channel!._id}>
|
||||
{getChannelName(channel!, true)}
|
||||
<ChannelName channel={channel} prefix />
|
||||
</option>
|
||||
))}
|
||||
</ComboBox>
|
||||
|
|
Loading…
Reference in a new issue