improve PWA and last room strating

This commit is contained in:
Gregoire Parant 2021-08-04 13:33:58 +02:00
parent 1ad9f5b045
commit 707040b506
6 changed files with 34 additions and 153 deletions

View file

@ -17,6 +17,8 @@ const authToken = "authToken";
const state = "state";
const nonce = "nonce";
const cacheAPIIndex = "workavdenture-cache-v1";
class LocalUserStore {
saveUser(localUser: LocalUser) {
localStorage.setItem("localUser", JSON.stringify(localUser));
@ -116,10 +118,23 @@ class LocalUserStore {
setLastRoomUrl(roomUrl: string): void {
localStorage.setItem(lastRoomUrl, roomUrl.toString());
caches.open(cacheAPIIndex).then((cache) => {
const stringResponse = new Response(JSON.stringify({ roomUrl }));
cache.put(`/${lastRoomUrl}`, stringResponse);
});
}
getLastRoomUrl(): string {
return localStorage.getItem(lastRoomUrl) ?? "";
}
getLastRoomUrlCacheApi(): Promise<string | undefined> {
return caches.open(cacheAPIIndex).then((cache) => {
return cache.match(`/${lastRoomUrl}`).then((res) => {
return res?.json().then((data) => {
return data.roomUrl;
});
});
});
}
setAuthToken(value: string | null) {
value ? localStorage.setItem(authToken, value) : localStorage.removeItem(authToken);