fix: persist notification preferences and clarify delivery controls

This commit is contained in:
2026-09-06 14:14:46 +03:00
parent 83df706631
commit a25dcb7a5d
8 changed files with 85 additions and 35 deletions
+19 -16
View File
@@ -1,3 +1,4 @@
import {validateReminderPreferences,quietNow} from '../services/reminderPreferences';
import {validateTeam} from '../services/teamData';
import {savedFilterCriteria} from '../services/savedFilterCriteria';
import {mergeServerNotifications,acknowledgeNotifications} from '../services/notifications';
@@ -166,7 +167,7 @@ export const AppProvider = ({ children }) => {
useEffect(() => {
notificationVersion.current++;notificationMutation.current=null;seenServerNotifications.current.clear();setNotificationError(null);setNotificationBusy(false);
aiRunRef.current=null;setAiAnalyzing(false);setAiJobStatus('');
dataRevisions.current={};setTeamError(null);setCompetitorError(null);
dataRevisions.current={};setTeamError(null);setCompetitorError(null);setReminderError(null);
setVeriSenkron(false); setPlan(null); setSaveError(null);
setFavoriteKurumlar([]); setTeamMembers([]); setSavedFilters([]); setCompetitorWatchlist([]);
setReminderSettings(defaultReminder()); setUserProfile(defaultProfile(authUser));
@@ -409,20 +410,22 @@ export const AppProvider = ({ children }) => {
const [vaultDocuments, setVaultDocuments] = useState([]);
const [reminderSettings, setReminderSettings] = useState(defaultReminder);
useEffect(() => {
if (veriSenkron) ilkYazmaDegil('reminder', reminderSettings);
}, [reminderSettings, veriSenkron]);
// Şu an sessiz saat aralığında mıyız (gece yarısını geçen aralıkları da destekler)
const isQuietNow = () => {
if (!reminderSettings.quietEnabled) return false;
const now = new Date();
const cur = now.getHours() * 60 + now.getMinutes();
const [sh, sm] = reminderSettings.quietStart.split(':').map(Number);
const [eh, em] = reminderSettings.quietEnd.split(':').map(Number);
const start = sh * 60 + sm, end = eh * 60 + em;
return start <= end ? cur >= start && cur < end : cur >= start || cur < end;
const reminderSaveLock=useRef(false),reminderCurrent=useRef(reminderSettings);
reminderCurrent.current=reminderSettings;
const [reminderSaving,setReminderSaving]=useState(false),[reminderError,setReminderError]=useState(null);
const saveReminderSettings=async change=>{
if(!authUser||!veriSenkron){setReminderError('Hesap verileri yüklenmeden bildirim ayarları kaydedilemez.');return false;}
if(reminderSaveLock.current)return false;
const session=getToken();reminderSaveLock.current=true;setReminderSaving(true);setReminderError(null);
try {
const next=validateReminderPreferences(typeof change==='function'?change(reminderCurrent.current):change);
const saved=await setUserData('reminder',next,dataRevisions.current.reminder ?? null);
if(getToken()!==session)return false;
dataRevisions.current.reminder=saved.revision;reminderCurrent.current=next;setReminderSettings(next);return true;
}catch(error){if(getToken()===session)setReminderError(error.message);return false;}
finally{reminderSaveLock.current=false;setReminderSaving(false);}
};
const isQuietNow=()=>quietNow(reminderCurrent.current);
const [webhooksConfig, setWebhooksConfig] = useState({
slackWebhookUrl: '',
@@ -580,7 +583,7 @@ export const AppProvider = ({ children }) => {
pushNotification(title,text);
};
const pushNotification=(title,text)=>{
if (isQuietNow() || !reminderSettings.pushEnabled) return;
if (isQuietNow() || !reminderCurrent.current.pushEnabled) return;
try {
if ('Notification' in window && Notification.permission === 'granted') {
new Notification(title, { body: text, icon: '/favicon.ico' });
@@ -826,7 +829,7 @@ export const AppProvider = ({ children }) => {
vaultDocuments,
setVaultDocuments,
reminderSettings,
setReminderSettings,
saveReminderSettings,reminderSaving,reminderError,
webhooksConfig,
setWebhooksConfig,
apiKeys,