Switch prefs to dexie
This commit is contained in:
		
							parent
							
								
									23d275acec
								
							
						
					
					
						commit
						effc1f42eb
					
				
					 5 changed files with 61 additions and 44 deletions
				
			
		| 
						 | 
				
			
			@ -92,21 +92,24 @@ const App = () => {
 | 
			
		|||
    // Define hooks: Note that the order of the hooks is important. The "loading" hooks
 | 
			
		||||
    // must be before the "saving" hooks.
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
        // Load subscriptions
 | 
			
		||||
        const subscriptions = repository.loadSubscriptions();
 | 
			
		||||
        const selectedSubscriptionId = repository.loadSelectedSubscriptionId();
 | 
			
		||||
        setSubscriptions(subscriptions);
 | 
			
		||||
        const load = async () => {
 | 
			
		||||
            // Load subscriptions
 | 
			
		||||
            const subscriptions = repository.loadSubscriptions();
 | 
			
		||||
            const selectedSubscriptionId = await repository.getSelectedSubscriptionId();
 | 
			
		||||
            setSubscriptions(subscriptions);
 | 
			
		||||
 | 
			
		||||
        // Set selected subscription
 | 
			
		||||
        const maybeSelectedSubscription = subscriptions.get(selectedSubscriptionId);
 | 
			
		||||
        if (maybeSelectedSubscription) {
 | 
			
		||||
            setSelectedSubscription(maybeSelectedSubscription);
 | 
			
		||||
        }
 | 
			
		||||
            // Set selected subscription
 | 
			
		||||
            const maybeSelectedSubscription = subscriptions.get(selectedSubscriptionId);
 | 
			
		||||
            if (maybeSelectedSubscription) {
 | 
			
		||||
                setSelectedSubscription(maybeSelectedSubscription);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        // Poll all subscriptions
 | 
			
		||||
        subscriptions.forEach((subscriptionId, subscription) => {
 | 
			
		||||
            poll(subscription);
 | 
			
		||||
        });
 | 
			
		||||
            // Poll all subscriptions
 | 
			
		||||
            subscriptions.forEach((subscriptionId, subscription) => {
 | 
			
		||||
                poll(subscription);
 | 
			
		||||
            });
 | 
			
		||||
        };
 | 
			
		||||
        load();
 | 
			
		||||
    }, [/* initial render */]);
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
        const notificationClickFallback = (subscription) => setSelectedSubscription(subscription);
 | 
			
		||||
| 
						 | 
				
			
			@ -124,7 +127,7 @@ const App = () => {
 | 
			
		|||
    useEffect(() => repository.saveSubscriptions(subscriptions), [subscriptions]);
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
        const subscriptionId = (selectedSubscription) ? selectedSubscription.id : "";
 | 
			
		||||
        repository.saveSelectedSubscriptionId(subscriptionId)
 | 
			
		||||
        repository.setSelectedSubscriptionId(subscriptionId)
 | 
			
		||||
    }, [selectedSubscription]);
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ const Preferences = (props) => {
 | 
			
		|||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const Notifications = (props) => {
 | 
			
		||||
const Notifications = () => {
 | 
			
		||||
    return (
 | 
			
		||||
        <Card sx={{p: 3}}>
 | 
			
		||||
            <Typography variant="h5">
 | 
			
		||||
| 
						 | 
				
			
			@ -60,10 +60,12 @@ const Notifications = (props) => {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
const MinPriority = () => {
 | 
			
		||||
    const [minPriority, setMinPriority] = useState(repository.getMinPriority());
 | 
			
		||||
    const handleChange = (ev) => {
 | 
			
		||||
        setMinPriority(ev.target.value);
 | 
			
		||||
        repository.setMinPriority(ev.target.value);
 | 
			
		||||
    const minPriority = useLiveQuery(() => repository.getMinPriority());
 | 
			
		||||
    const handleChange = async (ev) => {
 | 
			
		||||
        await repository.setMinPriority(ev.target.value);
 | 
			
		||||
    }
 | 
			
		||||
    if (!minPriority) {
 | 
			
		||||
        return null; // While loading
 | 
			
		||||
    }
 | 
			
		||||
    return (
 | 
			
		||||
        <Pref title="Minimum priority">
 | 
			
		||||
| 
						 | 
				
			
			@ -81,10 +83,12 @@ const MinPriority = () => {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
const DeleteAfter = () => {
 | 
			
		||||
    const [deleteAfter, setDeleteAfter] = useState(repository.getDeleteAfter());
 | 
			
		||||
    const handleChange = (ev) => {
 | 
			
		||||
        setDeleteAfter(ev.target.value);
 | 
			
		||||
        repository.setDeleteAfter(ev.target.value);
 | 
			
		||||
    const deleteAfter = useLiveQuery(async () => repository.getDeleteAfter());
 | 
			
		||||
    const handleChange = async (ev) => {
 | 
			
		||||
        await repository.setDeleteAfter(ev.target.value);
 | 
			
		||||
    }
 | 
			
		||||
    if (!deleteAfter) {
 | 
			
		||||
        return null; // While loading
 | 
			
		||||
    }
 | 
			
		||||
    return (
 | 
			
		||||
        <Pref title="Delete notifications">
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +105,6 @@ const DeleteAfter = () => {
 | 
			
		|||
    )
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const PrefGroup = (props) => {
 | 
			
		||||
    return (
 | 
			
		||||
        <div style={{
 | 
			
		||||
| 
						 | 
				
			
			@ -159,7 +162,7 @@ const DefaultServer = (props) => {
 | 
			
		|||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const Users = (props) => {
 | 
			
		||||
const Users = () => {
 | 
			
		||||
    const [dialogKey, setDialogKey] = useState(0);
 | 
			
		||||
    const [dialogOpen, setDialogOpen] = useState(false);
 | 
			
		||||
    const users = useLiveQuery(() => db.users.toArray());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue