Skip to content

Commit

Permalink
Feat/work experience average section rating api (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
YongChenSu authored Aug 18, 2024
1 parent e279c39 commit 8024c43
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

> .salaryRatingWrapper {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
margin: 12px 0;

@media (min-width: above-small) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const createLinkTo = ({ pageType, id }) => ({

const SNIPPET_SIZE = 30;

const averageSectionRating = 3.8; // for temporary use

const ExperienceEntry = ({
pageType,
data: {
Expand All @@ -34,6 +32,7 @@ const ExperienceEntry = ({
week_work_time: weekWorkTime,
salary,
recommend_to_others: recommendToOthers,
averageSectionRating,
},
size,
canView,
Expand All @@ -46,41 +45,44 @@ const ExperienceEntry = ({
評價 · {formatCreatedAt(createdAt)}
</P>
<div className={styles.salaryRecommendWrapper}>
{weekWorkTime && canView && (
<div className={styles.weekWorkTime}>
<Clock />
{formatWeekWorkTime(weekWorkTime)}
</div>
)}
{salary && (
<div
className={cn(styles.salary, {
[styles.locked]: !canView,
})}
>
{canView ? (
<React.Fragment>
<Coin />
{formatSalary(salary)}
</React.Fragment>
) : (
<React.Fragment>
<FontAwesomeIcon icon={faLock} />
{formatSalaryRange(salary)}
</React.Fragment>
)}
</div>
)}
{averageSectionRating !== null ? (
<div className={styles.overallRatingWrapper}>
<OverallRating rating={averageSectionRating} />
</div>
) : (
<div className={styles.recommendToOthers}>
{recommendToOthers === 'yes' ? <Good /> : <Bad />}
{recommendToOthers === 'yes' ? '推' : '不推'}
</div>
)}
<div className={styles.rowWrapper}>
{weekWorkTime && canView && (
<div className={styles.weekWorkTime}>
<Clock />
{formatWeekWorkTime(weekWorkTime)}
</div>
)}
{salary && (
<div
className={cn(styles.salary, {
[styles.locked]: !canView,
})}
>
{canView ? (
<React.Fragment>
<Coin />
{formatSalary(salary)}
</React.Fragment>
) : (
<React.Fragment>
<FontAwesomeIcon icon={faLock} />
{formatSalaryRange(salary)}
</React.Fragment>
)}
</div>
)}

{averageSectionRating ? (
<div className={styles.overallRatingWrapper}>
<OverallRating rating={averageSectionRating} />
</div>
) : (
<div className={styles.recommendToOthers}>
{recommendToOthers === 'yes' ? <Good /> : <Bad />}
{recommendToOthers === 'yes' ? '推' : '不推'}
</div>
)}
</div>
</div>
</div>

Expand Down Expand Up @@ -112,6 +114,7 @@ const ExperienceEntry = ({
ExperienceEntry.propTypes = {
canView: PropTypes.bool.isRequired,
data: PropTypes.shape({
averageSectionRating: PropTypes.number,
created_at: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
job_title: PropTypes.shape({ name: PropTypes.string.isRequired })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@

> .salaryRecommendWrapper {
display: flex;
justify-content: space-between;
margin: 12px 0;

@media (min-width: above-small) {
margin: 0;
justify-content: flex-start;
}
flex-direction: column;

.weekWorkTime,
.salary,
Expand All @@ -57,12 +52,6 @@
align-items: center;
font-size: 15px;
color: #424242;
}

.salary,
.weekWorkTime,
.recommendToOthers {
margin-left: 35px;

svg {
margin-right: 7px;
Expand All @@ -77,6 +66,22 @@
color: #ed0d5e;
}
}

.rowWrapper {
display: flex;
flex-wrap: wrap;
gap: 1rem;
justify-content: flex-start;
}

@media (min-width: above-small) {
margin: 0;
justify-content: flex-start;

.rowWrapper {
gap: 2.5rem;
}
}
}
}

Expand Down Expand Up @@ -154,5 +159,5 @@
}

.overallRatingWrapper {
margin-left: 1.5rem;
margin: 0;
}
4 changes: 2 additions & 2 deletions src/components/ExperienceDetail/Article/ArticleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ InterviewInfoBlocks.propTypes = {

const WorkInfoBlocks = ({ experience, hideContent }) => {
const expInYearText = formatExperienceInYear(experience.experience_in_year);
const averageSectionRating = 3.62; // for temporary use
return (
<Fragment>
<InfoBlock
Expand Down Expand Up @@ -167,7 +166,7 @@ const WorkInfoBlocks = ({ experience, hideContent }) => {
</InfoBlock>
) : null}
<RatingInfo
rating={averageSectionRating}
rating={experience.averageSectionRating}
recommend={experience.recommend_to_others}
/>
</Fragment>
Expand All @@ -176,6 +175,7 @@ const WorkInfoBlocks = ({ experience, hideContent }) => {

WorkInfoBlocks.propTypes = {
experience: PropTypes.shape({
averageSectionRating: PropTypes.number,
company: PropTypes.shape({
name: PropTypes.string,
}),
Expand Down
8 changes: 5 additions & 3 deletions src/components/ExperienceDetail/Article/InfoBlock.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react';
import { Link } from 'react-router-dom';
import cn from 'classnames';
import PropTypes from 'prop-types';
import { P } from 'common/base';
import styles from './InfoBlock.module.css';

const InfoBlock = ({ label, to, children }) => (
<li className={styles.block}>
const InfoBlock = ({ label, to, children, noMargin }) => (
<li className={`${styles.block}`}>
<P size="m" className={styles.label}>
{label}
</P>
<P size="m" className={styles.content}>
<P size="m" className={cn(styles.content, { [styles.noMargin]: noMargin })}>
{to ? <Link to={to}>{children}</Link> : children}
</P>
</li>
Expand All @@ -18,6 +19,7 @@ const InfoBlock = ({ label, to, children }) => (
InfoBlock.propTypes = {
children: PropTypes.node,
label: PropTypes.string.isRequired,
noMargin: PropTypes.bool,
to: PropTypes.string,
};

Expand Down
8 changes: 7 additions & 1 deletion src/components/ExperienceDetail/Article/InfoBlock.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@value gray-dark from "../../common/variables.module.css";
@value above-mobile, gray-dark from "../../common/variables.module.css";

.block {
display: flex;
Expand Down Expand Up @@ -30,3 +30,9 @@
}
}
}

.content.noMargin {
@media (max-width: above-mobile) {
margin-left: 0px;
}
}
2 changes: 1 addition & 1 deletion src/components/ExperienceDetail/Article/RatingInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RecommendationIcon.propTypes = {
const RatingInfo = ({ rating, recommend }) => {
if (rating > 0) {
return (
<InfoBlock label="整體評價">
<InfoBlock label="整體評價" noMargin>
<OverallRating rating={rating} hasRatingLabel />
</InfoBlock>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/OverallRating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Rating = ({ rating, textYellow }) => (
[styles.textYellow]: !textYellow,
})}
>
{rating}
{rating.toFixed(1)}
</div>
);

Expand Down
16 changes: 7 additions & 9 deletions src/components/common/OverallRating/Rating.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@value main-yellow, yellow-light from "../../common/variables.module.css";
@value below-mobile, main-yellow, yellow-light from "../../common/variables.module.css";

.overallRating {
display: flex;
Expand All @@ -11,15 +11,15 @@
}

.rating {
margin: 0 1rem 0 0;
margin: 0 0.5rem 0 0;
}

.textYellow {
color: main-yellow;
}

.ratingLabel {
margin-left: 10px;
margin-left: 1.5rem;
display: inline-block;
padding: 4px 16px;
background-color: yellow-light;
Expand Down Expand Up @@ -48,13 +48,11 @@
border-right-color: yellow-light;
}

@media (max-width: 430px) {
@media (max-width: below-mobile) {
.overallRating {
flex-direction: column;
align-items: flex-start;
flex-direction: row;
}

.rating {
margin: 0 0 2px 0;
.ratingLabel {
margin-left: 0.5rem;
}
}
11 changes: 6 additions & 5 deletions src/components/common/OverallRating/Thumbs.module.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
@value below-mobile, main-yellow, yellow-light from "../../common/variables.module.css";

.thumbsContainer {
display: flex;
align-items: center;
width: 9rem;
width: 120px;
justify-content: space-between;
margin-right: 1.5rem;
}

.thumb {
width: 18px;
height: 28px;
width: 24px;
height: 24px;
}

.thumbContainer {
Expand All @@ -28,7 +29,7 @@
clip-path: polygon(0 0, var(--clip-x) 0, var(--clip-x) 100%, 0 100%);
}

@media (max-width: 430px) {
@media (max-width: below-mobile) {
.thumbsContainer {
width: 8rem;
margin-right: 0.5rem;
Expand Down
18 changes: 8 additions & 10 deletions src/components/common/OverallRating/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import Thumbs from './Thumbs';
import { Rating, RatingLabel } from './Rating';
import styles from './Rating.module.css';

const OverallRating = ({ rating, hasRatingLabel }) => {
return (
<div className={cn(styles.overallRating)}>
<Rating rating={rating} textYellow={hasRatingLabel} />
<div className={styles.ratingInfo}>
<Thumbs rating={rating} />
{hasRatingLabel && <RatingLabel rating={rating} />}
</div>
const OverallRating = ({ rating, hasRatingLabel }) => (
<div className={cn(styles.overallRating)}>
<Rating rating={rating} textYellow={hasRatingLabel} />
<div className={styles.ratingInfo}>
<Thumbs rating={rating} />
{hasRatingLabel && <RatingLabel rating={rating} />}
</div>
);
};
</div>
);

OverallRating.propTypes = {
hasRatingLabel: PropTypes.bool,
Expand Down
1 change: 1 addition & 0 deletions src/graphql/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const getCompanyQuery = /* GraphQL */ `
reply_count
like_count
recommend_to_others
averageSectionRating
}
salary_work_times {
id
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const queryExperienceGql = /* GraphQL */ `
}
week_work_time
recommend_to_others
averageSectionRating
}
}
}
Expand Down Expand Up @@ -151,6 +152,7 @@ export const queryRelatedExperiencesGql = /* GraphQL */ `
}
week_work_time
recommend_to_others
averageSectionRating
}
}
}
Expand Down

0 comments on commit 8024c43

Please sign in to comment.