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 58c8fc79f4
commit d23912c836
4 changed files with 66 additions and 15 deletions

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,21 +215,26 @@ export function Sessions() {
<hr />
<CategoryButton
onClick={async () => {
// ! FIXME: add to rAuth
const del: string[] = [];
render.forEach((session) => {
if (deviceId !== session._id) {
del.push(session._id);
openScreen({
id: "sessions",
confirm: async () => {
// ! FIXME: add to rAuth
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)"} />}
action={"chevron"}
@@ -247,3 +255,4 @@ export function Sessions() {
</div>
);
}