Add question types, nudge feature, and share modal

- Add new question card components (photo, audio, text, who-likely)
- Add share preview modal for matches
- Add nudge notification system with rate limiting
- Add session-based notification improvements
- Add match confetti celebration animation
- Update onboarding flow with paywall tracking
- Remove deprecated swipe card and tutorial components
- Update GlassCard/GlassInput to use solid backgrounds
- Fix routing issues after packs screen removal
This commit is contained in:
jjbrunton committed 2026-01-25 19:17:39 +00:00
1 parent 8612b16b93
commit 1daf386765
114 files changed
+14877 -7911

No files matched your search

+146 -94
View File
@@ -7,18 +7,48 @@ const corsHeaders = {
};
type Answer = "yes" | "no" | "maybe";
type MatchType = "yes_yes" | "yes_maybe" | "maybe_maybe";
type MatchType = "yes_yes" | "yes_maybe" | "maybe_maybe" | "both_answered";
type QuestionType = "swipe" | "text_answer" | "audio" | "photo" | "who_likely";
type ResponseData =
| { type: "text_answer"; text: string }
| { type: "audio"; media_path: string; duration_seconds: number }
| { type: "photo"; media_path: string }
| { type: "who_likely"; chosen_user_id: string };
interface SubmitResponseBody {
question_id: string;
answer: Answer;
response_data?: ResponseData; // Optional for backwards compatibility
}
function calculateMatch(a1: Answer, a2: Answer): MatchType | null {
if (a1 === "no" || a2 === "no") return null;
if (a1 === "yes" && a2 === "yes") return "yes_yes";
if (a1 === "maybe" && a2 === "maybe") return "maybe_maybe";
return "yes_maybe";
interface Question {
id: string;
question_type?: QuestionType;
// ... other fields
}
function calculateMatchType(question: Question, answer1: Answer, answer2: Answer): MatchType | null {
// For swipe questions (or legacy questions without type), use existing logic
if (!question.question_type || question.question_type === "swipe") {
if (answer1 === "no" || answer2 === "no") return null;
if (answer1 === "yes" && answer2 === "yes") return "yes_yes";
if (answer1 === "maybe" && answer2 === "maybe") return "maybe_maybe";
return "yes_maybe";
}
// For text/audio/photo questions: match if both answered positively
if (["text_answer", "audio", "photo"].includes(question.question_type)) {
if (answer1 === "no" || answer2 === "no") return null;
return "both_answered";
}
// For who_likely: always matches when both answered
if (question.question_type === "who_likely") {
return "both_answered";
}
return null;
}
Deno.serve(async (req) => {
@@ -54,7 +84,7 @@ Deno.serve(async (req) => {
}
// Parse request body
const { question_id, answer }: SubmitResponseBody = await req.json();
const { question_id, answer, response_data }: SubmitResponseBody = await req.json();
if (!question_id || !answer) {
return new Response(
@@ -63,6 +93,20 @@ Deno.serve(async (req) => {
);
}
// Fetch the question to get its type
const { data: question, error: questionError } = await supabase
.from("questions")
.select("id, question_type")
.eq("id", question_id)
.single();
if (questionError || !question) {
return new Response(
JSON.stringify({ error: "Question not found" }),
{ status: 404, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
// Get user's profile and couple
const { data: profile, error: profileError } = await supabase
.from("profiles")
@@ -70,88 +114,89 @@ Deno.serve(async (req) => {
.eq("id", user.id)
.single();
if (profileError || !profile?.couple_id) {
return new Response(
JSON.stringify({ error: "User is not in a couple" }),
{ status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
// Check if this is a new response or an edit (edits bypass daily limit)
const { data: existingResponse } = await supabase
.from("responses")
.select("id")
.eq("user_id", user.id)
.eq("question_id", question_id)
.maybeSingle();
const isNewResponse = !existingResponse;
// Enforce daily response limit for new responses only
if (isNewResponse) {
// Check if user has premium access
const { data: hasPremiumData } = await supabase.rpc("has_premium_access", {
check_user_id: user.id,
});
const hasPremium = hasPremiumData === true;
// If non-premium, check daily limit
if (!hasPremium) {
// Get daily limit from app_config
const { data: configData } = await supabase
.from("app_config")
.select("daily_response_limit")
.limit(1)
.maybeSingle();
const dailyLimit = configData?.daily_response_limit || 0;
// If daily limit is enabled (> 0), check if user has reached it
if (dailyLimit > 0) {
// Calculate UTC day boundaries
const now = new Date();
const todayStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const tomorrowStart = new Date(todayStart);
tomorrowStart.setUTCDate(tomorrowStart.getUTCDate() + 1);
// Count responses created today (UTC)
const { count: dailyCount } = await supabase
.from("responses")
.select("*", { count: "exact", head: true })
.eq("user_id", user.id)
.gte("created_at", todayStart.toISOString())
.lt("created_at", tomorrowStart.toISOString());
// If over limit, reject
if ((dailyCount || 0) >= dailyLimit) {
return new Response(
JSON.stringify({
error: "Daily response limit reached",
daily_limit: dailyLimit,
reset_at: tomorrowStart.toISOString(),
}),
{ status: 429, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
}
}
}
// Save or update response
const { data: response, error: responseError } = await supabase
.from("responses")
.upsert(
{
user_id: user.id,
question_id,
couple_id: profile.couple_id,
answer,
},
{ onConflict: "user_id,question_id" }
)
.select()
.single();
if (profileError || !profile?.couple_id) {
return new Response(
JSON.stringify({ error: "User is not in a couple" }),
{ status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
// Check if this is a new response or an edit (edits bypass daily limit)
const { data: existingResponse } = await supabase
.from("responses")
.select("id")
.eq("user_id", user.id)
.eq("question_id", question_id)
.maybeSingle();
const isNewResponse = !existingResponse;
// Enforce daily response limit for new responses only
if (isNewResponse) {
// Check if user has premium access
const { data: hasPremiumData } = await supabase.rpc("has_premium_access", {
check_user_id: user.id,
});
const hasPremium = hasPremiumData === true;
// If non-premium, check daily limit
if (!hasPremium) {
// Get daily limit from app_config
const { data: configData } = await supabase
.from("app_config")
.select("daily_response_limit")
.limit(1)
.maybeSingle();
const dailyLimit = configData?.daily_response_limit || 0;
// If daily limit is enabled (> 0), check if user has reached it
if (dailyLimit > 0) {
// Calculate UTC day boundaries
const now = new Date();
const todayStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const tomorrowStart = new Date(todayStart);
tomorrowStart.setUTCDate(tomorrowStart.getUTCDate() + 1);
// Count responses created today (UTC)
const { count: dailyCount } = await supabase
.from("responses")
.select("*", { count: "exact", head: true })
.eq("user_id", user.id)
.gte("created_at", todayStart.toISOString())
.lt("created_at", tomorrowStart.toISOString());
// If over limit, reject
if ((dailyCount || 0) >= dailyLimit) {
return new Response(
JSON.stringify({
error: "Daily response limit reached",
daily_limit: dailyLimit,
reset_at: tomorrowStart.toISOString(),
}),
{ status: 429, headers: { ...corsHeaders, "Content-Type": "application/json" } }
);
}
}
}
}
// Save or update response
const { data: response, error: responseError } = await supabase
.from("responses")
.upsert(
{
user_id: user.id,
question_id,
couple_id: profile.couple_id,
answer,
response_data: response_data ?? null,
},
{ onConflict: "user_id,question_id" }
)
.select()
.single();
if (responseError) {
return new Response(
@@ -163,7 +208,7 @@ Deno.serve(async (req) => {
// Check for partner's response
const { data: partnerResponse } = await supabase
.from("responses")
.select("answer")
.select("answer, response_data, user_id")
.eq("couple_id", profile.couple_id)
.eq("question_id", question_id)
.neq("user_id", user.id)
@@ -172,9 +217,15 @@ Deno.serve(async (req) => {
let match = null;
if (partnerResponse) {
const matchType = calculateMatch(answer, partnerResponse.answer as Answer);
const matchType = calculateMatchType(question as Question, answer, partnerResponse.answer as Answer);
if (matchType) {
// Build response_summary for 'both_answered' matches
const responseSummary = (matchType === "both_answered") ? {
[user.id]: response_data ?? null,
[partnerResponse.user_id]: partnerResponse.response_data ?? null,
} : null;
// Create or update match
const { data: newMatch, error: matchError } = await supabase
.from("matches")
@@ -184,6 +235,7 @@ Deno.serve(async (req) => {
question_id,
match_type: matchType,
is_new: true,
response_summary: responseSummary,
},
{ onConflict: "couple_id,question_id" }
)
@@ -196,9 +248,9 @@ Deno.serve(async (req) => {
if (!matchError) {
match = newMatch;
// Match push notifications are queued via a Postgres trigger
// (pending_match_notifications) to allow short digesting.
// Match push notifications are queued via a Postgres trigger
// (pending_match_notifications) to allow short digesting.
}
}
}