utils.tsx 949 B

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