ce82e2a4ab
Co-authored-by: Kandev Agent <agent@kandev.dev>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useAppStore } from "@/components/state-provider";
|
|
import { useToast } from "@/components/toast-provider";
|
|
|
|
/** Surfaces sidebar preference sync errors. Mount once inside the app's ToastProvider. */
|
|
export function useSidebarViewsSync() {
|
|
const syncError = useAppStore((s) => s.sidebarViews.syncError);
|
|
const taskPrefsSyncError = useAppStore((s) => s.sidebarTaskPrefs.syncError);
|
|
const clearError = useAppStore((s) => s.clearSidebarSyncError);
|
|
const clearTaskPrefsError = useAppStore((s) => s.clearSidebarTaskPrefsSyncError);
|
|
const { toast } = useToast();
|
|
const { t } = useTranslation("sidebar");
|
|
|
|
useEffect(() => {
|
|
if (!syncError) return;
|
|
toast({ title: t("sidebar:views"), description: syncError, variant: "error" });
|
|
clearError();
|
|
}, [syncError, t, toast, clearError]);
|
|
|
|
useEffect(() => {
|
|
if (!taskPrefsSyncError) return;
|
|
toast({
|
|
title: t("sidebar:taskPreferences"),
|
|
description: taskPrefsSyncError,
|
|
variant: "error",
|
|
});
|
|
clearTaskPrefsError();
|
|
}, [taskPrefsSyncError, t, toast, clearTaskPrefsError]);
|
|
}
|