Skip to content

Commit

Permalink
Merge pull request #12 from hypercerts-org/feature/board-designs
Browse files Browse the repository at this point in the history
feat/ownership-table
  • Loading branch information
Jipperism authored Nov 6, 2023
2 parents 299a985 + bec921b commit 75622fb
Show file tree
Hide file tree
Showing 24 changed files with 772 additions and 140 deletions.
61 changes: 0 additions & 61 deletions components/Layout.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions components/admin/hyperboards-admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { CreateHyperboardModal } from "@/components/admin/create-hyperboard-moda
import { useMyHyperboards } from "@/hooks/useMyHyperboards";
import { DeleteHyperboardButton } from "@/components/admin/delete-hyperboard-button";
import { RemoveRegistryFromHyperboardButton } from "@/components/admin/remove-registry-from-hyperboard-button";
import { headerHeight } from "@/components/Layout";
import { EditHyperboardRegistryButton } from "@/components/admin/edit-hyperboard-registry-button";
import { AddHyperboardRegistryButton } from "@/components/admin/add-hyperboard-registry-button";
import { headerHeight } from "@/components/layout/header";

export const HyperboardsAdmin = () => {
const {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const HyperboardsAdmin = () => {
<Thead>
<Tr>
<Th>Name</Th>
<Td>Label</Td>
<Th>Label</Th>
<Th>Chain ID</Th>
</Tr>
</Thead>
Expand Down
8 changes: 6 additions & 2 deletions components/admin/registry-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ const getMyRegistryOptions = async (address: string, name: string) => {

export const SingleRegistrySelector = forwardRef(
function SingleRegistrySelectorRef(
props: Omit<Props, "ref">,
props: Omit<Props, "ref"> & { onlyMyRegistries?: boolean },
ref: React.Ref<any>,
) {
const address = useAddress();
return (
<AsyncSelect
{...props}
ref={ref}
loadOptions={(name) => getMyRegistryOptions(address || "", name)}
loadOptions={(name) =>
props.onlyMyRegistries
? getMyRegistryOptions(address || "", name)
: getRegistryOptions(name)
}
defaultOptions
/>
);
Expand Down
27 changes: 27 additions & 0 deletions components/breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink } from "@chakra-ui/react";
import { BiChevronRight } from "react-icons/bi";

export interface BreadcrumbEntry {
name: string;
onClick: () => void;
isActive?: boolean;
}

export interface BreadcrumbsProps {
crumbs: BreadcrumbEntry[];
}
export const Breadcrumbs = ({ crumbs }: BreadcrumbsProps) => {
return (
<Breadcrumb separator={<BiChevronRight color="gray.500" />}>
{crumbs.map((crumb) => (
<BreadcrumbItem
isCurrentPage={crumb.isActive}
key={crumb.name}
onClick={crumb.onClick}
>
<BreadcrumbLink>{crumb.name}</BreadcrumbLink>
</BreadcrumbItem>
))}
</Breadcrumb>
);
};
2 changes: 1 addition & 1 deletion components/forms/create-or-update-hyperboard-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CreateOrUpdateHyperboardForm = ({
defaultValues: initialValues,
});
return (
<form onSubmit={handleSubmit(onSubmitted)}>
<form onSubmit={handleSubmit(onSubmitted)} style={{ width: "100%" }}>
<FormControl isInvalid={!!errors.name}>
<FormLabel htmlFor="name">Name</FormLabel>
<Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const CreateOrUpdateHyperboardRegistryForm = ({
};

return (
<form onSubmit={handleSubmit(onSubmit)}>
<form style={{ width: "100%" }} onSubmit={handleSubmit(onSubmit)}>
<VStack>
<FormControl isInvalid={!!errors.registry}>
<FormLabel>Registry ID</FormLabel>
Expand Down
3 changes: 2 additions & 1 deletion components/forms/create-or-update-registry-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export const CreateOrUpdateRegistryForm = ({
defaultValues: { claims: [], ...initialValues },
});

// TODO: Add validation whether claim is on correct chain etc
return (
<form onSubmit={handleSubmit(onSubmitted)}>
<form onSubmit={handleSubmit(onSubmitted)} style={{ width: "100%" }}>
<VStack>
<FormControl isInvalid={!!errors.name}>
<FormLabel htmlFor="name">Name</FormLabel>
Expand Down
136 changes: 92 additions & 44 deletions components/ftc-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
registryContentItemToHyperboardEntry,
useHyperboardContents,
} from "@/hooks/registry";
import { Center, Flex, Spinner } from "@chakra-ui/react";
import { Center, Flex, Spinner, VStack } from "@chakra-ui/react";
import { Hyperboard } from "@/components/hyperboard";
import * as React from "react";
import Head from "next/head";
import { BreadcrumbEntry, Breadcrumbs } from "@/components/breadcrumbs";
import { OwnershipTable } from "@/components/hyperboard/ownership-table";

export const FtcBoard = ({ hyperboardId }: { hyperboardId: string }) => {
const containerRef = useRef<HTMLDivElement | null>(null);
Expand All @@ -33,53 +35,99 @@ export const FtcBoard = ({ hyperboardId }: { hyperboardId: string }) => {
return widthPerBoard;
};

const crumbs: BreadcrumbEntry[] = [];

if (hyperboard) {
crumbs.push({
name: hyperboard.name,
onClick: () => setSelectedRegistry(undefined),
});
}

if (selectedRegistry) {
const registry = hyperboard?.hyperboard_registries.find(
(x) => x.registries?.id === selectedRegistry,
);
if (registry?.registries) {
crumbs.push({
name: registry.registries?.name,
onClick: () => {},
isActive: true,
});
}
}

// TODO: Add start breadcrumb with company icon
// TODO: Add second breadcrumb with company name

return (
<>
<Head>
<title>Hyperboards - {hyperboard?.name || "Loading"}</title>
{hyperboard?.name ? (
<title>Hyperboards - {hyperboard.name}</title>
) : (
<title>Hyperboards - Loading</title>
)}
</Head>
<Center width={"100%"} paddingX={"80px"}>
<Flex
width={"100%"}
ref={containerRef}
overflow={"hidden"}
backgroundColor={"black"}
aspectRatio={"16 / 9"}
>
{isLoading ? (
<Center paddingY={"80px"} width={"100%"}>
<Spinner />
</Center>
) : (
<>
{results?.map((x) => (
<Flex
key={x.registry.id}
width={getWidth(x.registry.id)}
minWidth={getWidth(x.registry.id)}
transition={"all 0.5s ease-out"}
overflow={"hidden"}
>
<Hyperboard
onClickLabel={() =>
setSelectedRegistry((currentId) =>
currentId === x.registry.id ? undefined : x.registry.id,
)
}
label={x.label || "Unlabelled"}
height={height}
data={
(Object.values(x.content) || {})
.filter((x) => x.displayData)
.map((x) => registryContentItemToHyperboardEntry(x)) ||
[]
}
/>
</Flex>
))}
</>
)}
</Flex>

<Center flexDirection={"column"} width={"100%"} paddingX={[0, 0, "80px"]}>
<VStack width={"100%"}>
<Flex justifyContent={"flex-start"} width={"100%"}>
<Breadcrumbs crumbs={crumbs} />
</Flex>
<Flex
width={"100%"}
ref={containerRef}
overflow={"hidden"}
backgroundColor={"black"}
aspectRatio={"16 / 9"}
>
{isLoading ? (
<Center paddingY={"80px"} width={"100%"}>
<Spinner />
</Center>
) : (
<>
{results?.map((x) => (
<Flex
key={x.registry.id}
width={getWidth(x.registry.id)}
minWidth={getWidth(x.registry.id)}
transition={"all 0.5s ease-out"}
overflow={"hidden"}
>
<Hyperboard
onClickLabel={() =>
setSelectedRegistry((currentId) =>
currentId === x.registry.id
? undefined
: x.registry.id,
)
}
label={x.label || "Unlabelled"}
height={height}
data={
(Object.values(x.content) || {})
.filter((x) => x.displayData)
.map((x) =>
registryContentItemToHyperboardEntry(x),
) || []
}
/>
</Flex>
))}
</>
)}
</Flex>
</VStack>
{hyperboard && (
<OwnershipTable
hyperboardId={hyperboard.id}
showHeader
selectedRegistry={selectedRegistry}
onSelectRegistry={setSelectedRegistry}
/>
)}
</Center>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions components/hyperboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Hyperboard = (props: HyperboardProps) => {
if (!dimensions) {
return;
}
console.log("drawing", containerRef.current, dimensions);
// console.log("drawing", containerRef.current, dimensions);
d3.select(ref.current)
.attr("width", props.height)
.attr("height", props.height)
Expand Down Expand Up @@ -83,7 +83,7 @@ export const Hyperboard = (props: HyperboardProps) => {
};

const ratio = dimensions ? dimensions.width / dimensions.height : 1;
console.log("dimensions", dimensions, ratio);
// console.log("dimensions", dimensions, ratio);

return (
<Flex
Expand Down
Loading

0 comments on commit 75622fb

Please sign in to comment.