import React, { useState } from "react"; import { View, Text, Modal, TouchableOpacity, ActivityIndicator, useColorScheme, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { Subject } from "../services/api"; import { useAuth } from "../context/AuthContext"; interface Props { subject: Subject | null; // null = closed onClose: () => void; } export default function SubjectSheet({ subject, onClose }: Props) { const dark = useColorScheme() === "dark"; const { isSubscribed, subscribe, unsubscribe, user } = useAuth(); const [loading, setLoading] = useState(false); if (!subject) return null; const subscribed = isSubscribed(subject.id); const accent = dark ? "#E07B45" : "#C4622D"; const toggle = async () => { setLoading(true); try { if (subscribed) await unsubscribe(subject.id); else await subscribe(subject.id); } finally { setLoading(false); } }; return ( {/* Backdrop */} {/* Sheet — stop tap propagation */} { }}> {/* Drag handle */} {/* Group pill */} {/* Subject name */} {subject.name} {subscribed ? "You're subscribed to this subject." : "Subscribe to see this subject in your feed."} {/* Subscribe / Unsubscribe button */} {user ? ( {loading ? ( ) : ( <> {subscribed ? "Unsubscribe" : "Subscribe"} )} ) : ( Sign in to subscribe to subjects. )} ); }