feat(modal): port Error and ShowToken

This commit is contained in:
Paul Makles
2022-06-18 12:25:56 +01:00
parent 62ce6fdbf3
commit 35819441e4
13 changed files with 92 additions and 61 deletions

View File

@@ -6,7 +6,7 @@ import { useContext, useEffect } from "preact/hooks";
import { Header } from "@revoltchat/ui";
import { useIntermediate } from "../context/intermediate/Intermediate";
import { modalController } from "../context/modals";
import {
AppContext,
ClientStatus,
@@ -18,7 +18,6 @@ export default function Open() {
const client = useContext(AppContext);
const status = useContext(StatusContext);
const { id } = useParams<{ id: string }>();
const { openScreen } = useIntermediate();
if (status !== ClientStatus.ONLINE) {
return (
@@ -40,7 +39,12 @@ export default function Open() {
client
.user!.openDM()
.then((channel) => history.push(`/channel/${channel?._id}`))
.catch((error) => openScreen({ id: "error", error }));
.catch((error) =>
modalController.push({
type: "error",
error,
}),
);
return;
}
@@ -62,7 +66,12 @@ export default function Open() {
.get(id)
?.openDM()
.then((channel) => history.push(`/channel/${channel?._id}`))
.catch((error) => openScreen({ id: "error", error }));
.catch((error) =>
modalController.push({
type: "error",
error,
}),
);
}
return;

View File

@@ -25,6 +25,7 @@ import { useTranslation } from "../../../lib/i18n";
import { stopPropagation } from "../../../lib/stopPropagation";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { modalController } from "../../../context/modals";
import { FileUploader } from "../../../context/revoltjs/FileUploads";
import { useClient } from "../../../context/revoltjs/RevoltClient";
@@ -366,10 +367,10 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
onClick={(ev) =>
stopPropagation(
ev,
openScreen({
id: "token_reveal",
modalController.push({
type: "show_token",
token: bot.token,
username: user!.username,
name: user!.username,
}),
)
}>

View File

@@ -10,12 +10,11 @@ import { urlBase64ToUint8Array } from "../../../lib/conversion";
import { useApplicationState } from "../../../mobx/State";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { modalController } from "../../../context/modals";
import { AppContext } from "../../../context/revoltjs/RevoltClient";
export const Notifications = observer(() => {
const client = useContext(AppContext);
const { openScreen } = useIntermediate();
const settings = useApplicationState().settings;
const [pushEnabled, setPushEnabled] = useState<undefined | boolean>(
undefined,
@@ -52,8 +51,8 @@ export const Notifications = observer(() => {
await Notification.requestPermission();
if (permission !== "granted") {
return openScreen({
id: "error",
return modalController.push({
type: "error",
error: "DeniedNotification",
});
}