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:
Daesun 2022-05-07 16:31:53 -04:00 committed by GitHub
parent 93ba922536
commit ac0c100846
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 15 deletions

View file

@ -24,6 +24,7 @@ export type Screen =
| { id: "clipboard"; text: string }
| { id: "token_reveal"; token: string; username: string }
| { id: "external_link_prompt"; link: string }
| { id: "sessions", confirm: () => void }
| {
id: "_prompt";
question: Children;

View file

@ -10,6 +10,7 @@ import { OnboardingModal } from "./modals/Onboarding";
import { PromptModal } from "./modals/Prompt";
import { SignedOutModal } from "./modals/SignedOut";
import { ExternalLinkModal} from "./modals/ExternalLinkPrompt";
import { SessionsModal } from "./modals/SessionsPrompt";
import { TokenRevealModal } from "./modals/TokenReveal";
export interface Props {
@ -40,6 +41,8 @@ export default function Modals({ screen, openScreen }: Props) {
return <OnboardingModal onClose={onClose} {...screen} />;
case "external_link_prompt":
return <ExternalLinkModal onClose={onClose} {...screen} />;
case "sessions":
return <SessionsModal onClose={onClose} {...screen} />;
}
return null;

View 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>
)
}

View file

@ -20,6 +20,7 @@ import { useContext, useEffect, useState } from "preact/hooks";
import { dayjs } from "../../../context/Locale";
import { AppContext } from "../../../context/revoltjs/RevoltClient";
import { useIntermediate } from "../../../context/intermediate/Intermediate";
import Button from "../../../components/ui/Button";
import Preloader from "../../../components/ui/Preloader";
@ -39,6 +40,8 @@ export function Sessions() {
const [attemptingDelete, setDelete] = useState<string[]>([]);
const history = useHistory();
const { openScreen } = useIntermediate();
function switchPage(to: string) {
history.replace(`/settings/${to}`);
}
@ -212,6 +215,9 @@ export function Sessions() {
<hr />
<CategoryButton
onClick={async () => {
openScreen({
id: "sessions",
confirm: async () => {
// ! FIXME: add to rAuth
const del: string[] = [];
render.forEach((session) => {
@ -227,6 +233,8 @@ export function Sessions() {
}
setSessions(sessions.filter((x) => x._id === deviceId));
}
})
}}
icon={<LogOut size={24} color={"var(--error)"} />}
action={"chevron"}
@ -247,3 +255,4 @@ export function Sessions() {
</div>
);
}