Skip to content

Commit

Permalink
error fix and progress bar improvements
Browse files Browse the repository at this point in the history
- solve Tooltip error (wrong import)
- add total to progress bar
- clean up progress bar logic
  • Loading branch information
goblinodds committed May 16, 2024
1 parent bdd0faa commit ace2871
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pages/project/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from 'next/router'
import * as React from 'react'
import { SuperSEO } from 'react-super-seo'

import { LoadingOverlay, Progress, Tabs, Tooltip } from '@mantine/core'
import { LoadingOverlay, Progress, Tabs } from '@mantine/core'
import { CommentType } from '@prisma/client'
import {
IconCreditCard,
Expand Down Expand Up @@ -34,6 +34,7 @@ import { Tags } from '@/components/tags'
import { PageLoader } from '@/components/utils'
import { classNames } from '@/lib/classnames'
import { markdownToPlainHtml } from '@/lib/editor'
import { Tooltip } from '@/lib/mantine'
import { num } from '@/lib/text'
import { RouterOutput, trpc } from '@/lib/trpc'
import type { NextPageWithAuthAndLayout } from '@/lib/types'
Expand Down Expand Up @@ -131,6 +132,18 @@ function ProjectPage({ projectId }: { projectId: string }) {
const projectQuery = trpc.project.detail.useQuery(projectQueryInput)
const project = projectQuery.data

// progress bar funding percentages
const percentFunded =
project && project.fundingGoal && project.fundingGoal.gt(0)
? Math.round(
project.quarterDonationTotal
.dividedBy(project.fundingGoal)
.times(100)
.toNumber(),
)
: 0
const percentNeeded = 100 - percentFunded

// calculate projectBelongsToUser at the component level
let projectBelongsToUser = false
// if we have information about the project and if the user is logged in,
Expand Down Expand Up @@ -260,22 +273,14 @@ function ProjectPage({ projectId }: { projectId: string }) {
root: 'w-full h-8 rounded mt-5',
}}
>
<Progress.Section
value={project.quarterDonationTotal
.dividedBy(project.fundingGoal)
.times(100)
.toNumber()}
color="#47d6ab"
>
<Progress.Section value={percentFunded} color="#47d6ab">
<Progress.Label>
{`${Math.round(
project.quarterDonationTotal
.dividedBy(project.fundingGoal)
.times(100)
.toNumber(),
)}% funded`}
{`${percentFunded}% funded`}
</Progress.Label>
</Progress.Section>
<Progress.Section value={100} color="#AAAAAA">
<Progress.Label>{`${percentNeeded}% needed this quarter`}</Progress.Label>
</Progress.Section>
</Progress.Root>
</Tooltip>
</div>
Expand Down

0 comments on commit ace2871

Please sign in to comment.