groups: performing same updated storage versioning schema

This commit is contained in:
Hunter Miller 2021-10-21 16:36:31 -05:00
parent 499172e471
commit ba93e4e897
9 changed files with 45 additions and 9 deletions

View File

@ -109,6 +109,8 @@ module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env.LANDSCAPE_SHORTHASH': JSON.stringify(GIT_DESC),
'process.env.LANDSCAPE_STORAGE_VERSION': JSON.stringify(Date.now()),
'process.env.LANDSCAPE_LAST_WIPE': JSON.stringify('2021-10-20'),
'process.env.TUTORIAL_HOST': JSON.stringify('~difmex-passed'),
'process.env.TUTORIAL_GROUP': JSON.stringify('beginner-island'),
'process.env.TUTORIAL_CHAT': JSON.stringify('introduce-yourself-7010'),

View File

@ -73,6 +73,8 @@ module.exports = {
new webpack.DefinePlugin({
'process.env.LANDSCAPE_STREAM': JSON.stringify(process.env.LANDSCAPE_STREAM),
'process.env.LANDSCAPE_SHORTHASH': JSON.stringify(GIT_DESC),
'process.env.LANDSCAPE_STORAGE_VERSION': Date.now().toString(),
'process.env.LANDSCAPE_LAST_WIPE': '2021-10-20',
'process.env.TUTORIAL_HOST': JSON.stringify('~difmex-passed'),
'process.env.TUTORIAL_GROUP': JSON.stringify('beginner-island'),
'process.env.TUTORIAL_CHAT': JSON.stringify('introduce-yourself-7010'),

View File

@ -1,6 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import './register-sw';
import './storage-wipe';
import App from './views/App';
import './wdyr';

View File

@ -568,3 +568,14 @@ export function toHarkPlace(graph: string, index = '') {
path: toHarkPath(graph, index)
};
}
export function createStorageKey(name: string): string {
return `~${window.ship}/${window.desk}/${name}`;
}
// for purging storage with version updates
export function clearStorageMigration<T>() {
return {} as T;
}
export const storageVersion = parseInt(process.env.LANDSCAPE_STORAGE_VERSION, 10);

View File

@ -6,6 +6,7 @@ import { persist } from 'zustand/middleware';
import Urbit, { SubscriptionRequestInterface, FatalError } from '@urbit/http-api';
import { Poke } from '@urbit/api';
import airlock from '~/logic/api';
import { clearStorageMigration, createStorageKey, storageVersion } from '../lib/util';
setAutoFreeze(false);
enablePatches();
@ -73,9 +74,9 @@ export const optReduceState = <S, U>(
export let stateStorageKeys: string[] = [];
export const stateStorageKey = (stateName: string) => {
stateName = `Landscape${stateName}State-${process.env.LANDSCAPE_SHORTHASH}`;
stateStorageKeys = [...new Set([...stateStorageKeys, stateName])];
return stateName;
const key = createStorageKey(`${stateName}State`);
stateStorageKeys = [...new Set([...stateStorageKeys, key])];
return key;
};
(window as any).clearStates = () => {
@ -147,7 +148,9 @@ export const createState = <T extends {}>(
...(typeof properties === 'function' ? (properties as any)(set, get) : properties)
}), {
blacklist,
name: stateStorageKey(name)
name: stateStorageKey(name),
version: storageVersion,
migrate: clearStorageMigration
}));
export async function doOptimistically<A, S extends {}>(state: UseStore<S & BaseState<S>>, action: A, call: (a: A) => Promise<any>, reduce: ((a: A, fn: S & BaseState<S>) => S & BaseState<S>)[]) {

View File

@ -6,7 +6,7 @@ import { persist } from 'zustand/middleware';
import { BackgroundConfig, LeapCategories, RemoteContentPolicy, TutorialProgress, tutorialProgress } from '~/types/local-update';
import airlock from '~/logic/api';
import { bootstrapApi } from '../api/bootstrap';
import { wait } from '~/logic/lib/util';
import { clearStorageMigration, createStorageKey, storageVersion, wait } from '~/logic/lib/util';
export type SubscriptionStatus = 'connected' | 'disconnected' | 'reconnecting';
@ -136,7 +136,9 @@ const useLocalState = create<LocalStateZus>(persist((set, get) => ({
'prevTutStep', 'nextTutStep', 'tutorialRef', 'setTutorialRef', 'subscription',
'errorCount', 'breaks'
],
name: 'localReducer'
name: createStorageKey('local'),
version: storageVersion,
migrate: clearStorageMigration
}));
function withLocalState<P, S extends keyof LocalState, C extends React.ComponentType<P>>(Component: C, stateMemberKeys?: S[]) {

View File

@ -0,0 +1,12 @@
import { createStorageKey } from './logic/lib/util';
const key = createStorageKey(`storage-wipe-${process.env.LANDSCAPE_LAST_WIPE}`);
const wiped = localStorage.getItem(key);
// Loaded before everything, this clears local storage just once.
// Change VITE_LAST_WIPE in .env to date of wipe
if (!wiped) {
localStorage.clear();
localStorage.setItem(key, 'true');
}

View File

@ -3,5 +3,6 @@ import { PatpNoSig } from '@urbit/api';
declare global {
interface Window {
ship: PatpNoSig;
desk: string;
}
}

View File

@ -5,6 +5,7 @@ import React, { ReactElement, useCallback, useEffect, useState } from 'react';
import create from 'zustand';
import { persist } from 'zustand/middleware';
import { useFileUpload } from '~/logic/lib/useFileUpload';
import { createStorageKey, storageVersion, clearStorageMigration } from '~/logic/lib/util';
import { useOurContact } from '~/logic/state/contact';
import { useGraphTimesent } from '~/logic/state/graph';
import ShareProfile from '~/views/apps/chat/components/ShareProfile';
@ -21,7 +22,6 @@ interface useChatStoreType {
setMessage: (message: string) => void;
}
const unsentKey = 'chat-unsent';
export const useChatStore = create<useChatStoreType>(persist((set, get) => ({
id: '',
message: '',
@ -41,8 +41,10 @@ export const useChatStore = create<useChatStoreType>(persist((set, get) => ({
set({ message, messageStore: store });
}
}), {
name: unsentKey,
whitelist: ['messageStore']
whitelist: ['messageStore'],
name: createStorageKey('chat-unsent'),
version: storageVersion,
migrate: clearStorageMigration
}));
interface ChatPaneProps {