diff --git a/app/assets/javascripts/directives/views/sessionsModal.tsx b/app/assets/javascripts/directives/views/sessionsModal.tsx index 57c24a50fcd..08f3906e3d3 100644 --- a/app/assets/javascripts/directives/views/sessionsModal.tsx +++ b/app/assets/javascripts/directives/views/sessionsModal.tsx @@ -1,6 +1,11 @@ import { AppState } from '@/ui_models/app_state'; import { PureViewCtrl } from '@/views'; -import { SNApplication, RemoteSession, UuidString } from '@standardnotes/snjs'; +import { + SNApplication, + RemoteSession, + SessionStrings, + UuidString, +} from '@standardnotes/snjs'; import { autorun, IAutorunOptions, IReactionPublic } from 'mobx'; import { render, FunctionComponent } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; @@ -16,16 +21,20 @@ function useAutorun(view: (r: IReactionPublic) => any, opts?: IAutorunOptions) { useEffect(() => autorun(view, opts), []); } +type Session = RemoteSession & { + revoking?: true; +}; + function useSessions( application: SNApplication ): [ - RemoteSession[], + Session[], () => void, boolean, (uuid: UuidString) => Promise, string ] { - const [sessions, setSessions] = useState([]); + const [sessions, setSessions] = useState([]); const [lastRefreshDate, setLastRefreshDate] = useState(Date.now()); const [refreshing, setRefreshing] = useState(true); const [errorMessage, setErrorMessage] = useState(''); @@ -41,7 +50,7 @@ function useSessions( setErrorMessage('An unknown error occured while loading sessions.'); } } else { - const sessions = response as RemoteSession[]; + const sessions = response as Session[]; setSessions(sessions); setErrorMessage(''); } @@ -54,9 +63,21 @@ function useSessions( } async function revokeSession(uuid: UuidString) { + const responsePromise = application.revokeSession(uuid); + let sessionsBeforeRevoke = sessions; - setSessions(sessions.filter((session) => session.uuid !== uuid)); - const response = await application.revokeSession(uuid); + + const sessionsDuringRevoke = sessions.slice(); + const toRemoveIndex = sessions.findIndex( + (session) => session.uuid === uuid + ); + sessionsDuringRevoke[toRemoveIndex] = { + ...sessionsDuringRevoke[toRemoveIndex], + revoking: true, + }; + setSessions(sessionsDuringRevoke); + + const response = await responsePromise; if ('error' in response) { if (response.error?.message) { setErrorMessage(response.error?.message); @@ -64,6 +85,8 @@ function useSessions( setErrorMessage('An unknown error occured while revoking the session.'); } setSessions(sessionsBeforeRevoke); + } else { + setSessions(sessions.filter((session) => session.uuid !== uuid)); } } @@ -84,7 +107,7 @@ const SessionsModal: FunctionComponent<{ errorMessage, ] = useSessions(application); - const [revokingSessionUuid, setRevokingSessionUuid] = useState(''); + const [confirmRevokingSessionUuid, setRevokingSessionUuid] = useState(''); const closeRevokeSessionAlert = () => setRevokingSessionUuid(''); const cancelRevokeRef = useRef(); @@ -146,6 +169,7 @@ const SessionsModal: FunctionComponent<{

diff --git a/package.json b/package.json index 6584bf7b54e..1659fd0713b 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "@reach/alert-dialog": "^0.12.1", "@reach/dialog": "^0.12.1", "@standardnotes/sncrypto-web": "^1.2.9", - "@standardnotes/snjs": "^2.0.32", + "@standardnotes/snjs": "^2.0.35", "babel-loader": "^8.2.2", "mobx": "^6.0.4", "preact": "^10.5.7" diff --git a/yarn.lock b/yarn.lock index 6046c273c25..556ffb8079f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1045,10 +1045,10 @@ "@standardnotes/sncrypto-common" "^1.2.7" libsodium-wrappers "^0.7.8" -"@standardnotes/snjs@^2.0.32": - version "2.0.32" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.32.tgz#7742e3cb08ee560b5b7cf06e526ebc19ff2a81ba" - integrity sha512-SnbOqGwx5H59HjFSzBKT/1Wh2zAAcx+QSQeYDyKjZKNYN0g8JvirzL0FpoLTxa15BRTl2mG073eIyFsEtx8LFA== +"@standardnotes/snjs@^2.0.35": + version "2.0.35" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.35.tgz#9e9c3058ebbfc9af7a5fc3ae18497f02a9b1e71b" + integrity sha512-uA4HXorgiV8yFGN1dtO52istUudnc3ZzEQiFLgf0bkKvA0wH3Xt+R9bBviYAdIBkTBKHCyGsBdsCiKr1QS/X9g== dependencies: "@standardnotes/sncrypto-common" "^1.2.9"