Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegatee list #19

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'dot-connect/font.css'
import { config } from './walletConfigs'
import { ReDotProvider, ReDotChainProvider } from '@reactive-dot/react'
import { Suspense } from 'react'
import { AccountContextProvider } from './contexts/AccountsContext'
import { AccountContextProvider } from '@/contexts/AccountsContext'
import { DelegateeContextProvider } from '@/contexts/DelegateesContext'

const App = () => {
const [settings] = useLocalStorage('fellowship-settings', {
Expand All @@ -23,17 +24,19 @@ const App = () => {
<ReDotProvider config={config}>
<ReDotChainProvider chainId="polkadot">
<Suspense>
<AccountContextProvider>
<TooltipProvider>
<div className="flex min-h-screen w-full flex-col bg-muted/40">
<Navigation />
<div className="flex flex-col sm:gap-4 sm:py-4 sm:pl-14">
<Header />
<Content />
<DelegateeContextProvider>
<AccountContextProvider>
<TooltipProvider>
<div className="flex min-h-screen w-full flex-col bg-muted/40">
<Navigation />
<div className="flex flex-col sm:gap-4 sm:py-4 sm:pl-14">
<Header />
<Content />
</div>
</div>
</div>
</TooltipProvider>
</AccountContextProvider>
</TooltipProvider>
</AccountContextProvider>
</DelegateeContextProvider>
</Suspense>
</ReDotChainProvider>
</ReDotProvider>
Expand Down
120 changes: 120 additions & 0 deletions src/components/ui/dialog.tsx
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,
}
3 changes: 2 additions & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const DappName = 'Polkadot DelegIt Dashboard'
const PolkadotUrl = 'https://delegit-xyz.github.io/dashboard'

const GithubOwner = 'delegit-xyz'
// const GithubApiUrl = `https://api.github.com/repos/${GithubOwner}/${GithubRfc}`
export const DelegeeList =
'https://raw.githubusercontent.com/novasamatech/opengov-delegate-registry/master/registry/polkadot.json'

const SideMenuMaximisedWidth = 185
const SideMenuMinimisedWidth = 75
Expand Down
64 changes: 64 additions & 0 deletions src/contexts/DelegateesContext.tsx
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 }
1 change: 1 addition & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export type RouterType = {
export const routes: RouterType[] = [
{ link: 'home', name: 'Home', icon: House },
]

89 changes: 79 additions & 10 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,92 @@
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">
<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>
)
}
Loading