Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | 6x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 51x 1x 50x 31x 19x 38x 4x 60x 60x 60x 60x 60x 60x 60x 60x | import { Box, Stack, SxProps } from "@mui/material";
import { PencilIcon, XIcon } from "@phosphor-icons/react";
import LoadingSpinner from "@components/Snipper/LoadingSpinner";
import GiveButton from "@shared/Button/GiveButton";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import GiveText from "@shared/Text/GiveText";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useAppTheme } from "@theme/v2/Provider";
import type { VersionHistoryItem } from "../../types";
import HistoryListItem from "./HistoryListItem";
export interface HistoryContentProps {
versions: VersionHistoryItem[];
isLoading?: boolean;
isError?: boolean;
/** versionID of the version currently being viewed (highlighted row). */
activeVersionID?: number;
onSelectVersion: (versionID: number) => void;
onClose: () => void;
onEdit?: () => void;
editDisabled?: boolean;
isEditLoading?: boolean;
/** Sticky offset / height anchor so the panel sits under the page banner. */
bannerHeight?: number;
/** Desktop slide-in state. */
isOpen?: boolean;
}
const getDesktopWidth = () => {
const width = window.innerWidth;
Iif (width >= 2560) return 400;
Iif (width >= 1440) return 300;
return 264;
};
function HistoryHeader({ onClose }: { onClose: () => void }) {
const { palette } = useAppTheme();
const { isMobileView } = useCustomThemeV2();
return (
<Box
sx={{
padding: isMobileView ? "20px" : "16px 20px",
borderBottom: `1px solid ${palette.border?.primary}`,
...(!isMobileView && { flexShrink: 0 }),
}}
>
<Stack direction="row" justifyContent="space-between" alignItems="center">
<GiveText variant="bodyM" color="primary">
History
</GiveText>
<GiveIconButton
Icon={XIcon}
onClick={onClose}
variant="ghost"
size="small"
/>
</Stack>
</Box>
);
}
function HistoryBody({
versions,
isLoading,
isError,
activeVersionID,
onSelectVersion,
}: Pick<
HistoryContentProps,
"versions" | "isLoading" | "isError" | "activeVersionID" | "onSelectVersion"
>) {
const { palette } = useAppTheme();
const { isMobileView } = useCustomThemeV2();
const desktopScrollStyles = isMobileView
? {}
: {
minHeight: 0,
"&::-webkit-scrollbar": { width: "6px" },
"&::-webkit-scrollbar-thumb": {
backgroundColor: palette.primitive?.neutral?.[110],
borderRadius: "10px",
},
};
const renderState = () => {
if (isLoading) return <LoadingSpinner />;
if (isError) {
return (
<Box sx={{ padding: "24px 20px" }}>
<GiveText variant="bodyS" color="secondary">
Couldn't load version history. Please try again.
</GiveText>
</Box>
);
}
if (versions.length === 0) {
return (
<Box sx={{ padding: "24px 20px" }}>
<GiveText variant="bodyS" color="secondary">
No previous versions yet.
</GiveText>
</Box>
);
}
return versions.map((item, index) => (
<HistoryListItem
key={item.versionID}
item={item}
isCurrent={index === 0}
isActive={item.versionID === activeVersionID}
showConnector={index !== versions.length - 1}
onSelect={() => onSelectVersion(item.versionID)}
/>
));
};
return (
<Box sx={{ flex: 1, overflowY: "auto", ...desktopScrollStyles }}>
{renderState()}
</Box>
);
}
function HistoryFooter({
onEdit,
editDisabled,
isEditLoading,
}: Pick<HistoryContentProps, "onEdit" | "editDisabled" | "isEditLoading">) {
const { palette } = useAppTheme();
return (
<Box
sx={{
padding: "20px",
borderTop: `1px solid ${palette.border?.primary}`,
backgroundColor: palette.background.default,
flexShrink: 0,
}}
>
<GiveButton
label="Edit Version"
variant="filled"
color="light"
size="large"
onClick={onEdit}
disabled={editDisabled}
loading={isEditLoading}
startIcon={<PencilIcon size={20} />}
fullWidth
/>
</Box>
);
}
export function HistoryContent({
versions,
isLoading = false,
isError = false,
activeVersionID,
onSelectVersion,
onClose,
onEdit,
editDisabled = false,
isEditLoading = false,
bannerHeight = 0,
isOpen = true,
}: HistoryContentProps) {
const { isMobileView } = useCustomThemeV2();
const { palette } = useAppTheme();
const desktopWidth = getDesktopWidth();
const wrapperStyles: SxProps = isMobileView
? {
display: "flex",
flexDirection: "column",
height: "100%",
backgroundColor: palette.background.default,
}
: {
width: `${desktopWidth}px`,
height: `calc(100vh - ${bannerHeight}px)`,
position: "sticky",
top: `${bannerHeight}px`,
backgroundColor: palette.background.default,
borderLeft: `1px solid ${palette.border?.primary}`,
display: "flex",
flexDirection: "column",
flexShrink: 0,
zIndex: 50,
transform: isOpen ? "translateX(0)" : "translateX(100%)",
transition: "transform 0.3s ease-out",
};
return (
<Box sx={wrapperStyles}>
<HistoryHeader onClose={onClose} />
<HistoryBody
versions={versions}
isLoading={isLoading}
isError={isError}
activeVersionID={activeVersionID}
onSelectVersion={onSelectVersion}
/>
{!isMobileView && (
<HistoryFooter
onEdit={onEdit}
editDisabled={editDisabled}
isEditLoading={isEditLoading}
/>
)}
</Box>
);
}
|