import {proxy} from "valtio"; import Database from '../db' import Api from "../services/api"; const store = proxy({ notifications: [], newNotificationBadge: 0 }) const getNotificationsFromDB = () => { store.notifications.length = 0 store.notifications.push( ...Database.getAllKeys() .filter(key => key.startsWith('notification.')) .map(key => JSON.parse(Database.getString(key))) ) } export const getNotifications = () => { Api.getNotifications() .then(() => getNotificationsFromDB()) .catch(() => getNotificationsFromDB()) } export const increaseNewNotificationBadge = () => { store.newNotificationBadge++ } export default store