-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
11 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/app/[...parts]/_page/NpmDiff/DiffFiles/DiffFile/DiffFile.skeleton.tsx
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Box, Skeleton } from "@chakra-ui/react"; | ||
import CollapsableBorderBox from "^/components/CollapsableBorderBox"; | ||
import contentVisibility from "^/lib/utils/contentVisibility"; | ||
import { DiffFileHeaderSkeleton } from "./DiffFileHeader"; | ||
import { Decoration } from "./react-diff-view"; | ||
|
||
const FakeCodeRow = ({ | ||
length, | ||
indent, | ||
}: { | ||
length: number; | ||
indent: number; | ||
}) => ( | ||
<Skeleton | ||
marginTop="1em" | ||
marginLeft={indent * 2 + "em"} | ||
marginBottom="1em" | ||
height="0.5em" | ||
width={length + "em"} | ||
/> | ||
); | ||
|
||
export default function DiffFileSkeleton() { | ||
return ( | ||
<CollapsableBorderBox | ||
css={{ | ||
label: "DiffFile", | ||
margin: "1em 0", | ||
fontsize: "16px", | ||
...contentVisibility("700px"), | ||
}} | ||
header={<DiffFileHeaderSkeleton />} | ||
> | ||
<Box | ||
borderWidth="1px 0" | ||
background="gray.700" | ||
padding="10px" | ||
lineHeight={1.6} | ||
fontSize="16px" | ||
> | ||
<Skeleton height="0.5em" margin="0.5em 0" width="10em" /> | ||
</Box> | ||
<Box paddingLeft="3em"> | ||
<FakeCodeRow length={8} indent={0} /> | ||
<FakeCodeRow length={14} indent={0} /> | ||
<FakeCodeRow length={10} indent={0} /> | ||
<FakeCodeRow length={4} indent={1} /> | ||
<FakeCodeRow length={8} indent={2} /> | ||
<FakeCodeRow length={2} indent={1} /> | ||
<FakeCodeRow length={4} indent={0} /> | ||
</Box> | ||
</CollapsableBorderBox> | ||
); | ||
} |
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
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
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,5 @@ | ||
import DiffFile from "./DiffFile"; | ||
import DiffFile, { DiffFileProps } from "./DiffFile"; | ||
import DiffFileSkeleton from "./DiffFile.skeleton"; | ||
|
||
export default DiffFile; | ||
export { type DiffFileProps, DiffFileSkeleton }; |
10 changes: 10 additions & 0 deletions
10
src/app/[...parts]/_page/NpmDiff/DiffFiles/DiffFiles.skeleton.tsx
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Box } from "@chakra-ui/react"; | ||
import { DiffFileSkeleton } from "./DiffFile"; | ||
|
||
export default function DiffFilesSkeleton() { | ||
return ( | ||
<Box css={{ label: "DiffFiles", contain: "content", minWidth: "100%" }}> | ||
<DiffFileSkeleton /> | ||
</Box> | ||
); | ||
} |
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,4 +1,5 @@ | ||
import DiffFiles, { DiffFilesProps } from "./DiffFiles"; | ||
import DiffFilesSkeleton from "./DiffFiles.skeleton"; | ||
|
||
export type { DiffFilesProps }; | ||
export { type DiffFilesProps, DiffFilesSkeleton }; | ||
export default DiffFiles; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import { | ||
Box, | ||
BoxProps, | ||
HStack, | ||
Skeleton, | ||
useBreakpointValue, | ||
} from "@chakra-ui/react"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { Suspense } from "react"; | ||
import { ViewType } from "react-diff-view"; | ||
import { DIFF_TYPE_PARAM_NAME } from "../paramNames"; | ||
import { DiffFilesSkeleton } from "./DiffFiles"; | ||
import ViewTypeSwitch from "./ViewTypeSwitch"; | ||
|
||
export interface NpmDiffSkeletonProps extends BoxProps {} | ||
|
||
const NpmDiffSkeleton = (props: NpmDiffSkeletonProps) => { | ||
const searchParams = useSearchParams(); | ||
// Even if the initial value and the first breakpoint value is the same, | ||
// the component will re-render. This means it will _always_ render twice | ||
// even when it shouldn't have to. | ||
// We work around this by memoizing the rendering of the component. | ||
const defaultViewType = useBreakpointValue<ViewType>( | ||
{ | ||
base: "unified", | ||
lg: "split", | ||
}, | ||
// We assume that most users are on a computer so default to "lg". | ||
// We could use something like https://github.com/kaimallea/isMobile | ||
// but that means cache should be different for desktop/mobile | ||
"lg", | ||
)!; | ||
|
||
const viewType = | ||
// If specified in URL, use that | ||
(searchParams?.get(DIFF_TYPE_PARAM_NAME) === "split" && "split") || | ||
(searchParams?.get(DIFF_TYPE_PARAM_NAME) === "unified" && "unified") || | ||
// If not, use default based on screen size | ||
defaultViewType; | ||
|
||
return ( | ||
<Box {...props}> | ||
<HStack width="100%" justifyContent="space-between" {...props}> | ||
<Skeleton width={400} height="0.5rem" /> | ||
<Suspense> | ||
<ViewTypeSwitch currentViewType={viewType} /> | ||
</Suspense> | ||
</HStack> | ||
<DiffFilesSkeleton /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default NpmDiffSkeleton; |
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
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