Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: rating bugs & text modifs #60

Merged
merged 6 commits into from
Sep 29, 2024
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
25 changes: 14 additions & 11 deletions app/comparison/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default function Home() {
const { checkLoginFlow } = useAuth();
const { address, chainId } = useAccount();

const [rating1, setRating1] = useState<number>(3);
Copy link
Collaborator

@mmahdigh mmahdigh Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for stars must be null and if users don't rate a project, it should be sent as null to our backend server.

const [rating2, setRating2] = useState<number>(3);
const [rating1, setRating1] = useState<number | null>(null);
const [rating2, setRating2] = useState<number | null>(null);
const [project1, setProject1] = useState<IProject>();
const [project2, setProject2] = useState<IProject>();
const [coiLoading1, setCoiLoading1] = useState(false);
Expand Down Expand Up @@ -138,9 +138,8 @@ export default function Home() {

useEffect(() => {
if (!data || !data.pairs?.length) return;
console.log(data);
setRating1(data.pairs[0][0].rating || 3);
setRating2(data.pairs[0][1].rating || 3);
setRating1(data.pairs[0][0].rating ?? null);
setRating2(data.pairs[0][1].rating ?? null);
}, [data]);

useEffect(() => {
Expand All @@ -160,8 +159,10 @@ export default function Home() {
}, [data, temp]);

useEffect(() => {
const initialRating1 = data?.pairs[0][0].rating || 3;
const initialRating2 = data?.pairs[0][1].rating || 3;
const initialRating1 = data?.pairs[0][0].rating || 0;
const initialRating2 = data?.pairs[0][1].rating || 0;

if (rating1 === null || rating2 === null) return;

// observe if user rated both projects
if (rating1 !== initialRating1 && rating2 !== initialRating2) {
Expand Down Expand Up @@ -307,6 +308,8 @@ export default function Home() {
) =>
chosenId === selectedId && (!ratingA || (ratingB && ratingA < ratingB));

if (!rating1 && !rating2) return false;

if (
isLowRatedProjectSelected(project1!.id, rating1, rating2) ||
isLowRatedProjectSelected(project2!.id, rating2, rating1)
Expand All @@ -326,8 +329,8 @@ export default function Home() {
data: {
project1Id: project1!.id,
project2Id: project2!.id,
project1Stars: rating1,
project2Stars: rating2,
project1Stars: rating1 ?? null,
project2Stars: rating2 ?? null,
pickedId: chosenId,
},
});
Expand Down Expand Up @@ -542,7 +545,7 @@ export default function Home() {
<footer className="sticky bottom-0 z-50 flex w-full items-center justify-around gap-4 bg-white py-8 shadow-inner">
<div className="flex flex-col items-center justify-center gap-4 lg:flex-row xl:gap-8">
<Rating
value={rating1}
value={rating1 || 0}
onChange={setRating1}
disabled={isInitialVisit || coiLoading1}
/>
Expand All @@ -566,7 +569,7 @@ export default function Home() {
</div>
<div className="flex flex-col items-center justify-center gap-4 lg:flex-row xl:gap-8">
<Rating
value={rating2}
value={rating2 || 0}
onChange={setRating2}
disabled={isInitialVisit || coiLoading2}
/>
Expand Down
14 changes: 11 additions & 3 deletions app/comparison/ballot/modals/BallotError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import Image from 'next/image';
import React from 'react';

interface UnlockBallotProps {
onClick: () => void
onClick: () => void;
}

const BALLOT_REPPORT_URL =
'https://github.com/GeneralMagicio/pairwise-rpgf5/issues/new?assignees=MoeNick&labels=P0&projects=&template=report-error-on-updating-ballot.md&title=%5BError+updating+ballot%5D+';

const BallotError: React.FC<UnlockBallotProps> = ({ onClick }) => {
return (
<div className="mx-auto w-[96] overflow-hidden rounded-lg bg-white bg-ballot bg-no-repeat shadow-lg">
Expand All @@ -20,15 +23,20 @@ const BallotError: React.FC<UnlockBallotProps> = ({ onClick }) => {
Error updating ballot!
</h2>
<p className="mb-6 text-gray-400">
We encountered a problem updating your ballot.
Please retry updating.
We encountered a problem updating your ballot. Please retry updating.
</p>
<button
onClick={onClick}
className="flex w-full items-center justify-center rounded-lg bg-primary px-4 py-3 text-white transition duration-300 ease-in-out hover:bg-red-600"
>
Retry ballot update
</button>
<button
onClick={() => window.open(BALLOT_REPPORT_URL, '_blank')}
className="mt-4 flex w-full items-center justify-center rounded-lg bg-white px-4 py-3 font-semibold text-primary transition duration-300 ease-in-out"
>
Report an issue
</button>
</div>
</div>
);
Expand Down
9 changes: 7 additions & 2 deletions app/comparison/card/GithubBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ interface Props {
const GithubBox: FC<Props> = ({ repo }) => {
const { getCollapseProps, getToggleProps, isExpanded } = useCollapse();


return (
<div className="max-w-full rounded-lg border border-gray-200 bg-gray-50 p-2 py-[12px] font-inter">
<div
{...getToggleProps()}
className="max-w-full cursor-pointer rounded-lg border border-gray-200 bg-gray-50 p-2 py-[12px] font-inter"
>
<div
className={`flex items-center justify-between ${
isExpanded ? 'mb-4' : ''
Expand All @@ -36,6 +40,7 @@ const GithubBox: FC<Props> = ({ repo }) => {
href={repo.url}
className="break-all text-gray-700 hover:underline"
target="_blank"
onClick={(e) => e.stopPropagation()}
>
{repo.name || repo.url?.replace('https://' || 'http://', '')}
</a>
Expand All @@ -44,7 +49,7 @@ const GithubBox: FC<Props> = ({ repo }) => {
<span> Open source </span>
</div>
</div>
<button {...getToggleProps()} className="text-sm text-gray-600">
<button className="text-sm text-gray-600">
{isExpanded ? (
<div className="flex items-center gap-2">
<span> Hide metrics </span>
Expand Down
4 changes: 2 additions & 2 deletions app/comparison/card/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const ProjectCard: React.FC<Props> = ({
onChange={setAi}
checked={aiMode}
/>
<p className="font-medium"> TLDR </p>
<p className="font-medium"> AI Summary </p>
<StarsIcon />
</div>
<ProjectDescription description={project.description} />
Expand Down Expand Up @@ -446,7 +446,7 @@ export const ProjectCard: React.FC<Props> = ({
</p>
</div>
<div className="space-y-2">
{project.impactStatement.statement.create.map(
{project.impactStatement.statement?.create?.map(
({ question, answer }) => (
<QABox
key={question}
Expand Down
32 changes: 24 additions & 8 deletions app/comparison/card/SimpleInfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,47 @@ const SimpleInfoBox: FC<Props> = ({
target="_blank"
className="break-all text-gray-700 hover:underline"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
>
{displayTitle}
</a>
);
};

const shouldCollapse = description.length > 0;

return (
<div className="max-w-full rounded-lg border border-gray-200 bg-gray-50 p-2">
<div className={`flex items-center justify-between ${isExpanded ? 'mb-4' : ''}`}>
<div
className={`max-w-full rounded-lg border border-gray-200 bg-gray-50 p-2 ${
shouldCollapse ? 'cursor-pointer' : ''
}`}
{...(shouldCollapse &&
getToggleProps())}
>
<div
className={`flex items-center justify-between ${
isExpanded && shouldCollapse ? 'mb-4' : ''
}`}
>
<div className="flex items-center gap-2">
{ICONS_MAP[type] && showIcon && <span className="size-5">{ICONS_MAP[type]}</span>}
{ICONS_MAP[type] && showIcon && (
<span className="size-5">{ICONS_MAP[type]}</span>
)}
{renderTitle()}
</div>
{description.length > 0 && (
{shouldCollapse && (
<button
{...getToggleProps()}
className="text-sm text-gray-600 hover:underline"
>
{isExpanded ? <ArrowUpIcon /> : <ArrowDownIcon />}
</button>
)}
</div>
<section {...getCollapseProps()}>
<p className="mb-2 text-gray-600">{description}</p>
</section>
{shouldCollapse && (
<section {...getCollapseProps()}>
<p className="mb-2 text-gray-600">{description}</p>
</section>
)}
</div>
);
};
Expand Down
27 changes: 17 additions & 10 deletions app/comparison/card/modals/ContractBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const ContractBox = ({
target="_blank"
rel="noopener noreferrer"
className="break-all text-gray-700 hover:underline"
onClick={(e) => e.stopPropagation()}
>
{title}
</a>
Expand All @@ -53,29 +54,35 @@ export const ContractBox = ({
);
};

const shouldCollapse = description.length > 0;

return (
<div className="max-w-full rounded-lg border border-gray-200 bg-gray-50 p-2">
<div
{...(shouldCollapse && getToggleProps())}
className={`max-w-full rounded-lg border border-gray-200 bg-gray-50 p-2 ${
shouldCollapse ? 'cursor-pointer' : ''
}`}
>
<div
className={`flex items-center justify-between ${
isExpanded ? 'mb-4' : ''
isExpanded && shouldCollapse ? 'mb-4' : ''
}`}
>
<div className="flex items-center gap-2">
{renderIcon()}
{renderTitle()}
</div>
{description && (
<button
{...getToggleProps()}
className="text-sm text-gray-600 hover:underline"
>
{shouldCollapse && (
<button className="text-sm text-gray-600 hover:underline">
{isExpanded ? <ArrowUpIcon /> : <ArrowDownIcon />}
</button>
)}
</div>
<section {...getCollapseProps()}>
<p className="mb-2 text-gray-600">{description}</p>
</section>
{shouldCollapse && (
<section {...getCollapseProps()}>
<p className="mb-2 text-gray-600">{description}</p>
</section>
)}
</div>
);
};
2 changes: 1 addition & 1 deletion app/components/TextBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TextBlock: FC<{
scale?: number;
};
}> = ({ mainText, highlightText, description, highlightImage }) => (
<p className="sm:w-[35%]] w-full text-start text-3xl font-bold text-dark-500 xl:text-4xl">
<p className="sm:w-[35%]] w-full text-start text-3xl font-bold text-dark-500 xl:text-4xl xl:leading-[3rem]">
{mainText}{' '}
<span className="relative inline-block">
<Image
Expand Down
2 changes: 1 addition & 1 deletion app/landing/part2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const LandingPart2 = () => {
<div className="relative h-[360px] w-full md:h-[540px]">
<Image src="assets/images/landing-p2.svg" alt="landing part 2" width={700} height={540} />
</div>
<div className="flex max-w-[700px] flex-col gap-2 font-inter text-4xl font-bold sl:text-2xl">
<div className="flex max-w-[400px] flex-col gap-2 font-inter text-4xl font-bold md:max-w-[700px] sl:text-2xl">
<TextBlock
mainText="Choose the project that you consider had a greater"
highlightText="impact"
Expand Down
4 changes: 2 additions & 2 deletions app/landing/part3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import TextBlock from '../components/TextBlock';
export const LandingPart3 = () => {
return (
<div className="flex h-[calc(0.65*100vh)] min-h-[calc(0.85*760px)] w-full flex-col items-center justify-center gap-20 md:flex-row md:justify-between md:gap-0">
<div className="flex max-w-[560px] flex-col gap-2 font-inter text-4xl font-bold sl:text-2xl">
<div className="flex max-w-[400px] flex-col gap-2 font-inter text-4xl font-bold xl:max-w-[600px] sl:text-2xl">
<TextBlock
mainText="After completion your results will be landed back outside of Pairwise to edit your"
mainText="After completion you will be redirected back to the Optimism website, and your Pairwise ranked projects will be updated on your"
highlightText="Ballot"
description=""
highlightImage={{
Expand Down