Skip to content
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
581 changes: 581 additions & 0 deletions app/audit/art/stacks.ts

Large diffs are not rendered by default.

431 changes: 431 additions & 0 deletions app/audit/audit.css

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions app/audit/components/ActionDock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use client';

import { useEffect, useState } from 'react';
import { cn } from '@/utils/styles';
import { formatDateShort, formatUsd, formatUsdShort, type RfpView } from '../data/rfp';
import { AddToPoolButton, SubmitProposalButton } from './Actions';
import { BackerFaces, PoolBar } from './Pool';

/**
* Both actions and the pool's progress, pinned to the bottom of the screen,
* as on /consciousness. It shows as soon as the hero's buttons (marked
* `data-audit-hero-cta`) scroll off screen and stays for the rest of the
* page. A floating bar on wide screens, a full-width bar on phones.
*/
export function ActionDock({ rfp }: { rfp: RfpView }) {

Check warning on line 15 in app/audit/components/ActionDock.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSYxkRz710yE2at&open=AaHxtiSYxkRz710yE2at&pullRequest=1311
const [ctaInView, setCtaInView] = useState(true);

useEffect(() => {
const hero = document.querySelector('[data-audit-hero-cta]');
if (!hero) {
setCtaInView(false);
return;
}
const io = new IntersectionObserver(([e]) => setCtaInView(e.isIntersecting), {
threshold: 0,
});
io.observe(hero);
return () => io.disconnect();
}, []);

return (
<div
className={cn(
'pointer-events-none sticky bottom-0 z-40 flex justify-center transition-[transform,opacity] duration-500 ease-out tablet:bottom-5 tablet:px-6',
ctaInView ? 'translate-y-[130%] opacity-0' : 'translate-y-0 opacity-100'
)}
aria-hidden={ctaInView}
inert={ctaInView}
>
{/* Wide screens: a floating bar. */}
<div className="pointer-events-auto hidden w-full max-w-[920px] items-center gap-4 rounded-[10px] border border-[color:var(--a-ink)] bg-[rgb(253_252_248/0.96)] py-2.5 pl-3 pr-2.5 shadow-[0_18px_50px_-18px_rgb(var(--a-ink-rgb)/0.5)] backdrop-blur-xl tablet:flex">
<BackerFaces rfp={rfp} size={30} max={4} />
<div className="min-w-0 flex-1 pl-1">
<p className="truncate text-[14.5px] leading-tight text-[var(--a-soft)]">
<span className="font-semibold tabular-nums text-[var(--a-ink)]">
{formatUsd(rfp.raisedUsd)}
</span>{' '}
raised toward {formatUsdShort(rfp.goalUsd)}
<span className="mx-2 opacity-50">·</span>
Phase 1 ends {formatDateShort(rfp.goalBy)}
</p>
<PoolBar rfp={rfp} className="mt-2 h-1.5 max-w-[300px]" />
</div>
<div className="ml-auto flex shrink-0 items-center gap-2">
<SubmitProposalButton size="md" />
<AddToPoolButton size="md" />
</div>
</div>

{/* Phones: a full-width bar. */}
<div className="pointer-events-auto w-full border-t border-[color:var(--a-ink)] bg-[rgb(253_252_248/0.97)] px-4 pb-[calc(10px+env(safe-area-inset-bottom))] pt-2.5 shadow-[0_-12px_32px_-14px_rgb(var(--a-ink-rgb)/0.35)] backdrop-blur-xl tablet:hidden">
<p className="mb-2 flex items-center justify-between text-[12px] text-[var(--a-mute)]">
<span>
<span className="font-semibold tabular-nums text-[var(--a-ink)]">
{formatUsdShort(rfp.raisedUsd)}
</span>{' '}
raised toward {formatUsdShort(rfp.goalUsd)}
</span>
<span>Phase 1 ends {formatDateShort(rfp.goalBy)}</span>
</p>
<PoolBar rfp={rfp} className="mb-2.5 h-1" />
<div className="flex gap-2">
<AddToPoolButton size="md" className="flex-[3] px-3" />
<SubmitProposalButton size="md" className="flex-[2] px-3" label="Propose" />
</div>
</div>
</div>
);
}
83 changes: 83 additions & 0 deletions app/audit/components/Actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use client';

import { useContext } from 'react';
import { ArrowRight, Plus } from 'lucide-react';
import { OrchActionsContext } from '@/app/consciousness/components/OrchActions';
import { cn } from '@/utils/styles';

/**
* The page's two buttons, in its own style. The actions are the RFP landing
* pages' shared ones (`OrchActionsContext`): adding to the pool and starting
* a proposal.
*/
function useActions() {
const ctx = useContext(OrchActionsContext);
if (!ctx) throw new Error('The audit page buttons need an actions provider');
return ctx;
}

type Size = 'sm' | 'md' | 'lg';

const SIZES: Record<Size, string> = {
sm: 'h-9 px-4 text-[13px]',
md: 'h-11 px-5 text-[14px]',
lg: 'h-12 px-6 text-[15px]',
};

export function AddToPoolButton({
size = 'md',
label = 'Add to the pool',
className,
}: {
size?: Size;
label?: string;
className?: string;
}) {

Check warning on line 35 in app/audit/components/Actions.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSixkRz710yE2a7&open=AaHxtiSixkRz710yE2a7&pullRequest=1311
const { addToPool } = useActions();
return (
<button
type="button"
onClick={addToPool}
className={cn('a-btn a-btn-solid', SIZES[size], className)}
>
<Plus aria-hidden className="h-4 w-4" strokeWidth={2.2} />
{label}
</button>
);
}

export function SubmitProposalButton({
size = 'md',
label = 'Submit a proposal',
className,
}: {
size?: Size;
label?: string;
className?: string;
}) {

Check warning on line 57 in app/audit/components/Actions.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSixkRz710yE2a8&open=AaHxtiSixkRz710yE2a8&pullRequest=1311
const { submitProposal } = useActions();
return (
<button
type="button"
onClick={submitProposal}
className={cn('a-btn a-btn-line', SIZES[size], className)}
>
{label}
<ArrowRight aria-hidden className="h-4 w-4" strokeWidth={2.2} />
</button>
);
}

/** A quiet text link that starts a proposal. */
export function ProposeLink({ label }: { label: string }) {

Check warning on line 72 in app/audit/components/Actions.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSixkRz710yE2a9&open=AaHxtiSixkRz710yE2a9&pullRequest=1311
const { submitProposal } = useActions();
return (
<button type="button" onClick={submitProposal} className="a-link group">
{label}
<ArrowRight
aria-hidden
className="h-4 w-4 transition-transform group-hover:translate-x-0.5"
/>
</button>
);
}
99 changes: 99 additions & 0 deletions app/audit/components/AuditRfpActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use client';

import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
import { useRouter } from 'next/navigation';
import toast from 'react-hot-toast';
import { ContributeToFundraiseModal } from '@/components/modals/ContributeToFundraiseModal';
import { WorkCoverCard } from '@/components/work/WorkCoverCard';
import { isAwardMechanism } from '@/components/Funding/lib/fundingMechanism';
import { handOffRfp } from '@/components/AIMode/rfpHandoff';
import { newDraftTarget, workspaceHref } from '@/components/AIMode/workspaceUrl';
import { isGrantActive, type FundingPool, type Grant } from '@/types/grant';
import { OrchActionsContext } from '@/app/consciousness/components/OrchActions';

/**
* The page's buttons wired to the RFP, exactly as /consciousness wires its
* own (`app/consciousness/components/LiveRfpActions.tsx`, which this
* follows): Add to the pool opens the contribute panel on the grant's
* funding pool, and Submit a proposal hands the RFP to the AI workspace. A
* pending or closed RFP says so instead.
*/
export function AuditRfpActions({
grant,
title,
imageUrl,
children,
}: {
grant: Grant;
title: string;
imageUrl: string | null;
children: ReactNode;
}) {

Check warning on line 31 in app/audit/components/AuditRfpActions.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSgxkRz710yE2a5&open=AaHxtiSgxkRz710yE2a5&pullRequest=1311
const router = useRouter();
const [isPanelOpen, setIsPanelOpen] = useState(false);
const [pool, setPool] = useState<FundingPool | null>(grant.fundingPool ?? null);
useEffect(() => setPool(grant.fundingPool ?? null), [grant.fundingPool]);

const isActive = isGrantActive(grant);
const notOpen =
grant.status === 'PENDING' ? 'This call opens once it is approved.' : 'This call is closed.';
const grantId = String(grant.id);
const organization = grant.organization?.trim() || grant.createdBy?.authorProfile?.fullName || '';

const submitProposal = useCallback(() => {
if (!isActive) {
toast(notOpen, { id: 'audit-action' });
return;
}
handOffRfp({
id: grantId,
shortTitle: grant.shortTitle || title,
imageUrl: imageUrl ?? '',
fundingAmount: grant.amount.usd ?? 0,
organization,
applicationVisibility: grant.applicationVisibility,
fundingMechanism: grant.fundingMechanism ?? 'FUNDING',
});
router.push(workspaceHref(newDraftTarget('need_funding', grantId)));
}, [isActive, notOpen, grant, grantId, title, imageUrl, organization, router]);

const addToPool = useCallback(() => {
if (!isActive || pool?.status !== 'OPEN') {
toast(isActive ? 'The pool is not taking contributions.' : notOpen, { id: 'audit-action' });
return;
}
setIsPanelOpen(true);
}, [isActive, pool, notOpen]);

const handleContributeSuccess = useCallback(
(updatedPool?: FundingPool) => {
if (updatedPool) setPool(updatedPool);
router.refresh();
},
[router]
);

const value = useMemo(() => ({ submitProposal, addToPool }), [submitProposal, addToPool]);

return (
<OrchActionsContext.Provider value={value}>
{children}
{pool && (
<ContributeToFundraiseModal
mode="fundingPool"
isOpen={isPanelOpen}
onClose={() => setIsPanelOpen(false)}
onContributeSuccess={handleContributeSuccess}
fundingPool={pool}
proposalTitle={title}
variant="panel"
topContent={
<WorkCoverCard title={title} eyebrow="RFP" imageUrl={imageUrl ?? undefined} />
}
isAward={isAwardMechanism(grant.fundingMechanism)}
successText="Every dollar in the pool goes to the audits funded under this call."
/>
)}
</OrchActionsContext.Provider>
);
}
24 changes: 24 additions & 0 deletions app/audit/components/AuditShell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';

import type { ReactNode } from 'react';
import { OrchActionsProvider } from '@/app/consciousness/components/OrchActions';

/**
* A full-screen page of its own, without the app's sidebar or top bar, as
* /consciousness is. Until the RFP is loaded its two buttons only say that
* the call opens soon (`OrchActionsProvider`); `AuditRfpActions` then wires
* them to the live RFP.
*/
export function AuditShell({
children,
fontClassName,
}: {
children: ReactNode;
fontClassName: string;
}) {

Check warning on line 18 in app/audit/components/AuditShell.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaHxtiSUxkRz710yE2an&open=AaHxtiSUxkRz710yE2an&pullRequest=1311
return (
<main className={`audit relative min-h-screen min-w-0 ${fontClassName}`}>
<OrchActionsProvider>{children}</OrchActionsProvider>
</main>
);
}
Loading