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 4 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
92 changes: 79 additions & 13 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 @@ -77,19 +78,84 @@ const Ratings = (props: RatingsProps) => {
<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="pb-4 pt-2">
{/* 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}
style={{
...props.style,
height: '4px',
width: '4px',
opacity: index == 0 || index == 10 ? 0 : 1,
backgroundColor:
index < categoryScores[i] ? '#00ACE6' : '#646464',

borderRadius: '50%',
marginTop: '1px',
veermshah marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
)}
renderTrack={({ props, children }) => {
return (
<div
onMouseDown={props.onMouseDown}
onTouchStart={props.onTouchStart}
style={{
...props.style,
height: '10px',
display: 'flex',
width: '100%',
veermshah marked this conversation as resolved.
Show resolved Hide resolved
}}
>
<div
ref={props.ref}
style={{
height: '6px',
width: '100%',
borderRadius: '5px',
background: getTrackBackground({
values: [categoryScores[i]],
colors: ['#00ACE6', '#ccc'],
veermshah marked this conversation as resolved.
Show resolved Hide resolved
min: 0,
max: 10,
}),
alignSelf: 'center',
veermshah marked this conversation as resolved.
Show resolved Hide resolved
}}
>
{children}
</div>
</div>
);
}}
renderThumb={({ props }) => (
<div
{...props}
key={props.key}
style={{
...props.style,
height: '20px',
width: '20px',
backgroundColor: '#00ACE6',
borderRadius: '50%',
veermshah marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
)}
/>
</div>
</div>
))}
{!props.update ? (
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