Skip to content

Commit

Permalink
Merge pull request #1012 from FAIMS/improve-startup-process
Browse files Browse the repository at this point in the history
Improve startup process - big change still with some loose ends but functional. Manually tested on Android and IOS.
  • Loading branch information
stevecassidy authored Jul 14, 2024
2 parents 6fecba0 + fcb4320 commit cd1f2f4
Show file tree
Hide file tree
Showing 57 changed files with 2,119 additions and 2,305 deletions.
394 changes: 394 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"jsdoc": "^4.0.2",
"jsdom": "^22.1.0",
"jss": "^10.10.0",
"msw": "^2.3.1",
"node-gyp": "^9.3.1",
"type-fest": "^4.20.0"
}
Expand Down
17 changes: 2 additions & 15 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import * as ROUTES from './constants/routes';
import {PrivateRoute} from './constants/privateRouter';
import Index from './gui/pages';
import {SignIn} from './gui/pages/signin';
import {SignInReturnLoader} from './gui/pages/signin-return';
import AboutBuild from './gui/pages/about-build';
import Workspace from './gui/pages/workspace';
import NoteBookList from './gui/pages/notebook_list';
Expand All @@ -41,10 +40,8 @@ import {ThemeProvider, StyledEngineProvider} from '@mui/material/styles';
// https://stackoverflow.com/a/64135466/3562777 temporary solution to remove findDOMNode is depreciated in StrictMode warning
// will be resolved in material-ui v5

import {createdProjects} from './sync/state';
import {ProjectsList} from 'faims3-datamodel';
import theme from './gui/theme';
import {getTokenContentsForRouting} from './users';
import {getTokenContentsForCurrentUser} from './users';

import {useEffect, useState} from 'react';

Expand All @@ -59,19 +56,13 @@ import {TokenContents} from 'faims3-datamodel';
// };

export default function App() {
const projects: ProjectsList = {};

for (const active_id in createdProjects) {
projects[active_id] = createdProjects[active_id].project;
}

const [token, setToken] = useState(null as null | undefined | TokenContents);

// TODO: Rather than returning the contents of a token, we should work out
// what details are actually needed.
useEffect(() => {
const getToken = async () => {
setToken(await getTokenContentsForRouting());
setToken(await getTokenContentsForCurrentUser());
};
getToken();
}, []);
Expand All @@ -93,10 +84,6 @@ export default function App() {
</PrivateRoute>
}
/>
<Route
path={ROUTES.SIGN_IN_RETURN}
Component={SignInReturnLoader}
/>
<Route
path={ROUTES.WORKSPACE}
element={
Expand Down
12 changes: 11 additions & 1 deletion src/buildconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,19 @@ function get_bugsnag_key(): string | false {
return bugsnag_key;
}


Check warning on line 291 in src/buildconfig.ts

View workflow job for this annotation

GitHub Actions / build (20, false)

Delete `⏎`
function get_conductor_url(): string {
const url = import.meta.env.VITE_CONDUCTOR_URL;
if (url) {
return url;
} else {
return 'http://localhost:8154';
}
}

// this should disappear once we have listing activation set up
export const AUTOACTIVATE_LISTINGS = true;

export const CONDUCTOR_URL = get_conductor_url();
export const DEBUG_POUCHDB = include_pouchdb_debugging();
export const DEBUG_APP = include_app_debugging();
export const DIRECTORY_PROTOCOL = directory_protocol();
Expand Down
1 change: 0 additions & 1 deletion src/constants/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {ProjectID, RecordID, RevisionID} from 'faims3-datamodel';

export const INDEX = '/';
export const SIGN_IN = '/signin/';
export const SIGN_IN_RETURN = '/signin-return';

export const NOT_FOUND = '/not-found';
export const WORKSPACE = '/workspace';
Expand Down
40 changes: 1 addition & 39 deletions src/context/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*
* Filename: actions.ts
* Description:
* TODO
* Define interfaces for reducer actions in the context store
*/

import {ProjectObject} from 'faims3-datamodel';
import {Record} from 'faims3-datamodel';
import {AlertColor} from '@mui/material/Alert/Alert';

export enum ActionType {
Expand All @@ -28,14 +26,6 @@ export enum ActionType {
HAS_UNSYNCED_CHANGES,
IS_SYNC_ERROR,

INITIALIZED,

GET_ACTIVE_PROJECT,
DROP_ACTIVE_PROJECT,

GET_ACTIVE_RECORD,
DROP_ACTIVE_RECORD,

SET_LISTINGS_KNOWN,

ADD_ALERT,
Expand All @@ -61,40 +51,12 @@ export interface IS_SYNC_ERROR {
payload: boolean;
}

export interface INITIALIZED {
type: ActionType.INITIALIZED;
payload: undefined;
}

export type SyncingActions =
| INITIALIZED
| IS_SYNCING_UP
| IS_SYNCING_DOWN
| HAS_UNSYNCED_CHANGES
| IS_SYNC_ERROR;

export interface GET_ACTIVE_PROJECT {
type: ActionType.GET_ACTIVE_PROJECT;
payload: ProjectObject | null;
}

export interface DROP_ACTIVE_PROJECT {
type: ActionType.DROP_ACTIVE_PROJECT;
}

export type ProjectActions = GET_ACTIVE_PROJECT | DROP_ACTIVE_PROJECT;

export interface GET_ACTIVE_RECORD {
type: ActionType.GET_ACTIVE_RECORD;
payload: Record | null;
}

export interface DROP_ACTIVE_RECORD {
type: ActionType.DROP_ACTIVE_RECORD;
}

export type RecordActions = GET_ACTIVE_RECORD | DROP_ACTIVE_RECORD;

export interface SET_LISTINGS_KNOWN {
type: ActionType.SET_LISTINGS_KNOWN;
payload: Set<string>;
Expand Down
90 changes: 16 additions & 74 deletions src/context/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,32 @@
*
* Filename: store.tsx
* Description:
* TODO
* Define a global Context store to hold the state of sync and alerts
*/

import React, {createContext, useReducer, Dispatch, useEffect} from 'react';
import React, {
createContext,
useReducer,
Dispatch,
useEffect,
useState,
} from 'react';

import {v4 as uuidv4} from 'uuid';

import {ProjectObject} from 'faims3-datamodel';
import {Record} from 'faims3-datamodel';
import {getSyncStatusCallbacks} from '../utils/status';
import {
ProjectActions,
RecordActions,
SyncingActions,
AlertActions,
ActionType,
} from './actions';
import {SyncingActions, AlertActions, ActionType} from './actions';
import LoadingApp from '../gui/components/loadingApp';
import {initialize} from '../sync/initialize';
import {set_sync_status_callbacks} from '../sync/connection';
import {AlertColor} from '@mui/material/Alert/Alert';

interface InitialStateProps {
initialized: boolean;
isSyncingUp: boolean;
isSyncingDown: boolean;
hasUnsyncedChanges: boolean;
isSyncError: boolean;

active_project: ProjectObject | null;
active_record: Record | null;
alerts: Array<
{
severity: AlertColor;
Expand All @@ -55,22 +50,16 @@ interface InitialStateProps {
}

const InitialState = {
initialized: false,
isSyncingUp: false,
isSyncingDown: false,
hasUnsyncedChanges: false,
isSyncError: false,

active_project: null,
active_record: null,
alerts: [],
};

export interface ContextType {
state: InitialStateProps;
dispatch: Dispatch<
ProjectActions | RecordActions | SyncingActions | AlertActions
>;
dispatch: Dispatch<SyncingActions | AlertActions>;
}

const store = createContext<ContextType>({
Expand All @@ -81,18 +70,10 @@ const store = createContext<ContextType>({
const {Provider} = store;

const StateProvider = (props: any) => {
const [initialized, setInitialized] = useState(false);
const [state, dispatch] = useReducer(
(
state: InitialStateProps,
action: ProjectActions | RecordActions | SyncingActions | AlertActions
) => {
(state: InitialStateProps, action: SyncingActions | AlertActions) => {
switch (action.type) {
case ActionType.INITIALIZED: {
return {
...state,
initialized: true,
};
}
case ActionType.IS_SYNCING_UP: {
return {
...state,
Expand All @@ -117,12 +98,6 @@ const StateProvider = (props: any) => {
isSyncError: action.payload,
};
}
case ActionType.GET_ACTIVE_PROJECT: {
return {...state, active_project: action.payload};
}
case ActionType.DROP_ACTIVE_PROJECT: {
return {...state, active_project: null};
}

case ActionType.ADD_ALERT: {
const alert = {
Expand Down Expand Up @@ -156,32 +131,6 @@ const StateProvider = (props: any) => {
alerts: [...state.alerts, alert],
};
}

// case ActionType.APPEND_RECORD_LIST: {
// return {
// ...state,
// record_list: {
// ...state.record_list,
// [action.payload.project_id]: action.payload.data,
// },
// };
// // return {...state, record_list: action.payload};
// }
// case ActionType.POP_RECORD_LIST: {
// const new_record_list = {
// ...state.record_list[action.payload.project_id],
// };
// action.payload.data_ids.forEach(
// data_id => delete new_record_list[data_id]
// );
// return {
// ...state,
// record_list: {
// ...state.record_list,
// [action.payload.project_id]: new_record_list,
// },
// };
// }
default:
throw new Error();
}
Expand All @@ -193,16 +142,9 @@ const StateProvider = (props: any) => {

useEffect(() => {
initialize()
.then(() =>
setTimeout(
() =>
dispatch({
type: ActionType.INITIALIZED,
payload: undefined,
}),
10000
)
)
.then(() => {
setInitialized(true);
})
.catch(err => {
console.log('Could not initialize: ', err);
dispatch({
Expand All @@ -212,7 +154,7 @@ const StateProvider = (props: any) => {
});
}, []);

if (state.initialized) {
if (initialized) {
return <Provider value={{state, dispatch}}>{props.children}</Provider>;
} else {
return (
Expand Down
Loading

0 comments on commit cd1f2f4

Please sign in to comment.