Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kentcdodds/lineage

src/ui/refresh-state.ts

33 lines · 739 B · TypeScript
export type RefreshPresentation = {
	showFullPageLoading: boolean
	statusUpdating: boolean
	treatAsOffline: boolean
}

export function whileRefreshing(hasCachedSeries: boolean): RefreshPresentation {
	return {
		showFullPageLoading: !hasCachedSeries,
		statusUpdating: hasCachedSeries,
		treatAsOffline: false,
	}
}

export function afterRefresh(input: {
	hasCachedSeries: boolean
	fetchSucceeded: boolean
	networkOnline: boolean
}): RefreshPresentation {
	if (input.fetchSucceeded) {
		return {
			showFullPageLoading: false,
			statusUpdating: false,
			treatAsOffline: false,
		}
	}

	return {
		showFullPageLoading: !input.hasCachedSeries,
		statusUpdating: false,
		treatAsOffline: !input.networkOnline || input.hasCachedSeries,
	}
}