experiment page visual tweaks

This commit is contained in:
Kyle Corbitt
2023-07-18 22:22:58 -07:00
parent 1c1cefe286
commit 2cb623f332
5 changed files with 44 additions and 66 deletions

View File

@@ -7,11 +7,16 @@ import {
Text,
CardHeader,
Divider,
Box,
Spinner,
AspectRatio,
} from "@chakra-ui/react";
import { RiFlaskLine } from "react-icons/ri";
import { formatTimePast } from "~/utils/dayjs";
import Link from "next/link";
import { useRouter } from "next/router";
import { BsPlusSquare } from "react-icons/bs";
import { api } from "~/utils/api";
import { useHandledAsyncCallback } from "~/utils/hooks";
type ExperimentData = {
testScenarioCount: number;
@@ -24,24 +29,17 @@ type ExperimentData = {
};
export const ExperimentCard = ({ exp }: { exp: ExperimentData }) => {
const router = useRouter();
return (
<Box
as={Card}
variant="elevated"
<Card
as={Link}
bg="gray.50"
_hover={{ bg: "gray.100" }}
transition="background 0.2s"
cursor="pointer"
onClick={(e) => {
e.preventDefault();
void router.push({ pathname: "/experiments/[id]", query: { id: exp.id } }, undefined, {
shallow: true,
});
}}
href={{ pathname: "/experiments/[id]", query: { id: exp.id } }}
>
<CardHeader>
<HStack w="full" color="gray.700">
<HStack w="full" color="gray.700" justify="center">
<Icon as={RiFlaskLine} boxSize={4} />
<Text fontWeight="bold">{exp.label}</Text>
</HStack>
@@ -52,19 +50,19 @@ export const ExperimentCard = ({ exp }: { exp: ExperimentData }) => {
<Divider h={12} orientation="vertical" />
<CountLabel label="Scenarios" count={exp.testScenarioCount} />
</HStack>
<HStack w="full" color="gray.500" fontSize="xs">
<Text>Created {formatTimePast(exp.createdAt)}</Text>
<HStack w="full" color="gray.500" fontSize="xs" textAlign="center">
<Text flex={1}>Created {formatTimePast(exp.createdAt)}</Text>
<Divider h={4} orientation="vertical" />
<Text>Updated {formatTimePast(exp.updatedAt)}</Text>
<Text flex={1}>Updated {formatTimePast(exp.updatedAt)}</Text>
</HStack>
</CardBody>
</Box>
</Card>
);
};
const CountLabel = ({ label, count }: { label: string; count: number }) => {
return (
<VStack alignItems="flex-start">
<VStack alignItems="center" flex={1}>
<Text color="gray.500" fontWeight="bold">
{label}
</Text>
@@ -74,3 +72,26 @@ const CountLabel = ({ label, count }: { label: string; count: number }) => {
</VStack>
);
};
export const NewExperimentCard = () => {
const router = useRouter();
const utils = api.useContext();
const createMutation = api.experiments.create.useMutation();
const [createExperiment, isLoading] = useHandledAsyncCallback(async () => {
const newExperiment = await createMutation.mutateAsync({ label: "New Experiment" });
await router.push({ pathname: "/experiments/[id]", query: { id: newExperiment.id } });
}, [createMutation, router]);
return (
<Card _hover={{ cursor: "pointer", bgColor: "gray.50" }} onClick={createExperiment}>
<AspectRatio ratio={1} w="full">
<VStack align="center" justify="center" h="100%" spacing={6}>
<Icon as={isLoading ? Spinner : BsPlusSquare} boxSize={8} />
<Text display={{ base: "none", md: "block" }} ml={2}>
New Experiment
</Text>
</VStack>
</AspectRatio>
</Card>
);
};

View File

@@ -1,31 +0,0 @@
import { Icon, Button, Spinner, Text, type ButtonProps } from "@chakra-ui/react";
import { api } from "~/utils/api";
import { useRouter } from "next/router";
import { BsPlusSquare } from "react-icons/bs";
import { useHandledAsyncCallback } from "~/utils/hooks";
export const NewExperimentButton = (props: ButtonProps) => {
const router = useRouter();
const utils = api.useContext();
const createMutation = api.experiments.create.useMutation();
const [createExperiment, isLoading] = useHandledAsyncCallback(async () => {
const newExperiment = await createMutation.mutateAsync({ label: "New Experiment" });
await utils.experiments.list.invalidate();
await router.push({ pathname: "/experiments/[id]", query: { id: newExperiment.id } });
}, [createMutation, router]);
return (
<Button
onClick={createExperiment}
display="flex"
alignItems="center"
variant={{ base: "solid", md: "ghost" }}
{...props}
>
<Icon as={isLoading ? Spinner : BsPlusSquare} boxSize={4} />
<Text display={{ base: "none", md: "block" }} ml={2}>
New Experiment
</Text>
</Button>
);
};