weiterer fortschritt mit tamagui und dem neuen mobile event admin
This commit is contained in:
@@ -22,6 +22,8 @@ const EventContext = React.createContext<EventContextValue | undefined>(undefine
|
||||
|
||||
export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
const { status } = useAuth();
|
||||
const [manualEvents, setManualEvents] = React.useState<TenantEvent[]>([]);
|
||||
const [manualAttempted, setManualAttempted] = React.useState(false);
|
||||
const [storedSlug, setStoredSlug] = React.useState<string | null>(() => {
|
||||
if (typeof window === 'undefined') {
|
||||
return null;
|
||||
@@ -51,8 +53,28 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
initialData: [],
|
||||
});
|
||||
|
||||
const events = React.useMemo(() => (authReady ? fetchedEvents : []), [authReady, fetchedEvents]);
|
||||
const isLoading = authReady ? queryLoading : status === 'loading';
|
||||
const events = React.useMemo(
|
||||
() => (authReady ? (manualEvents.length ? manualEvents : fetchedEvents) : []),
|
||||
[authReady, fetchedEvents, manualEvents]
|
||||
);
|
||||
const isLoading = authReady ? queryLoading || (!manualAttempted && manualEvents.length === 0 && fetchedEvents.length === 0) : status === 'loading';
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!authReady || manualAttempted || queryLoading) {
|
||||
return;
|
||||
}
|
||||
if (fetchedEvents.length > 0 && !isError) {
|
||||
return;
|
||||
}
|
||||
setManualAttempted(true);
|
||||
getEvents({ force: true })
|
||||
.then((list) => {
|
||||
setManualEvents(list ?? []);
|
||||
})
|
||||
.catch(() => {
|
||||
setManualEvents([]);
|
||||
});
|
||||
}, [authReady, fetchedEvents.length, isError, manualAttempted, queryLoading]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!events.length || typeof window === 'undefined') {
|
||||
|
||||
Reference in New Issue
Block a user