-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
ViewerStreams
internals to allow a single list ot tabs
The way that `ViewerStreams` was set up made it hard to mix components that depending on `RSC_CHUNK` together with those that may instead need `RSC_REQUEST` and `RSC_RESPONSE`. The `FlightResponse` component was sort of dictating a split between them. It needed to change because I wanted to put "Headers" in the same row as everything else, like the parsed chunks and the network graph. I ended up changing a few other things as well, like removing a bunch of `useMemo` (to make the code simpler, and because the compiler is going to help).
- Loading branch information
1 parent
3f22306
commit 9e70239
Showing
25 changed files
with
659 additions
and
792 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,68 @@ | ||
import { createContext } from "react"; | ||
import { | ||
ReactNode, | ||
createContext, | ||
useContext, | ||
useEffect, | ||
useState, | ||
useTransition, | ||
} from "react"; | ||
|
||
export const EndTimeContext = createContext<number>(Infinity); | ||
const EndTimeContext = createContext<{ | ||
endTime: number; | ||
visibleEndTime: number; | ||
changeEndTime: (value: number) => void; | ||
isPending: boolean; | ||
}>({ | ||
endTime: Infinity, | ||
visibleEndTime: Infinity, | ||
changeEndTime: () => {}, | ||
isPending: false, | ||
}); | ||
|
||
export function EndTimeProvider({ | ||
maxEndTime, | ||
children, | ||
}: { | ||
maxEndTime: number; | ||
children: ReactNode; | ||
}) { | ||
const [endTime, setEndTime] = useState(Infinity); | ||
const [visibleEndTime, setVisibleEndTime] = useState(endTime); | ||
const [isPending, startTransition] = useTransition(); | ||
|
||
const changeEndTime = (value: number) => { | ||
setVisibleEndTime(value); | ||
startTransition(() => { | ||
setEndTime(value); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (endTime !== maxEndTime) { | ||
changeEndTime(maxEndTime); | ||
} | ||
}, [maxEndTime]); | ||
|
||
return ( | ||
<EndTimeContext.Provider | ||
value={{ | ||
endTime, | ||
visibleEndTime, | ||
changeEndTime, | ||
isPending, | ||
}} | ||
> | ||
<div>{children}</div> | ||
</EndTimeContext.Provider> | ||
); | ||
} | ||
|
||
export function useEndTime() { | ||
const context = useContext(EndTimeContext); | ||
|
||
if (context === undefined) { | ||
throw new Error("useEndTime must be used within a EndTimeContext.Provider"); | ||
} | ||
|
||
return context; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
packages/core/src/components/FlightResponseSelector.stories.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.