message: Use localforage for storing
diff: import type { Request } from '../types/request';
  import { Message, MessageId, Proceeding } from '../types/proceedings.d';
  -import create from 'zustand';
  -import { devtools, persist } from 'zustand/middleware';
  +import create, { StateCreator, StoreApi } from 'zustand';
  +import { persist, StateStorage } from 'zustand/middleware';
  import { produce } from 'immer';
  import { Privacy, PRIVACY_ACTIONS } from '../Utility/Privacy';
  import type { SetOptional } from 'type-fest';
  import { ErrorException } from '../Utility/errors';
  +import localforage from 'localforage';
  export interface ProceedingsState {
  proceedings: Record<string, Proceeding>;
  @@ -16,15 +17,16 @@ export interface ProceedingsState {
  addAttachment: (id: MessageId, file: unknown) => void;
  removeProceeding: (reference: string) => void;
  clearProceedings: () => void;
  + _hasHydrated: boolean;
  + drink: () => void;
  }
  const id_regex = /^(\d{4,}-[\dA-Za-z]{7,})-(\d+)$/;
  -export const useProceedingsStore = create<ProceedingsState>(
  - devtools(
  - persist(
  +const proceedingsStore = persist<ProceedingsState>(
  (set, get) => ({
  proceedings: {},
  + drink: () => set({ _hasHydrated: true }),
  addProceeding: (proceeding) =>
  Privacy.isAllowed(PRIVACY_ACTIONS.SAVE_MY_REQUESTS) &&
  set(
  @@ -44,10 +46,7 @@ export const useProceedingsStore = create<ProceedingsState>(
  const existing_ids = Object.keys(state.proceedings[message.reference].messages);
  const message_id_number =
  existing_ids.length > 0
  - ? Number.parseInt(
  - existing_ids[existing_ids.length - 1].match(id_regex)?.[2] || '1',
  - 10
  - ) + 1
  + ? Number.parseInt(existing_ids[existing_ids.length - 1].match(id_regex)?.[2] || '1', 10) + 1
  : 0;
  const message_id_string = `${message.reference}-${`${message_id_number}`.padStart(2, '0')}`;
  message.id = message_id_string;
  @@ -73,16 +72,25 @@ export const useProceedingsStore = create<ProceedingsState>(
  })
  ),
  clearProceedings: () => set({ proceedings: {} }),
  + _hasHydrated: false,
  }),
  {
  name: 'Datenanfragen.de-proceedings',
  version: 0,
  - getStorage: () => localStorage,
  + getStorage: () =>
  + localforage.createInstance({ name: 'Datenanfragen.de', storeName: 'proceedings' }) as StateStorage, // This casting is necessary, because zustand only accepts Promise<void> as a retunr type, while localforage returns Promise<string>, the APIs are otherwise compatible.
  + onRehydrateStorage: () => (state) => state && state.drink(),
  }
  - )
  - )
  );
  +const { devtools } =
  + process.env.NODE_ENV === 'development' ? require('zustand/middleware') : { devtools: (d: unknown) => d };
  +
  +export const useProceedingsStore =
  + process.env.NODE_ENV === 'development'
  + ? create<ProceedingsState>(devtools(proceedingsStore))
  + : create<ProceedingsState>(proceedingsStore);
  +
  export const proceedingFromRequest = (request: Request, subject?: string, content?: string): Proceeding => ({
  reference: request.reference,
  messages: {
  