Skip to content

Commit

Permalink
fix: recoil default
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Oct 4, 2023
1 parent a1c0b72 commit b501c61
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 102 deletions.
6 changes: 4 additions & 2 deletions dashboard/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ export default function ContextedApp() {
const [recoilKey, setRecoilKey] = useState(0);
return (
<RecoilRoot key={recoilKey}>
<RecoilNexus />
<App resetRecoil={() => setRecoilKey((k) => k + 1)} />
<React.Suspense fallback={<div>CHAAARGEMENT</div>}>
<RecoilNexus />
<App resetRecoil={() => setRecoilKey((k) => k + 1)} />
</React.Suspense>
</RecoilRoot>
);
}
151 changes: 80 additions & 71 deletions dashboard/src/components/DataLoader.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dashboard/src/recoil/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setCacheItem } from '../services/dataManagement';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { organisationState } from './auth';
import { looseUuidRegex } from '../utils';
Expand All @@ -8,7 +8,13 @@ import { capture } from '../services/sentry';
const collectionName = 'action';
export const actionsState = atom({
key: collectionName,
default: [],
default: selector({
key: 'action/default',
get: async () => {
const cache = await getCacheItemDefaultValue('action', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/comments.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'comment';
export const commentsState = atom({
key: collectionName,
default: [],
default: selector({
key: 'comment/default',
get: async () => {
const cache = await getCacheItemDefaultValue('comment', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/groups.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { setCacheItem } from '../services/dataManagement';
import { atom, selectorFamily } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector, selectorFamily } from 'recoil';
import type { GroupInstance } from '../types/group';
import type { UUIDV4 } from '../types/uuid';

const collectionName = 'group';
export const groupsState = atom<GroupInstance[]>({
key: collectionName,
default: [],
default: selector({
key: 'group/default',
get: async () => {
const cache = await getCacheItemDefaultValue('group', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/passages.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'passage';
export const passagesState = atom({
key: collectionName,
default: [],
default: selector({
key: 'passage/default',
get: async () => {
const cache = await getCacheItemDefaultValue('passage', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
10 changes: 8 additions & 2 deletions dashboard/src/recoil/persons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setCacheItem } from '../services/dataManagement';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector, useRecoilValue } from 'recoil';
import { organisationState } from './auth';
import { toast } from 'react-toastify';
Expand All @@ -9,7 +9,13 @@ import type { PredefinedField, CustomField } from '../types/field';
const collectionName = 'person';
export const personsState = atom<PersonInstance[]>({
key: collectionName,
default: [],
default: selector({
key: 'person/default',
get: async () => {
const cache = await getCacheItemDefaultValue('person', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/places.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'place';
export const placesState = atom({
key: collectionName,
default: [],
default: selector({
key: 'place/default',
get: async () => {
const cache = await getCacheItemDefaultValue('place', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/relPersonPlace.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'relPersonPlace';
export const relsPersonPlaceState = atom({
key: collectionName,
default: [],
default: selector({
key: 'relPersonPlace/default',
get: async () => {
const cache = await getCacheItemDefaultValue('relPersonPlace', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/rencontres.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'rencontre';
export const rencontresState = atom({
key: collectionName,
default: [],
default: selector({
key: 'rencontre/default',
get: async () => {
const cache = await getCacheItemDefaultValue('rencontre', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
10 changes: 8 additions & 2 deletions dashboard/src/recoil/reports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setCacheItem } from '../services/dataManagement';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { capture } from '../services/sentry';
import { organisationState } from './auth';
Expand All @@ -8,7 +8,13 @@ import { toast } from 'react-toastify';
const collectionName = 'report';
export const reportsState = atom({
key: collectionName,
default: [],
default: selector({
key: 'report/default',
get: async () => {
const cache = await getCacheItemDefaultValue('report', []);
return cache;
},
}),
effects: [
({ onSet }) =>
onSet(async (newValue) => {
Expand Down
12 changes: 9 additions & 3 deletions dashboard/src/recoil/territory.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { setCacheItem } from '../services/dataManagement';
import { atom } from 'recoil';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { atom, selector } from 'recoil';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'territory';
export const territoriesState = atom({
key: collectionName,
default: [],
default: selector({
key: 'territory/default',
get: async () => {
const cache = await getCacheItemDefaultValue('territory', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down
10 changes: 8 additions & 2 deletions dashboard/src/recoil/territoryObservations.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { organisationState } from './auth';
import { atom, selector } from 'recoil';
import { setCacheItem } from '../services/dataManagement';
import { getCacheItemDefaultValue, setCacheItem } from '../services/dataManagement';
import { looseUuidRegex } from '../utils';
import { toast } from 'react-toastify';
import { capture } from '../services/sentry';

const collectionName = 'territory-observation';
export const territoryObservationsState = atom({
key: collectionName,
default: [],
default: selector({
key: 'territory-observation/default',
get: async () => {
const cache = await getCacheItemDefaultValue('territory-observation', []);
return cache;
},
}),
effects: [({ onSet }) => onSet(async (newValue) => setCacheItem(collectionName, newValue))],
});

Expand Down

0 comments on commit b501c61

Please sign in to comment.