|
@@ -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<number>(0);
|
|
|
+ const location = useLocation();
|
|
|
+ const refLocation = useRef<string>();
|
|
|
+
|
|
|
+ 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()
|