- 안드로이드 알림 설정 AppBridge 추가
- KeyIn Request 필드 수정
This commit is contained in:
@@ -16,7 +16,15 @@ import { useAppBridge } from '@/hooks/useAppBridge';
|
||||
|
||||
export const SettingPage = () => {
|
||||
let userInfo = useStore.getState().UserStore.userInfo;
|
||||
const { isPushNotificationEnabled, openAppSettings, logout, getLoginType } = useAppBridge();
|
||||
const {
|
||||
isPushNotificationEnabled,
|
||||
openAppSettings,
|
||||
logout,
|
||||
getLoginType,
|
||||
getNotificationSetting,
|
||||
setNotificationSetting: updateNotificationSetting,
|
||||
isAndroid
|
||||
} = useAppBridge();
|
||||
|
||||
useSetHeaderTitle('설정');
|
||||
useSetHeaderType(HeaderType.LeftArrow);
|
||||
@@ -31,6 +39,7 @@ export const SettingPage = () => {
|
||||
const {mutateAsync: appAlarmConsent} = useAppAlarmConsentMutation();
|
||||
|
||||
const [pushNotificationEnabled, setPushNotificationEnabled] = useState<boolean>(false);
|
||||
const [notificationSetting, setNotificationSetting] = useState<boolean>(true);
|
||||
const [alarmSetting, setAlarmSetting] = useState<Record<string, boolean>>({
|
||||
'21': false,
|
||||
'11': false,
|
||||
@@ -65,7 +74,74 @@ export const SettingPage = () => {
|
||||
const onClickPushNotificationToggle = () => {
|
||||
openAppSettings();
|
||||
};
|
||||
|
||||
|
||||
// 알림 설정 로드 (Android만)
|
||||
const loadNotificationSetting = useCallback(async () => {
|
||||
if (!isAndroid) {
|
||||
console.log('[loadNotificationSetting] Not Android, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[loadNotificationSetting] Calling getNotificationSetting()...');
|
||||
const enabled = await getNotificationSetting();
|
||||
console.log('[loadNotificationSetting] Received value from bridge:', enabled);
|
||||
console.log('[loadNotificationSetting] Type of enabled:', typeof enabled);
|
||||
|
||||
setNotificationSetting(enabled);
|
||||
console.log('[loadNotificationSetting] State updated to:', enabled);
|
||||
} catch (error) {
|
||||
console.error('[loadNotificationSetting] Failed to load notification setting:', error);
|
||||
}
|
||||
}, [isAndroid, getNotificationSetting]);
|
||||
|
||||
// 알림 설정 토글 핸들러 (Android만)
|
||||
const onClickNotificationSettingToggle = useCallback(async () => {
|
||||
if (!isAndroid) {
|
||||
console.log('[onClickNotificationSettingToggle] Not Android, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const newValue = !notificationSetting;
|
||||
console.log('[onClickNotificationSettingToggle] to save:', newValue);
|
||||
|
||||
const result = await updateNotificationSetting(newValue);
|
||||
console.log('[onClickNotificationSettingToggle] result:', result);
|
||||
|
||||
// ✅ needsPermission이 true이면 설정 화면으로 이동한 것
|
||||
if (result && typeof result === 'object' && 'needsPermission' in result && result.needsPermission) {
|
||||
console.log('[onClickNotificationSettingToggle] Permission needed - opened settings');
|
||||
// 설정이 변경되지 않았으므로 상태 유지
|
||||
return;
|
||||
}
|
||||
|
||||
// ✅ 성공한 경우에만 상태 업데이트
|
||||
if (result && typeof result === 'object' && 'enabled' in result) {
|
||||
setNotificationSetting(result.enabled);
|
||||
console.log('[onClickNotificationSettingToggle] State updated to:', result.enabled);
|
||||
} else {
|
||||
// Fallback
|
||||
setNotificationSetting(newValue);
|
||||
console.log('[onClickNotificationSettingToggle] State updated to (fallback):', newValue);
|
||||
}
|
||||
|
||||
// ✅ 저장 후 바로 다시 읽어서 확인
|
||||
console.log('[onClickNotificationSettingToggle] Verifying saved value...');
|
||||
const verifyValue = await getNotificationSetting();
|
||||
console.log('[onClickNotificationSettingToggle] Verified value:', verifyValue);
|
||||
|
||||
if (verifyValue !== result?.enabled && !result?.needsPermission) {
|
||||
console.error('[onClickNotificationSettingToggle] WARNING: Saved value != Verified value', {
|
||||
saved: result?.enabled,
|
||||
verified: verifyValue
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[onClickNotificationSettingToggle] Failed to update notification setting:', error);
|
||||
}
|
||||
}, [isAndroid, notificationSetting, updateNotificationSetting, getNotificationSetting]);
|
||||
|
||||
const callAppAlarmFind = () => {
|
||||
if(userInfo.usrid){
|
||||
let params: AppAlarmFindParams = {
|
||||
@@ -115,16 +191,19 @@ export const SettingPage = () => {
|
||||
callAppAlarmFind();
|
||||
checkPushNotificationStatus();
|
||||
loadLoginType();
|
||||
loadNotificationSetting(); // ✅ 추가
|
||||
|
||||
// 앱이 포어그라운드로 돌아올 때 푸시 알림 권한 상태 재확인
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
checkPushNotificationStatus();
|
||||
loadNotificationSetting(); // ✅ 추가
|
||||
}
|
||||
};
|
||||
|
||||
const handleFocus = () => {
|
||||
checkPushNotificationStatus();
|
||||
loadNotificationSetting(); // ✅ 추가
|
||||
};
|
||||
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
@@ -134,20 +213,28 @@ export const SettingPage = () => {
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
window.removeEventListener('focus', handleFocus);
|
||||
};
|
||||
}, [checkPushNotificationStatus, loadLoginType]);
|
||||
}, [checkPushNotificationStatus, loadLoginType, loadNotificationSetting]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<main className="pop">
|
||||
<div className="sub-wrap">
|
||||
{/* ✅ Android일 때는 앱 내 설정, 아니면 시스템 권한 표시 */}
|
||||
<div className="settings-header">
|
||||
<div className="settings-title">알림 수신 설정</div>
|
||||
<label className="settings-switch" onClick={onClickPushNotificationToggle}>
|
||||
<label className="settings-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={pushNotificationEnabled}
|
||||
checked={isAndroid ? notificationSetting : pushNotificationEnabled}
|
||||
readOnly
|
||||
onClick={(e) => e.preventDefault()}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
if (isAndroid) {
|
||||
onClickNotificationSettingToggle();
|
||||
} else {
|
||||
onClickPushNotificationToggle();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span className="slider"></span>
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user