feat: refine session workflow with global state, quick tasting, and statistics

This commit is contained in:
2025-12-18 17:19:38 +01:00
parent 7f600698e4
commit ca1621e765
14 changed files with 399 additions and 116 deletions

View File

@@ -7,6 +7,7 @@ import { getStorageUrl } from '@/lib/supabase';
import { useSearchParams } from 'next/navigation';
import { validateSession } from '@/services/validate-session';
import { useI18n } from '@/i18n/I18nContext';
import { useSession } from '@/context/SessionContext';
import { shortenCategory } from '@/lib/format';
interface Bottle {
@@ -121,21 +122,24 @@ interface BottleGridProps {
export default function BottleGrid({ bottles }: BottleGridProps) {
const { t } = useI18n();
const { activeSession } = useSession();
const searchParams = useSearchParams();
const sessionId = searchParams.get('session_id');
const sessionIdFromUrl = searchParams.get('session_id');
const effectiveSessionId = activeSession?.id || sessionIdFromUrl;
const [validatedSessionId, setValidatedSessionId] = useState<string | null>(null);
React.useEffect(() => {
const checkSession = async () => {
if (sessionId) {
const isValid = await validateSession(sessionId);
setValidatedSessionId(isValid ? sessionId : null);
if (effectiveSessionId) {
const isValid = await validateSession(effectiveSessionId);
setValidatedSessionId(isValid ? effectiveSessionId : null);
} else {
setValidatedSessionId(null);
}
};
checkSession();
}, [sessionId]);
}, [effectiveSessionId]);
const [searchQuery, setSearchQuery] = useState('');
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);