Add feature interest buttons to dares and quiz

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 4.5 committed 2026-01-01 18:42:56 +00:00
1 parent 3b445597f0
commit feb7657562
4 files changed
+288 -6

No files matched your search

@@ -0,0 +1,79 @@
import { useState, useEffect, useCallback } from "react";
import { supabase } from "../lib/supabase";
import { useAuthStore } from "../store";
export function useFeatureInterest(featureName: string) {
const [isInterested, setIsInterested] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [isToggling, setIsToggling] = useState(false);
const user = useAuthStore((state) => state.user);
// Fetch current interest status
useEffect(() => {
async function fetchInterest() {
if (!user?.id) {
setIsLoading(false);
return;
}
const { data } = await supabase
.from("feature_interests")
.select("id")
.eq("user_id", user.id)
.eq("feature_name", featureName)
.maybeSingle();
setIsInterested(!!data);
setIsLoading(false);
}
fetchInterest();
}, [user?.id, featureName]);
const toggleInterest = useCallback(async () => {
if (!user?.id || isToggling) return;
setIsToggling(true);
const wasInterested = isInterested;
// Optimistic update
setIsInterested(!wasInterested);
try {
if (wasInterested) {
// Remove interest
const { error } = await supabase
.from("feature_interests")
.delete()
.eq("user_id", user.id)
.eq("feature_name", featureName);
if (error) throw error;
} else {
// Add interest
const { error } = await supabase
.from("feature_interests")
.insert({
user_id: user.id,
feature_name: featureName,
});
if (error) throw error;
}
} catch (error) {
console.error("Error toggling feature interest:", error);
// Revert on error
setIsInterested(wasInterested);
} finally {
setIsToggling(false);
}
}, [user?.id, featureName, isInterested, isToggling]);
return {
isInterested,
isLoading,
isToggling,
toggleInterest,
isAuthenticated: !!user?.id,
};
}