Skip to content

Commit

Permalink
Style CGP content
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Feb 19, 2024
1 parent 5b6f77e commit f889d41
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 34 deletions.
11 changes: 5 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
},
"files.exclude": {
"**/*.js.map": true,
"**/*.js": {"when": "$(basename).ts"},
"**/*.map": {"when": "$(basename).map"},
"**/*.js": { "when": "$(basename).ts" },
"**/*.map": { "when": "$(basename).map" }
},
"files.watcherExclude": {
"**/.git/objects/**": true,
Expand All @@ -18,7 +18,7 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.preferences.importModuleSpecifier": "non-relative",
"[typescriptreact]": {
Expand All @@ -32,14 +32,13 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.tabSize": 2,
"editor.detectIndentation": false,
"tailwindCSS.experimental.classRegex": [
["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
]
"tailwindCSS.experimental.classRegex": [["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]]
}
48 changes: 42 additions & 6 deletions src/app/governance/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use client';

import { useMemo } from 'react';
import { FullWidthSpinner } from 'src/components/animation/Spinner';
import { BackLink } from 'src/components/buttons/BackLink';
import { ExternalLink } from 'src/components/buttons/ExternalLink';
import { Section } from 'src/components/layout/Section';
import { links } from 'src/config/links';
import { ProposalBadgeRow } from 'src/features/governance/ProposalCard';
import {
MergedProposalData,
Expand All @@ -11,6 +14,7 @@ import {
import { useProposalContent } from 'src/features/governance/useProposalContent';
import { usePageInvariant } from 'src/utils/navigation';
import { trimToLength } from 'src/utils/strings';
import styles from './styles.module.css';

const ID_PARAM_REGEX = /^(cgp-)?(\d+)$/;

Expand All @@ -34,11 +38,14 @@ export default function Page({ params: { id } }: { params: { id: string } }) {
}, [proposals, id]);

usePageInvariant(!proposals || proposal, '/governance', 'Proposal not found');
if (!proposal) return null;

if (!proposal) {
return <FullWidthSpinner>Loading proposals</FullWidthSpinner>;
}

return (
<Section containerClassName="space-y-4 mt-4">
<div className="flex flex-col md:flex-row">
<div className="flex flex-col items-stretch md:flex-row">
<ProposalContent data={proposal} />
<ProposalChainData data={proposal} />
</div>
Expand All @@ -50,20 +57,49 @@ function ProposalContent({ data }: { data: MergedProposalData }) {
const { proposal, metadata } = data;
const title = trimToLength(metadata?.title || `Proposal #${proposal?.id}`, 80);

//TODO loading/err
const { content } = useProposalContent(metadata);
const { content, isLoading } = useProposalContent(metadata);

return (
<div className="space-y-3">
<BackLink href="/governance">Browse proposals</BackLink>
<h1 className="font-serif text-xl md:text-2xl">{title}</h1>
<ProposalBadgeRow data={data} showProposer />
<div dangerouslySetInnerHTML={{ __html: content || '' }}></div>
{isLoading && !content && <FullWidthSpinner>Loading proposal content</FullWidthSpinner>}
{!isLoading && !content && (
<div className="flex flex-col items-center justify-center space-y-4 py-12">
<p className="text-center text-taupe-600">No CGP content found for this proposal</p>
<p className="text-center text-taupe-600">
Check the{' '}
<ExternalLink href={links.governance} className="underline">
Celo Governance repository
</ExternalLink>{' '}
for more information
</p>
</div>
)}
{content && (
<div
dangerouslySetInnerHTML={{ __html: content }}
className={`max-w-screen-md space-y-4 pb-4 ${styles.proposal}`}
></div>
)}
</div>
);
}

function ProposalChainData({ data: { proposal } }: { data: MergedProposalData }) {
if (!proposal) return null;
return <div>TODO</div>;
return (
<div className="space-y-4">
<div className="border border-taupe-300 p-4">
<h2>Vote</h2>
</div>
<div className="border border-taupe-300 p-4">
<h2>Results</h2>
</div>
<div className="border border-taupe-300 p-4">
<h2>Voters</h2>
</div>
</div>
);
}
59 changes: 59 additions & 0 deletions src/app/governance/[id]/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.proposal h1,
.proposal h2,
.proposal h3,
.proposal h4 {
font-family: 'Garamond', serif;
}

.proposal h1,
.proposal h2 {
font-size: 24px;
}

.proposal h3 {
font-size: 20px;
}

.proposal h4 {
font-size: 18px;
}

.proposal a {
text-decoration: underline;
cursor: pointer;
}

.proposal a:hover {
opacity: 0.75;
}

.proposal a:active {
opacity: 0.65;
}

.proposal ol,
.proposal ul {
padding-left: 1rem;
}

.proposal ul {
list-style: disc;
}

.proposal ol {
list-style: decimal;
}

.proposal li {
padding-left: 1rem;
margin-top: 0.6rem;
}

.proposal pre {
padding: 0.5rem;
background-color: rgba(0, 0, 0, 0.04);
}

.proposal img {
display: none;
}
6 changes: 2 additions & 4 deletions src/app/governance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Image from 'next/image';
import { useMemo, useState } from 'react';
import { Fade } from 'src/components/animation/Fade';
import { SpinnerWithLabel } from 'src/components/animation/Spinner';
import { FullWidthSpinner } from 'src/components/animation/Spinner';
import { TabHeaderFilters } from 'src/components/buttons/TabHeaderButton';
import { SearchField } from 'src/components/input/SearchField';
import { Section } from 'src/components/layout/Section';
Expand Down Expand Up @@ -109,9 +109,7 @@ function ProposalList() {
</div>
</Fade>
) : (
<div className="flex justify-center py-10">
<SpinnerWithLabel>Loading governance data</SpinnerWithLabel>
</div>
<FullWidthSpinner>Loading governance data</FullWidthSpinner>
)}
</div>
);
Expand Down
8 changes: 2 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import { useMemo } from 'react';
import { Fade } from 'src/components/animation/Fade';
import { SpinnerWithLabel } from 'src/components/animation/Spinner';
import { FullWidthSpinner } from 'src/components/animation/Spinner';
import { SolidButton } from 'src/components/buttons/SolidButton';
import { Section } from 'src/components/layout/Section';
import { StatBox } from 'src/components/layout/StatBox';
Expand Down Expand Up @@ -84,11 +84,7 @@ function HeroSection({ totalVotes, groups }: { totalVotes?: bigint; groups?: Val

function TableSection({ totalVotes, groups }: { totalVotes?: bigint; groups?: ValidatorGroup[] }) {
if (!totalVotes || !groups) {
return (
<div className="flex justify-center py-10">
<SpinnerWithLabel>Loading validator data</SpinnerWithLabel>
</div>
);
return <FullWidthSpinner>Loading validator data</FullWidthSpinner>;
}

return (
Expand Down
11 changes: 11 additions & 0 deletions src/components/animation/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export function SpinnerWithLabel({
);
}

export function FullWidthSpinner({
children,
className,
}: PropsWithChildren<{ className?: string }>) {
return (
<div className={`flex justify-center py-16 ${className}`}>
<SpinnerWithLabel>{children}</SpinnerWithLabel>
</div>
);
}

const sizeToClass = {
xs: 'loading-xs',
sm: 'loading-sm',
Expand Down
1 change: 1 addition & 0 deletions src/config/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const links = {
twitter: 'https://twitter.com/CeloOrg',
docs: 'https://docs.celo.org',
forum: 'https://forum.celo.org',
governance: 'https://github.com/celo-org/governance',
// RPCs
forno: 'https://forno.celo.org',
infura: 'https://celo-mainnet.infura.io/v3',
Expand Down
8 changes: 2 additions & 6 deletions src/features/staking/ActiveStakesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from 'clsx';
import Image from 'next/image';
import { useMemo } from 'react';
import { SpinnerWithLabel } from 'src/components/animation/Spinner';
import { FullWidthSpinner } from 'src/components/animation/Spinner';
import { SolidButton } from 'src/components/buttons/SolidButton';
import { PLACEHOLDER_BAR_CHART_ITEM, StackedBarChart } from 'src/components/charts/StackedBarChart';
import { sortAndCombineChartData } from 'src/components/charts/chartData';
Expand Down Expand Up @@ -63,11 +63,7 @@ export function ActiveStakesTable({
}, [groupToStake, addressToGroup]);

if (!groupToStake || !addressToGroup || !groupToIsActivatable) {
return (
<div className="my-16 flex justify-center">
<SpinnerWithLabel>Loading staking data</SpinnerWithLabel>
</div>
);
return <FullWidthSpinner>Loading staking data</FullWidthSpinner>;
}

if (!objLength(groupToStake)) {
Expand Down
8 changes: 2 additions & 6 deletions src/features/staking/rewards/RewardsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { SpinnerWithLabel } from 'src/components/animation/Spinner';
import { FullWidthSpinner } from 'src/components/animation/Spinner';
import { SolidButton } from 'src/components/buttons/SolidButton';
import { PLACEHOLDER_BAR_CHART_ITEM, StackedBarChart } from 'src/components/charts/StackedBarChart';
import { sortAndCombineChartData } from 'src/components/charts/chartData';
Expand Down Expand Up @@ -48,11 +48,7 @@ export function RewardsTable({
}, [groupToReward, addressToGroup]);

if (!groupToReward || !addressToGroup) {
return (
<div className="my-16 flex justify-center">
<SpinnerWithLabel>Loading staking data</SpinnerWithLabel>
</div>
);
return <FullWidthSpinner>Loading staking data</FullWidthSpinner>;
}

if (!objLength(groupToReward)) {
Expand Down

0 comments on commit f889d41

Please sign in to comment.