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

Redesigned ratings slider #144

Merged
merged 6 commits into from
Sep 20, 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
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.44.3",
"react-range": "^1.10.0",
"react-router-dom": "^6.8.1",
"typescript": "^4.4.2",
"universal-cookie": "^4.0.4",
Expand Down
81 changes: 64 additions & 17 deletions client/src/components/judge/Ratings.tsx
veermshah marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { getRequest, postRequest, putRequest } from '../../api';
import { errorAlert } from '../../util';
import Button from '../Button';
import { getTrackBackground, Range } from 'react-range';

interface RatingsProps {
callback?: () => void;
Expand Down Expand Up @@ -71,25 +72,71 @@ const Ratings = (props: RatingsProps) => {
};

return (
<div className="flex flex-col align-center">
<div className="flex flex-col mx-4">
{categories.map((v, i) => (
<div key={i}>
<p className="text-center">
<b>{v}</b>: {categoryScores[i]}
</p>
<input
type="range"
min="0"
max="10"
value={categoryScores[i]}
onChange={(e) => {
const newScores = [...categoryScores];
newScores[i] = parseInt(e.target.value);
setCategoryScores(newScores);
if (props.update) submit(newScores);
}}
className="w-full"
/>
<div className="text-light text-mono flex flex-row justify-between">
<p>{v}</p>
<p>{categoryScores[i]}</p>
</div>
<div className="pb-4 pt-1">
{/* React Range Slider */}
<Range
label="Select your value"
step={1}
min={0}
max={10}
values={[categoryScores[i]]}
onChange={(values) => {
const newScores = [...categoryScores];
newScores[i] = values[0];
setCategoryScores(newScores);
if (props.update) submit(newScores);
}}
renderMark={({ props, index }) => (
<div
{...props}
key={props.key}
className={`h-0.5 w-0.5 rounded-full mt-1 ${
index === 0 || index === 10 ? 'opacity-0' : 'opacity-100'
} ${index < categoryScores[i] ? 'bg-primary' : 'bg-black'}`}
/>
)}
renderTrack={({ props, children }) => {
return (
<div
onMouseDown={props.onMouseDown}
onTouchStart={props.onTouchStart}
className="h-6 flex w-full"
style={{ ...props.style }}
>
<div
ref={props.ref}
style={{
background: getTrackBackground({
values: [categoryScores[i]],
colors: ['#00ACE6', '#ccc'],
veermshah marked this conversation as resolved.
Show resolved Hide resolved
min: 0,
max: 10,
}),
}}
className={`h-[6px] w-full rounded-lg self-center`}
>
{children}
</div>
</div>
);
}}
renderThumb={({ props }) => (
<div
{...props}
key={props.key}
className="h-5 w-5 bg-primary rounded-full"
style={{ ...props.style }}
/>
)}
/>
</div>
</div>
))}
{!props.update ? (
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/judge/popups/RatePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const RatePopup = (props: RatePopupProps) => {
<Popup enabled={props.enabled} setEnabled={props.setEnabled}>
<h1 className="text-3xl font-bold text-primary">Judge Project</h1>
<h2 className="text-xl font-bold">Please rate the current project</h2>
<div className="flex flex-col items-center w-full my-4">
<div className="flex flex-col w-full my-4">
<Ratings callback={done} />
</div>
</Popup>
Expand Down
27 changes: 23 additions & 4 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,11 @@ react-hook-form@^7.44.3:
resolved "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.44.3.tgz"
integrity sha512-/tHId6p2ViAka1wECMw8FEPn/oz/w226zehHrJyQ1oIzCBNMIJCaj6ZkQcv+MjDxYh9MWR7RQic7Qqwe4a5nkw==

react-range@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/react-range/-/react-range-1.10.0.tgz#20f56885bd39400084c91c2ae7f9375ed9b22fb5"
integrity sha512-kDo0LiBUHIQIP8menx0UoxTnHr7UXBYpIYl/DR9jCaO1o29VwvCLpkP/qOTNQz5hkJadPg1uEM07XJcJ1XGoKw==

react-refresh@^0.14.0:
version "0.14.0"
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz"
Expand Down Expand Up @@ -1551,8 +1556,16 @@ source-map-js@^1.2.0:
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz"
integrity sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
name string-width-cjs
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -1570,8 +1583,14 @@ string-width@^5.0.1, string-width@^5.1.2:
emoji-regex "^9.2.2"
strip-ansi "^7.0.1"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down