-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tbaut-lockAndVotes
- Loading branch information
Showing
9 changed files
with
692 additions
and
23 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
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,120 @@ | ||
import * as React from "react" | ||
import * as DialogPrimitive from "@radix-ui/react-dialog" | ||
import { X } from "lucide-react" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Dialog = DialogPrimitive.Root | ||
|
||
const DialogTrigger = DialogPrimitive.Trigger | ||
|
||
const DialogPortal = DialogPrimitive.Portal | ||
|
||
const DialogClose = DialogPrimitive.Close | ||
|
||
const DialogOverlay = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Overlay>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Overlay | ||
ref={ref} | ||
className={cn( | ||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName | ||
|
||
const DialogContent = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<DialogPortal> | ||
<DialogOverlay /> | ||
<DialogPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"> | ||
<X className="h-4 w-4" /> | ||
<span className="sr-only">Close</span> | ||
</DialogPrimitive.Close> | ||
</DialogPrimitive.Content> | ||
</DialogPortal> | ||
)) | ||
DialogContent.displayName = DialogPrimitive.Content.displayName | ||
|
||
const DialogHeader = ({ | ||
className, | ||
...props | ||
}: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
"flex flex-col space-y-1.5 text-center sm:text-left", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogHeader.displayName = "DialogHeader" | ||
|
||
const DialogFooter = ({ | ||
className, | ||
...props | ||
}: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogFooter.displayName = "DialogFooter" | ||
|
||
const DialogTitle = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Title>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Title | ||
ref={ref} | ||
className={cn( | ||
"text-lg font-semibold leading-none tracking-tight", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
DialogTitle.displayName = DialogPrimitive.Title.displayName | ||
|
||
const DialogDescription = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Description>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Description | ||
ref={ref} | ||
className={cn("text-sm text-muted-foreground", className)} | ||
{...props} | ||
/> | ||
)) | ||
DialogDescription.displayName = DialogPrimitive.Description.displayName | ||
|
||
export { | ||
Dialog, | ||
DialogPortal, | ||
DialogOverlay, | ||
DialogClose, | ||
DialogTrigger, | ||
DialogContent, | ||
DialogHeader, | ||
DialogFooter, | ||
DialogTitle, | ||
DialogDescription, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable react-refresh/only-export-components */ | ||
import { createContext, useContext, useEffect, useState } from 'react' | ||
import delegateesList from '@/polkadot.json' | ||
// import { dotApi } from '@/clients' | ||
|
||
type DelegateesContextProps = { | ||
children: React.ReactNode | React.ReactNode[] | ||
} | ||
|
||
type DelegateeProps = { | ||
address: string | ||
name: string | ||
image: string | ||
shortDescription: string | ||
longDescription: string | ||
isOrganization: boolean | ||
} | ||
|
||
export interface IDelegateesContext { | ||
delegetees: DelegateeProps[] | ||
} | ||
|
||
const DelegateesContext = createContext<IDelegateesContext | undefined>( | ||
undefined, | ||
) | ||
|
||
const DelegateeContextProvider = ({ children }: DelegateesContextProps) => { | ||
const [delegetees, setDelegatees] = useState<DelegateeProps[]>([]) | ||
|
||
useEffect(() => { | ||
setDelegatees(delegateesList as DelegateeProps[]) | ||
}, []) | ||
|
||
// Votes thingy - pause for now | ||
// useEffect(() => { | ||
// const a = async (delegetees: any[]) => { | ||
// const result: Promise<any>[] = delegetees.map((d) => { | ||
// return dotApi.query.ConvictionVoting.VotingFor.getEntries(d.address) | ||
// }) | ||
// await Promise.all(result).then((res) => { | ||
// console.log(res) | ||
// }) | ||
// } | ||
// a(delegetees) | ||
// }, [delegetees]) | ||
|
||
return ( | ||
<DelegateesContext.Provider value={{ delegetees }}> | ||
{children} | ||
</DelegateesContext.Provider> | ||
) | ||
} | ||
|
||
const useDelegatees = () => { | ||
const context = useContext(DelegateesContext) | ||
if (context === undefined) { | ||
throw new Error( | ||
'useDelegatees must be used within a DelegateesContextProvider', | ||
) | ||
} | ||
return context | ||
} | ||
|
||
export { DelegateeContextProvider, useDelegatees } |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ export type RouterType = { | |
export const routes: RouterType[] = [ | ||
{ link: 'home', name: 'Home', icon: House }, | ||
] | ||
|
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,25 +1,94 @@ | ||
import { LocksCard } from '@/components/LocksCard' | ||
import { Button } from '@/components/ui/button' | ||
import { Card } from '@/components/ui/card' | ||
import { useDelegatees } from '@/contexts/DelegateesContext' | ||
import { Check, Copy, Ellipsis } from 'lucide-react' | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTrigger, | ||
} from '@/components/ui/dialog' | ||
|
||
const openInNewTab = (url: string | URL | undefined) => { | ||
window.open(url, '_blank', 'noopener,noreferrer') | ||
} | ||
import { ellipsisFn } from '@polkadot-ui/utils' | ||
|
||
import copy from 'copy-to-clipboard' | ||
import { useEffect, useState } from 'react' | ||
|
||
// const openInNewTab = (url: string | URL | undefined) => { | ||
// window.open(url, '_blank', 'noopener,noreferrer') | ||
// } | ||
|
||
export const Home = () => { | ||
const { delegetees } = useDelegatees() | ||
|
||
const [copied, setCopied] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
if (copied) { | ||
setTimeout(() => setCopied(false), 1000) | ||
} | ||
}, [copied]) | ||
|
||
console.log(delegetees) | ||
return ( | ||
<main className="grid flex-1 items-start gap-4 p-4 sm:mx-[5%] xl:mx-[20%] mx-0 sm:px-6 sm:py-0 md:gap-8"> | ||
<LocksCard /> | ||
<h1 className="font-unbounded text-primary flex-1 shrink-0 whitespace-nowrap text-xl font-semibold tracking-tight sm:grow-0"> | ||
Title | ||
Delegetees | ||
</h1> | ||
<div className="pageTop"> | ||
<p>text</p> | ||
<Button className="mt-6" onClick={() => openInNewTab('')}> | ||
ClickButton | ||
</Button> | ||
{delegetees?.map((d) => ( | ||
<Card className="border-2 flex flex-col p-2 mb-5"> | ||
<div className="flex columns-3"> | ||
<div className="p-2 w-[10%]"> | ||
<img className="rounded-3xl" width="100" src={d.image} /> | ||
</div> | ||
<div className="p-2 w-[85%]"> | ||
<div className="font-bold">{d.name}</div> | ||
<div className="">{d.shortDescription}</div> | ||
</div> | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<Button | ||
variant={'outline'} | ||
className="text-xs" | ||
onClick={() => console.log('read more')} | ||
> | ||
<Ellipsis className="text-xs" /> | ||
</Button> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<div className="font-bold">{d.name}</div> | ||
</DialogHeader> | ||
<DialogDescription className="flex"> | ||
<div>{ellipsisFn(d.address)}</div> | ||
<div className="pl-4 cursor-pointer"> | ||
{copied ? ( | ||
<Check className="text-[green]" /> | ||
) : ( | ||
<Copy | ||
className="cursor-pointer" | ||
onClick={() => { | ||
setCopied(true) | ||
copy(d.address) | ||
}} | ||
/> | ||
)} | ||
</div> | ||
</DialogDescription> | ||
<div className="grid py-4"> | ||
<div className="items-center">{d.longDescription}</div> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
</div> | ||
<div className="w-full"></div> | ||
</Card> | ||
))} | ||
</div> | ||
|
||
<div style={{ paddingTop: '2rem' }}></div> | ||
</main> | ||
) | ||
} |
Oops, something went wrong.