feat: refine session workflow with global state, quick tasting, and statistics
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user