diff --git a/src/components/InsightView.tsx b/src/components/InsightView.tsx index 2d34a86..c36edcc 100644 --- a/src/components/InsightView.tsx +++ b/src/components/InsightView.tsx @@ -22,10 +22,12 @@ interface data { export function InsightView() { const vote = useVote() const dateFormat = 'MMMM D, YYYY' + const initialDate = new Date() + initialDate.setMonth(initialDate.getMonth() - 1) const [data, setData] = useState({ - date: new Date(), + date: initialDate, type: DateFilterTypes.month, - votes: [] + votes: vote.backlogVotes.filter((i) => moment(i.timestamp).isAfter(initialDate)) }) const [events, setEvents] = useState>([]) const [order, setOrder] = useState<'address' | 'backlogItem'>('address') diff --git a/src/components/ItemCard.tsx b/src/components/ItemCard.tsx new file mode 100644 index 0000000..3364b0d --- /dev/null +++ b/src/components/ItemCard.tsx @@ -0,0 +1,101 @@ +import { Box, Dialog, Flex, Truncate } from '@primer/components' +import { ChevronUpIcon } from '@primer/styled-octicons' +import moment from 'moment' +import React, { useState } from 'react' + +import { PRIMARY_COLOR } from 'src/utils/constants' +import { AddressAvatars } from './AddressAvatars' +import { Link } from './elements/Link' +import { ItemVote } from './ItemVote' +import { BacklogItem } from '../types/BacklogItem' + +interface Props { + item:BacklogItem + length: number + index: number +} + +export function ItemCard(props: Props) { + const { item, length, index } = props + const [showDialog, setShowDialog] = useState(false) + const returnFocusRef = React.useRef(null) + const lastItem = length === index + 1 + const addresses = [...new Set(item.votes.flatMap((i) => i.address))] + + return ( + + setShowDialog(false)} + aria-labelledby="header-id" + > + + + #{item.number} {item.title} + + + + + + + + + setShowDialog(true)} + > + + {item.totalVoteValue} + + + + + + {item.title} + + + + + {item.description} + +

+ #{item.number} opened {moment(item.created).fromNow()} by{' '} + {item.author} +

+ {item.totalVoteCount > 0 && ( +
+ +
+ )} +
+
+
+
+ ) +} diff --git a/src/components/ItemsView.tsx b/src/components/ItemsView.tsx index c79b62c..c0c0615 100644 --- a/src/components/ItemsView.tsx +++ b/src/components/ItemsView.tsx @@ -1,27 +1,19 @@ import { - Box, ButtonPrimary, - Dialog, Flex, TextInput, - Tooltip, - Truncate, } from '@primer/components' import { SearchIcon, - ChevronUpIcon, - VerifiedIcon, } from '@primer/styled-octicons' import moment from 'moment' import React, { ChangeEvent, useState } from 'react' import { useBacklog } from 'src/hooks/useBacklog' import { BacklogItem } from 'src/types' -import { PRIMARY_COLOR } from 'src/utils/constants' -import { AddressAvatars } from './AddressAvatars' import { Link } from './elements/Link' -import { ItemVote } from './ItemVote' import { NoItemsFound } from './NoItemsFound' import { NoOpenItems } from './NoOpenItems' +import { ItemCard } from './ItemCard' export function ItemsView() { const backlog = useBacklog() @@ -76,81 +68,7 @@ export function ItemsView() { {backlog.items.length === 0 && } {items.length === 0 && } {items.map((i: BacklogItem, index: number) => { - const [showDialog, setShowDialog] = useState(false) - const returnFocusRef = React.useRef(null) - const lastItem = items.length === index + 1 - const addresses = [...new Set(i.votes.flatMap(i => i.address))] - - return ( - - setShowDialog(false)} - aria-labelledby="header-id"> - - - #{i.number} {i.title} - - - - - - - - - setShowDialog(true)} - > - - {i.totalVoteValue} - - - - - - {i.title} - - - - - {i.description} - -

- #{i.number} opened {moment(i.created).fromNow()} by{' '} - {i.author} -

- {i.totalVoteCount > 0 && ( -
- -
- )} -
-
-
-
- ) + return })} diff --git a/src/components/QuadraticVote.tsx b/src/components/QuadraticVote.tsx index 35709e0..0f34147 100644 --- a/src/components/QuadraticVote.tsx +++ b/src/components/QuadraticVote.tsx @@ -30,7 +30,7 @@ export function QuadraticVote(props: Props) { } } - function onChange(type: 'MIN' | 'DOWN' | 'UP' | 'MAX') { + function onChangeStep(type: 'MIN' | 'DOWN' | 'UP' | 'MAX') { let amount: number let qc: number @@ -62,6 +62,19 @@ export function QuadraticVote(props: Props) { setQuadraticCost(qc) } + function onChangeInput(event) { + const targetValue = event.target.value + const amount = + targetValue < 1 + ? 1 + : targetValue > maxVotes + ? Math.floor(maxVotes) + : parseInt(targetValue) + const qc = getQuadraticCost(amount) + setVoteAmount(amount) + setQuadraticCost(qc) + } + function disableLower() { return voteAmount <= step } @@ -78,10 +91,11 @@ export function QuadraticVote(props: Props) { return Number(Math.pow(value, 2).toFixed(2)) } - return (
-

You can spend a maximum of {Math.max(maxVotes, 0)} voting power ('VP').

+

+ You can spend a maximum of {Math.max(maxVotes, 0)} voting power ('VP'). +

You already have {itemCost} votes ({getQuadraticCost(itemCost)} VP) on this item. @@ -103,7 +117,7 @@ export function QuadraticVote(props: Props) { className="mr-2" variant="small" disabled={disableLower()} - onClick={() => onChange('MIN')} + onClick={() => onChangeStep('MIN')} > MIN @@ -112,26 +126,27 @@ export function QuadraticVote(props: Props) { className="mr-2" variant="small" disabled={disableLower()} - onClick={() => onChange('DOWN')} + onClick={() => onChangeStep('DOWN')} > « @@ -140,7 +155,7 @@ export function QuadraticVote(props: Props) { className="ml-2" variant="small" disabled={disableHigher()} - onClick={() => onChange('MAX')} + onClick={() => onChangeStep('MAX')} > MAX diff --git a/src/pages/[owner]/[repo].tsx b/src/pages/[owner]/[repo].tsx index 887af9d..fc5497c 100644 --- a/src/pages/[owner]/[repo].tsx +++ b/src/pages/[owner]/[repo].tsx @@ -1,10 +1,8 @@ import React from 'react' -import { GetStaticPaths, GetStaticProps } from 'next' +import { GetServerSideProps } from 'next' import { ParsedUrlQuery } from 'querystring' import { Backlog } from 'src/types' -import { DEFAULT_CACHE_REVALIDATE } from 'src/utils/constants' import { GithubService } from 'src/services/github/service' -import { TokenlogService } from 'src/services/tokenlog' import { Create } from 'src/repository/factory' import { BacklogLayout } from 'src/components/layouts/Backlog' import { BacklogContextProvider } from 'src/context/backlog-context' @@ -33,28 +31,7 @@ export default function BacklogPage(data: Props) { ) } -export const getStaticPaths: GetStaticPaths = async () => { - const repository = Create() - const service = new TokenlogService(repository) - const ids = await service.GetBacklogs() - - const paths = ids - .map((backlog: Backlog) => { - if (backlog.type === 'github') { - const owner = backlog.id.replace('github:', '').split('/')[0] - const repo = backlog.id.replace('github:', '').split('/')[1] - - return { - params: { owner: owner, repo: repo }, - } - } - }) - .filter((i) => !!i) - - return { paths, fallback: 'blocking' } -} - -export const getStaticProps: GetStaticProps = async ( +export const getServerSideProps: GetServerSideProps = async ( context ) => { const repository = Create() @@ -62,7 +39,7 @@ export const getStaticProps: GetStaticProps = async ( const id = `github:${context.params.owner}/${context.params.repo}` const backlog = await service.GetBacklog(id) backlog.items = await service.GetBacklogItems(id) - + if (!backlog) { return { props: null, @@ -74,6 +51,5 @@ export const getStaticProps: GetStaticProps = async ( props: { backlog: backlog, }, - revalidate: DEFAULT_CACHE_REVALIDATE, } } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 9e71e50..5e8ef67 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -6,7 +6,7 @@ export const IMAGE_URL = 'https://tokenlog.xyz/icon.png' export const CREATOR_NOTICE = '2020 — wslyvh' -export const DEFAULT_CACHE_REVALIDATE = 10 +export const DEFAULT_CACHE_REVALIDATE = 5 export const VOTE_VERSION = 2