mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-21 22:50:59 -05:00
feat(sessions): Add confirmation prompt (#575)
Reopening of issue #572 Fixes issue #42 Translations added on PR 31 of revolt/translations Co-authored-by: Paul Makles <paulmakles@gmail.com>
This commit is contained in:
parent
93ba922536
commit
ac0c100846
4 changed files with 66 additions and 15 deletions
|
@ -24,6 +24,7 @@ export type Screen =
|
||||||
| { id: "clipboard"; text: string }
|
| { id: "clipboard"; text: string }
|
||||||
| { id: "token_reveal"; token: string; username: string }
|
| { id: "token_reveal"; token: string; username: string }
|
||||||
| { id: "external_link_prompt"; link: string }
|
| { id: "external_link_prompt"; link: string }
|
||||||
|
| { id: "sessions", confirm: () => void }
|
||||||
| {
|
| {
|
||||||
id: "_prompt";
|
id: "_prompt";
|
||||||
question: Children;
|
question: Children;
|
||||||
|
|
|
@ -9,7 +9,8 @@ import { InputModal } from "./modals/Input";
|
||||||
import { OnboardingModal } from "./modals/Onboarding";
|
import { OnboardingModal } from "./modals/Onboarding";
|
||||||
import { PromptModal } from "./modals/Prompt";
|
import { PromptModal } from "./modals/Prompt";
|
||||||
import { SignedOutModal } from "./modals/SignedOut";
|
import { SignedOutModal } from "./modals/SignedOut";
|
||||||
import {ExternalLinkModal} from "./modals/ExternalLinkPrompt";
|
import { ExternalLinkModal} from "./modals/ExternalLinkPrompt";
|
||||||
|
import { SessionsModal } from "./modals/SessionsPrompt";
|
||||||
import { TokenRevealModal } from "./modals/TokenReveal";
|
import { TokenRevealModal } from "./modals/TokenReveal";
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
|
@ -40,6 +41,8 @@ export default function Modals({ screen, openScreen }: Props) {
|
||||||
return <OnboardingModal onClose={onClose} {...screen} />;
|
return <OnboardingModal onClose={onClose} {...screen} />;
|
||||||
case "external_link_prompt":
|
case "external_link_prompt":
|
||||||
return <ExternalLinkModal onClose={onClose} {...screen} />;
|
return <ExternalLinkModal onClose={onClose} {...screen} />;
|
||||||
|
case "sessions":
|
||||||
|
return <SessionsModal onClose={onClose} {...screen} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
38
src/context/intermediate/modals/SessionsPrompt.tsx
Normal file
38
src/context/intermediate/modals/SessionsPrompt.tsx
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { Text } from "preact-i18n";
|
||||||
|
|
||||||
|
import Modal from "../../../components/ui/Modal";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onClose: () => void;
|
||||||
|
confirm: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SessionsModal({ onClose, confirm}: Props) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
visible={true}
|
||||||
|
onClose={onClose}
|
||||||
|
title={<Text id={"app.special.modals.sessions.title"} />}
|
||||||
|
actions={[
|
||||||
|
{
|
||||||
|
onClick: () => {
|
||||||
|
onClose()
|
||||||
|
},
|
||||||
|
confirmation: true,
|
||||||
|
contrast: true,
|
||||||
|
accent: true,
|
||||||
|
children: <Text id="app.special.modals.actions.back"/>
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onClick: () => {
|
||||||
|
confirm()
|
||||||
|
onClose()
|
||||||
|
},
|
||||||
|
confirmation: true,
|
||||||
|
children: <Text id="app.special.modals.sessions.accept"/>
|
||||||
|
}
|
||||||
|
]}>
|
||||||
|
<Text id="app.special.modals.sessions.short" /> <br />
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import { useContext, useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
import { dayjs } from "../../../context/Locale";
|
import { dayjs } from "../../../context/Locale";
|
||||||
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
import { AppContext } from "../../../context/revoltjs/RevoltClient";
|
||||||
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
||||||
|
|
||||||
import Button from "../../../components/ui/Button";
|
import Button from "../../../components/ui/Button";
|
||||||
import Preloader from "../../../components/ui/Preloader";
|
import Preloader from "../../../components/ui/Preloader";
|
||||||
|
@ -39,6 +40,8 @@ export function Sessions() {
|
||||||
const [attemptingDelete, setDelete] = useState<string[]>([]);
|
const [attemptingDelete, setDelete] = useState<string[]>([]);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
|
const { openScreen } = useIntermediate();
|
||||||
|
|
||||||
function switchPage(to: string) {
|
function switchPage(to: string) {
|
||||||
history.replace(`/settings/${to}`);
|
history.replace(`/settings/${to}`);
|
||||||
}
|
}
|
||||||
|
@ -212,21 +215,26 @@ export function Sessions() {
|
||||||
<hr />
|
<hr />
|
||||||
<CategoryButton
|
<CategoryButton
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
// ! FIXME: add to rAuth
|
openScreen({
|
||||||
const del: string[] = [];
|
id: "sessions",
|
||||||
render.forEach((session) => {
|
confirm: async () => {
|
||||||
if (deviceId !== session._id) {
|
// ! FIXME: add to rAuth
|
||||||
del.push(session._id);
|
const del: string[] = [];
|
||||||
|
render.forEach((session) => {
|
||||||
|
if (deviceId !== session._id) {
|
||||||
|
del.push(session._id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setDelete(del);
|
||||||
|
|
||||||
|
for (const id of del) {
|
||||||
|
await client.api.delete(`/auth/session/${id as ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSessions(sessions.filter((x) => x._id === deviceId));
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
setDelete(del);
|
|
||||||
|
|
||||||
for (const id of del) {
|
|
||||||
await client.api.delete(`/auth/session/${id as ""}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
setSessions(sessions.filter((x) => x._id === deviceId));
|
|
||||||
}}
|
}}
|
||||||
icon={<LogOut size={24} color={"var(--error)"} />}
|
icon={<LogOut size={24} color={"var(--error)"} />}
|
||||||
action={"chevron"}
|
action={"chevron"}
|
||||||
|
@ -247,3 +255,4 @@ export function Sessions() {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue