Skip to content

Commit

Permalink
refactor: add react-rating star component
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Apr 5, 2024
1 parent 7947ffe commit bb32bac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './globals.css';
import '@smastrom/react-rating/style.css';

import type { Metadata, Viewport } from 'next';

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@coinbase/onchainkit": "^0.6.1",
"@next/bundle-analyzer": "^14.1.0",
"@nextui-org/react": "^2.2.9",
"@smastrom/react-rating": "^1.5.0",
"@tanstack/react-query": "^5.24.2",
"@tanstack/react-virtual": "^3.0.2",
"class-variance-authority": "^0.7.0",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 24 additions & 21 deletions src/orgs/components/org-reviews/aggregate-ratings-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Rating, RoundedStar } from '@smastrom/react-rating';

import { DetailsPanelCardWrapper } from '~/shared/components/details-panel/card-wrapper';
import { Heading } from '~/shared/components/heading';
import { Text } from '~/shared/components/text';

import { ORG_RATING_LABELS } from '~/orgs/core/constants';
import { OrgDetails } from '~/orgs/core/schemas';
Expand All @@ -21,17 +24,6 @@ export const AggregateRatingsCard = ({
([, rating]) => rating !== null,
) as [string, number][];

// const ratings = Object.entries({
// benefits: null,
// careerGrowth: 4.5,
// diversityInclusion: 3.9,
// management: 3.4,
// product: 3.3,
// compensation: 4.9,
// onboarding: 4.6,
// workLifeBalance: null,
// }).filter(([, rating]) => rating !== null) as [string, number][];

return (
<DetailsPanelCardWrapper>
<Heading text={HEADING_TEXT} />
Expand All @@ -44,16 +36,21 @@ export const AggregateRatingsCard = ({
key={label}
className="flex shrink-0 flex-wrap items-center justify-start gap-2"
>
<p>{rating.toFixed(1)}</p>
{/* <Rating
count={1}
fractions={5}
value={(rating ?? 0) / 5}
color="gold"
/> */}
<p className="shrink-0">
{ORG_RATING_LABELS[label as keyof typeof ORG_RATING_LABELS]}
</p>
<Text
className="text-base font-bold text-white"
text={rating.toFixed(1)}
/>
<Rating
readOnly
value={rating}
style={{ maxWidth: 120 }}
itemStyles={RATING_ITEM_STYLES}
/>

<Text
className="shrink-0 text-base text-white"
text={ORG_RATING_LABELS[label as keyof typeof ORG_RATING_LABELS]}
/>
</div>
))}
</div>
Expand All @@ -64,3 +61,9 @@ export const AggregateRatingsCard = ({
};

const HEADING_TEXT = 'Aggregate Ratings';

const RATING_ITEM_STYLES = {
itemShapes: RoundedStar,
activeFillColor: '#ffb700',
inactiveFillColor: '#3f3f3f',
};

0 comments on commit bb32bac

Please sign in to comment.