utils.tsx 919 B

12345678910111213141516171819202122232425262728293031
  1. import {EventId, EventIdStatus} from '../types';
  2. import {valueSuggestions} from '../utils';
  3. import {fetchFromStorage, saveToStorage} from './localStorage';
  4. function fetchSourceGroupData() {
  5. const fetchedSourceGroupData = fetchFromStorage();
  6. if (!fetchedSourceGroupData) {
  7. const sourceGroupData: Parameters<typeof saveToStorage>[0] = {
  8. eventId: '',
  9. sourceSuggestions: valueSuggestions,
  10. };
  11. saveToStorage(sourceGroupData);
  12. return sourceGroupData;
  13. }
  14. return fetchedSourceGroupData;
  15. }
  16. function saveToSourceGroupData(eventId: EventId, sourceSuggestions = valueSuggestions) {
  17. switch (eventId.status) {
  18. case EventIdStatus.LOADING:
  19. break;
  20. case EventIdStatus.LOADED:
  21. saveToStorage({eventId: eventId.value, sourceSuggestions});
  22. break;
  23. default:
  24. saveToStorage({eventId: '', sourceSuggestions});
  25. }
  26. }
  27. export {fetchSourceGroupData, saveToSourceGroupData};