commit 702b5abf368cd9b79ff43ebe25848314f0cbdcc7
parent b1f851364b5b78bc7f37027b6f1b0b7cd655ffc3
Author: Sunny <122193933+Sunny-JP@users.noreply.github.com>
Date: Fri, 30 Jan 2026 10:18:18 +0900
Merge pull request #37 from Sunny-JP/v4-sunny-dev
V4 sunny dev
Diffstat:
3 files changed, 19 insertions(+), 65 deletions(-)
diff --git a/src/app/api/tap/route.ts b/src/app/api/tap/route.ts
@@ -8,7 +8,7 @@ export const runtime = 'edge';
export async function POST(request: Request) {
try {
const body = await request.json();
- const { tapTime, isPushEnabled, onesignalId, ticket1Time, ticket2Time } = body;
+ const { tapTime, ticket1Time, ticket2Time } = body;
const authHeader = request.headers.get('Authorization');
const supabase = createClient(
@@ -28,20 +28,13 @@ export async function POST(request: Request) {
updated_at: new Date().toISOString()
};
- if (isPushEnabled !== undefined) {
- upsertData.is_push_enabled = Boolean(isPushEnabled);
- }
-
- if (onesignalId) {
- upsertData.onesignal_id = onesignalId;
- }
-
if (ticket1Time !== undefined) upsertData.ticket1_time = ticket1Time ? new Date(ticket1Time).toISOString() : null;
if (ticket2Time !== undefined) upsertData.ticket2_time = ticket2Time ? new Date(ticket2Time).toISOString() : null;
+ let newHistory: string[] = [];
if (tapTime) {
const { data: profile } = await supabase.from('profiles').select('tap_history').eq('id', user.id).single();
- const newHistory = [...(profile?.tap_history || [])];
+ newHistory = [...(profile?.tap_history || [])];
const tapDate = new Date(tapTime);
tapDate.setMilliseconds(0);
@@ -50,16 +43,9 @@ export async function POST(request: Request) {
upsertData.tap_history = newHistory;
}
- // DBへの書き込みを実行
await supabase.from('profiles').upsert(upsertData);
- const { data: currentProfile } = await supabase
- .from('profiles')
- .select('is_push_enabled')
- .eq('id', user.id)
- .single();
-
- if (tapTime && currentProfile?.is_push_enabled && shouldScheduleNotification(new Date(tapTime))) {
+ if (tapTime && shouldScheduleNotification(new Date(tapTime))) {
const sendAfter = new Date(tapTime);
sendAfter.setSeconds(0, 0);
sendAfter.setHours(sendAfter.getHours() + 3);
@@ -88,7 +74,8 @@ export async function POST(request: Request) {
}
}
- return NextResponse.json({ success: true });
+ return NextResponse.json({ success: true, history: newHistory });
+
} catch (error: any) {
console.error("API Error:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
diff --git a/src/app/page.tsx b/src/app/page.tsx
@@ -111,29 +111,16 @@ export default function Home() {
try {
const { data: { session } } = await supabase.auth.getSession();
-
- let isPushEnabled = undefined;
- let onesignalId = undefined;
-
- try {
- if (typeof window !== 'undefined' && OneSignal.User?.PushSubscription) {
- isPushEnabled = OneSignal.User.PushSubscription.optedIn;
- onesignalId = OneSignal.User.PushSubscription.id;
- }
- } catch (osError) {
- console.warn("OneSignal state access failed, proceeding with sync:", osError);
- }
+ if (!session) return;
const res = await fetch('/api/tap', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- 'Authorization': `Bearer ${session?.access_token}`
+ 'Authorization': `Bearer ${session.access_token}`
},
body: JSON.stringify({
tapTime: tapISO,
- isPushEnabled: isPushEnabled,
- onesignalId: onesignalId,
ticket1Time: t1ISO,
ticket2Time: t2ISO
})
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx
@@ -44,9 +44,8 @@ const Settings = () => {
setIsPushLoading(true);
try {
- if (!OneSignal.User) throw new Error("通知システムが未ロードです。");
+ if (typeof window === 'undefined' || !OneSignal.User) return;
- // 1. 通知権限のリクエスト (booleanが返る)
const isAllowed = await OneSignal.Notifications.requestPermission();
if (!isAllowed) {
alert("通知がブロックされています。ブラウザの設定で許可してください。");
@@ -54,41 +53,22 @@ const Settings = () => {
}
const { data: { session } } = await supabase.auth.getSession();
- if (!session?.user) throw new Error("ログインが必要です。");
-
- // 2. ユーザーIDを同期
- await OneSignal.login(session.user.id);
+ if (session?.user) {
+ await OneSignal.login(session.user.id);
+ }
- // 3. 購読状態の切り替え (optedIn を使用)
- const isCurrentlyOptedIn = OneSignal.User.PushSubscription.optedIn;
- if (isCurrentlyOptedIn) {
+ const isOptedIn = OneSignal.User.PushSubscription.optedIn;
+ if (isOptedIn) {
await OneSignal.User.PushSubscription.optOut();
- alert("通知をOFFにしました。");
+ alert("この端末の通知をOFFにしました。");
} else {
await OneSignal.User.PushSubscription.optIn();
- alert("通知をONにしました!");
+ alert("この端末の通知をONにしました!");
}
- // 4. 最新の状態をDBに同期
- // optOut/In 後の最新の状態を取得して送信
- const finalOptedIn = OneSignal.User.PushSubscription.optedIn;
- const currentSubscriptionId = OneSignal.User.PushSubscription.id;
-
- await fetch('/api/tap', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${session.access_token}`
- },
- body: JSON.stringify({
- onesignalId: currentSubscriptionId,
- isPushEnabled: finalOptedIn // ここで真偽値を送る
- })
- });
-
- } catch (e: any) {
- console.error("Notification Error:", e);
- alert(e.message);
+ } catch (e) {
+ console.error("Notification setting error:", e);
+ alert("設定の切り替えに失敗しました。");
} finally {
setIsPushLoading(false);
}