Skip to content

Commit

Permalink
Merge pull request #11 from aahna-ashina/dw-916/profile-page
Browse files Browse the repository at this point in the history
Add Citizen profile page
  • Loading branch information
aahna-ashina authored Nov 20, 2022
2 parents 4247291 + c913b39 commit 254b2c6
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 8 deletions.
5 changes: 2 additions & 3 deletions components/CitizenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import GradientLink from './GradientLink'

// @ts-expect-error
import Blockies from 'react-blockies'

import { IdentificationIcon } from '@heroicons/react/24/outline'

export default function CitizenCard({
Expand All @@ -22,9 +23,7 @@ export default function CitizenCard({

<div className="flex">
{ensName ? (
<>
<img className="mask mask-circle h-12 w-12" src={`https://cdn.stamp.fyi/avatar/eth:${ethAddress}?s=144`} />
</>
<img className="mask mask-circle h-12 w-12" src={`https://cdn.stamp.fyi/avatar/eth:${ethAddress}?s=144`} />
) : (
<Blockies className="mask mask-circle" seed={ethAddress} size={12} />
)}
Expand Down
10 changes: 5 additions & 5 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function CitizenChart() {
gradientGreen.addColorStop(1, 'rgba(136, 241, 187, 0.3)')

// Fetch data from datasets repo
const citizenCountFileUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/citizens/citizen-count-per-week.csv'
const citizenCountFileUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/citizens/output/citizen-count-per-week.csv'
console.info('Fetching citizenCount data:', citizenCountFileUrl)
Papa.parse(citizenCountFileUrl, {
download: true,
Expand Down Expand Up @@ -117,7 +117,7 @@ export function CitizenList() {
console.info('CitizenList useEffect')

// Fetch data from datasets repo
const citizenDataFileUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/citizens/citizens.csv'
const citizenDataFileUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/citizens/output/citizens.csv'
console.info('Fetching citizen data:', citizenDataFileUrl)
Papa.parse(citizenDataFileUrl, {
download: true,
Expand Down Expand Up @@ -150,8 +150,8 @@ export function CitizenList() {
)
}

const Home: NextPage = () => {
console.info('NextPage')
const HomePage: NextPage = () => {
console.info('HomePage')

return (
<>
Expand All @@ -173,4 +173,4 @@ const Home: NextPage = () => {
)
}

export default Home
export default HomePage
289 changes: 289 additions & 0 deletions pages/profile/[passportId].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
import { useEffect, useRef, useState } from "react"
import { NextPage } from "next"
import Image from "next/image"
import dework from '../../public/dework.svg'

// @ts-expect-error
import Blockies from 'react-blockies'

import Papa from 'papaparse'

import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineController,
LineElement,
Title,
Tooltip,
Legend,
Filler,
ChartData
} from 'chart.js'
import { Chart } from 'react-chartjs-2'
ChartJS.register(
CategoryScale,
LinearScale,
PointElement,
LineController,
LineElement,
Filler,
Title,
Tooltip,
Legend
)

export function NationCredChart({ profile }: any) {
console.info('NationCredChart')

const chartRef = useRef<ChartJS>(null)
const [chartData, setChartData] = useState<ChartData<'line'>>({
datasets: [],
})

useEffect(() => {
console.info('useEffect')
const chart = chartRef.current

if (!chart) {
return
}

let colorGradient = chart.ctx.createLinearGradient(0, 0, 0, 400)
colorGradient.addColorStop(0, 'rgba(213, 163, 152, 0.2)')
colorGradient.addColorStop(1, 'rgba(213, 163, 152, 0.8)')

// Fetch data from datasets repo
const sourceCredFileUrl: string = `https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/sourcecred/output/sourcecred-${profile.ethAddress}.csv`
console.info('Fetching SourceCred data:', sourceCredFileUrl)
Papa.parse(sourceCredFileUrl, {
download: true,
header: true,
skipEmptyLines: true,
dynamicTyping: true,
complete: (result: any) => {
console.info('result:', result)

const week_ends: string[] = []
const sourcecred_scores: number[] = []
const discord_scores: number[] = []
const discourse_scores: number[] = []
const github_scores: number[] = []
result.data.forEach((row: any, i: number) => {
console.info(`row ${i}`, row)
week_ends[i] = String(row.week_end)
sourcecred_scores[i] = Number(row.sourcecred_score)
discord_scores[i] = Number(row.discord_score)
discourse_scores[i] = Number(row.discourse_score)
github_scores[i] = Number(row.github_score)
})
console.info('week_ends:', week_ends)
console.info('sourcecred_scores:', sourcecred_scores)
console.info('discord_scores:', discord_scores)
console.info('discourse_scores:', discourse_scores)
console.info('github_scores:', github_scores)

const data = {
labels: week_ends,
datasets: [
{
label: 'SourceCred score',
data: sourcecred_scores,
borderColor: 'rgba(213, 163, 152, 0.4)',
backgroundColor: colorGradient,
fill: true
},
{
label: 'Discord score',
data: discord_scores,
borderColor: 'rgba(132, 116, 138, 0.2)'
},
{
label: 'Discourse score',
data: discourse_scores,
borderColor: 'rgba(132, 116, 138, 0.4)'
},
{
label: 'GitHub score',
data: github_scores,
borderColor: 'rgba(132, 116, 138, 0.8)'
}
]
}

setChartData(data)
}
})
}, [])

return <Chart type='line' ref={chartRef} data={chartData} />
}

export function DeworkChart({ profile }: any) {
console.info('DeworkChart')

const chartRef = useRef<ChartJS>(null)
const [chartData, setChartData] = useState<ChartData<'line'>>({
datasets: [],
})

useEffect(() => {
console.info('useEffect')
const chart = chartRef.current

if (!chart) {
return
}

let colorGradient = chart.ctx.createLinearGradient(0, 0, 0, 400)
colorGradient.addColorStop(0, 'rgba(231, 88, 143, 0.4)')
colorGradient.addColorStop(1, 'rgba(231, 88, 143, 0.2)')

// Fetch data from datasets repo
const deworkFileUrl: string = `https://raw.githubusercontent.com/nation3/nationcred-datasets/main/data-sources/dework/output/dework-${profile.ethAddress}.csv`
console.info('Fetching Dework data:', deworkFileUrl)
Papa.parse(deworkFileUrl, {
download: true,
header: true,
skipEmptyLines: true,
dynamicTyping: true,
complete: (result: any) => {
console.info('result:', result)

const week_ends: string[] = []
const tasks_completed: number[] = []
const task_points: number[] = []
result.data.forEach((row: any, i: number) => {
console.info(`row ${i}`, row)
week_ends[i] = String(row.week_end)
tasks_completed[i] = Number(row.tasks_completed)
task_points[i] = Number(row.task_points)
})
console.info('week_ends:', week_ends)
console.info('tasks_completed:', tasks_completed)
console.info('task_points:', task_points)

const data = {
labels: week_ends,
datasets: [
{
label: 'Tasks completed',
data: tasks_completed,
borderColor: 'rgba(231, 88, 143, 0.4)',
backgroundColor: colorGradient,
fill: true
},
{
label: 'Task points ',
data: task_points,
borderColor: 'rgba(133, 114, 217, 0.4)'
}
]
}

setChartData(data)
}
})
}, [])

return <Chart type='line' ref={chartRef} data={chartData} />
}

const ProfilePage: NextPage = ({ profile }: any) => {
console.info('ProfilePage')

console.info('profile:', profile)

return (
<>
<div className="flex">
{profile.ensName ? (
<img className="mask mask-circle h-24 w-24" src={`https://cdn.stamp.fyi/avatar/eth:${profile.ethAddress}?s=144`} />
) : (
<Blockies className="mask mask-circle" seed={profile.ethAddress} size={24} />
)}

<div className="ml-4 font-semibold">
<h1 className="text-4xl mt-2">
{profile.ensName ? profile.ensName : `${profile.ethAddress.substring(0, 6)}...${profile.ethAddress.slice(-4)}`}
</h1>
<h2 className="text-2xl text-gray-400 mt-2">
Citizen #{profile.passportId}
</h2>
</div>
</div>

<div className="card bg-base-100 mt-4">
<div className="card-body">
<button className="btn btn-disabled bg-transparent loading">Loading profile...</button>
</div>
</div>

<h2 className="text-2xl mt-8">🎗️ NationCred</h2>

<div className="card bg-base-100 mt-4">
<div className="card-body">
<NationCredChart profile={profile} />
</div>
</div>

<h2 className="text-2xl mt-8"><Image src={dework} width={22} height={22} /> Dework</h2>

<div className="card bg-base-100 mt-4">
<div className="card-body">
<DeworkChart profile={profile} />
</div>
</div>

<h2 className="text-2xl mt-8">🗳️ Voting Power</h2>

<p className="mt-4">Voting power: {profile.votingPower.toFixed(2)}</p>

<div className="card bg-base-100 mt-4">
<div className="card-body">
<button className="btn btn-disabled bg-transparent loading">Loading votes...</button>
</div>
</div>
</>
)
}

export async function getStaticPaths() {
console.info('getStaticPaths')

// TODO

return {
paths: [
// { params: { passportId: '0' } },
// { params: { passportId: '1' } }
],
fallback: 'blocking'
}
}

export async function getStaticProps(context: any) {
console.info('getStaticProps')

console.info('context:', context)

const passportId: string = context.params.passportId
console.info('passportId:', passportId)

const citizensJsonUrl: string = 'https://raw.githubusercontent.com/nation3/nationcred-datasets/a04c42fb5f78f1c57304c31ecccc3032c98b9a8a/data-sources/citizens/output/citizens.json'
console.info('Fetching Citizen data:', citizensJsonUrl)
const response = await fetch(citizensJsonUrl)
const citizens = await response.json()

const citizen = citizens[passportId]
console.info('citizen:', citizen)

return {
props: {
profile: citizen
}
}
}

export default ProfilePage
21 changes: 21 additions & 0 deletions public/dework.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 254b2c6

Please sign in to comment.