From 8c6d6ae5e21b6de99819d85b37a353aa6d058393 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Sat, 5 Nov 2022 02:28:16 +0100 Subject: [PATCH] resolve the TODOs --- src/components/overview.tsx | 5 ++--- src/contexts/timecontext.tsx | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/overview.tsx b/src/components/overview.tsx index fe8e6dc..ff47d3d 100644 --- a/src/components/overview.tsx +++ b/src/components/overview.tsx @@ -4,7 +4,7 @@ import { Card } from 'primereact/card'; import { DataTable } from 'primereact/datatable'; import { Password } from 'primereact/password'; import { AuthContext } from '../contexts'; -import { Auth } from '../services'; +import { Auth, Session } from '../services'; import { BackendReturnStatus } from '../types'; import { Column } from 'primereact/column'; @@ -18,9 +18,8 @@ export const Overview: React.FC = () => { const regenerateKey = async () => { Auth.refreshRadarScopeKey().then((status) => { if (status === BackendReturnStatus.Unauthorized) { + Session.setLastShownComponent('/overview'); Auth.triggerLoginFlow(); - // TODO reload user data in auth - // TODO store current URL and get back after login } else if (status === BackendReturnStatus.Failure) { setStatusMessage({ error: true, diff --git a/src/contexts/timecontext.tsx b/src/contexts/timecontext.tsx index 24a3851..1482f02 100644 --- a/src/contexts/timecontext.tsx +++ b/src/contexts/timecontext.tsx @@ -1,5 +1,6 @@ -import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'; -import { Auth, System } from '../services'; +import React, { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'; +import { useLocation } from 'react-router-dom'; +import { Auth, Session, System } from '../services'; import { BackendReturnStatus } from '../types'; const TimeContext = React.createContext<{ @@ -9,14 +10,19 @@ const TimeContext = React.createContext<{ export const TimeProvider = ({ children }: { children: any }) => { const [offset, setOffset] = useState(0); + const location = useLocation(); + const refLocation = useRef(); + + refLocation.current = location.pathname; useEffect(() => { const estimateTimeOffset = async () => { System.timestamp().then((response) => { if (response.status === BackendReturnStatus.Unauthorized) { + if (refLocation.current) { + Session.setLastShownComponent(refLocation.current); + } Auth.triggerLoginFlow(); - // TODO reload user data in auth - // TODO store current URL and get back after login } else if (response.status === BackendReturnStatus.Ok) { // calculate the time offset (not accurate) between the server and the client to show "correct" times const clientTimeUtc = new Date().getTime()