-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: unique number into button #393
base: main
Are you sure you want to change the base?
feat: unique number into button #393
Conversation
Your pull request title did not conform to conventional commits standards. Our upcoming automated release pipeline will automatically determine
|
1 similar comment
Your pull request title did not conform to conventional commits standards. Our upcoming automated release pipeline will automatically determine
|
Your pull request title did not conform to conventional commits standards. Our upcoming automated release pipeline will automatically determine
|
Please include screenshots of before/after your changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/shared/types/ThemeColors.ts
Outdated
@@ -6,6 +6,7 @@ export const colors = { | |||
ut: { | |||
burntorange: '#BF5700', | |||
black: '#333F48', | |||
white: '#FFFFFF', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. White is already provided by unocss as a color, e.g. text-white
. To use the white you made here, it w would be text-ut-white
, but again, this doesn't need to be here since pure white is just a color and not specific to our design system.
@@ -34,13 +36,13 @@ export default function PopupCourseBlock({ | |||
dragHandleProps, | |||
}: PopupCourseBlockProps): JSX.Element { | |||
const [enableCourseStatusChips, setEnableCourseStatusChips] = useState<boolean>(false); | |||
const [isCopied, setIsCopied] = useState<boolean>(false); // Add state to track if copied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment here is unnecessary, isCopied
with useState<boolean>
is clear enough 👍
className='bg-transparent px-2 py-0.25 text-white btn' | ||
color={colors.secondaryColor} | ||
onClick={handleCopy} | ||
style={{ display: 'flex', backgroundColor: colors.secondaryColor, color: 'text-white' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few things here:
- Unless there's something I'm not seeing,
display: 'flex'
here should just be theflex
class, instead of in thestyle
- 'text-white' is not a valid CSS color, it should be just 'white' if you want white. There is a class called
text-white
which would work here, but [see next point] - I think that the text color should be based on the contrast compared to the secondary color, not always white. @IsaDavRod and @Razboy20 might have more info on if that's necessary. It would be something like the line above
const fontColor = pickFontColor(colors.primaryColor);
but for the secondary color
using the backgroundColor: colors.secondaryColor
in style
makes sense though, since there aren't classes for those 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pnpm-lock.yaml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't change, since you didn't install any new packages for this. You might be using an outdated version of pnpm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revert back the files that don't require/shouldn't be changed.
public/json/departments.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't change as your PR didn't need changes here. Are you formatting via pnpm run prettier:fix
, manually, or another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it seems to be auto formatting? I checked my settings and turned the option that I thought was causing the issue off, but it still seems to be auto formatting. What I ended up doing is just copy paste the files that changed from the main branch.
<div | ||
onClick={handleClick} | ||
className={clsx( | ||
'h-full w-full inline-flex items-center justify-center gap-1 rounded pr-3 focusable cursor-pointer text-left', | ||
className | ||
)} | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than making a new div here, the onClick should stay where it originally was.
const handleCopy = () => { | ||
navigator.clipboard.writeText(formattedUniqueId); | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 1000); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an e: MouseEvent
should be accepted as the first argument, and e.preventDefault()
should be called, as to not also open a background calendar tab when clicking on this button.
(will happen when the other PR comment is resolved)
const handleCopy = () => { | ||
navigator.clipboard.writeText(formattedUniqueId); | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you copy the text twice, the previous timeout isn't cancelled, thus the check icon can disappear faster than expected. Rather, a better methodology would be to debounce when the copy state is set to false. (Can probably be done by having the timeout id (returned by setTimeout) be stored in isCopied (perhaps renamed to copyTimeoutId)—it should be set to undefined when it is not active, and to an id when it is.
attempt to clearTimeout(timeoutId)
, then setTimeoutId(setTImeout(...))
. or similar.
Feel free to ping on discord for advice :)
…m/nikshitak/UT-Registration-Plus into feature/unique-number-into-button
82c75e6
to
79e283b
Compare
const formattedUniqueId = course.uniqueId.toString().padStart(5, '0'); | ||
const [copyTimeoutId, setCopyTimeoutId] = useState<NodeJS.Timeout | undefined>(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyTimeoutId
should be a ref (useRef), not a useState, since setState calls are queued until the next render. not doing so could lead to issues when a user clicks multiple times in the same render (aside: does that even matter 🤔)
edit: I would store whether we're currently waiting in another state, and the timeout id in a ref
|
||
const handleClick = async () => { | ||
await background.switchToCalendarTab({ uniqueId: course.uniqueId }); | ||
window.close(); | ||
}; | ||
|
||
const handleCopy = (event: React.MouseEvent<HTMLElement>) => { | ||
if (copyTimeoutId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for copyTimeoutId !== undefined
, since
- It's technically possible for the timeout id to be 0
- You initialize it to undefined
- You check for undefined later
|
||
<button | ||
className='flex bg-transparent px-2 py-0.25 text-white btn' | ||
color={colors.secondaryColor} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you set backgroundColor
and the text color
in the style
prop, what's the point of this color
prop?
@@ -91,6 +108,20 @@ export default function PopupCourseBlock({ | |||
<StatusIcon status={course.status} className='h-5 w-5' /> | |||
</div> | |||
)} | |||
|
|||
<button | |||
className='flex bg-transparent px-2 py-0.25 text-white btn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is text-white
(applies color: #FFFFFF
via CSS) here, when you set the text color
in the style
prop? (text-white
, being a class, is completely overridden by color: buttonColor
, since style
has greater precedence than class[Name]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please address Sam's comment about timeout (if you spam click the button, the checkmark will show for a longer time after the last click)
- Can the minimum height of the course block's div be 50px?
- Can the height of the unique number copy button be 30px?
- It looks like this PR disables some functionality too. When the user clicks the course block in the main popup, it should open the Calendar view and the respective injected cc popup. See prod build as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review previous comments and fix the merge conflict.
…ind code, fixed previous bugs
…er-into-button' into feature/unique-number-into-button
I looked at the Chromatic error and it seemed like the error was stemming from the CourseCatalogInjectedPopup component, but I don't think anything in |
> | ||
<div | ||
style={{ | ||
backgroundColor: colors.secondaryColor, | ||
}} | ||
className='flex items-center self-stretch rounded rounded-r-0 cursor-move!' | ||
{...dragHandleProps} | ||
onClick={handleClick} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this handleClick was moved to the wrong place, you should be able to click on the PopupCourseBlock and be taken to the calendar to that specific course, with the exception being a click on the unique button
@@ -96,6 +114,19 @@ export default function PopupCourseBlock({ | |||
<StatusIcon status={course.status} className='h-5 w-5' /> | |||
</div> | |||
)} | |||
|
|||
<button | |||
className='flex bg-transparent px-2 py-0.25 text-white btn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the intention of the bg-transparent
here?
@@ -96,6 +114,19 @@ export default function PopupCourseBlock({ | |||
<StatusIcon status={course.status} className='h-5 w-5' /> | |||
</div> | |||
)} | |||
|
|||
<button | |||
className='flex bg-transparent px-2 py-0.25 text-white btn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (copyWait !== undefined) { | ||
clearTimeout(copyWait); | ||
} | ||
|
||
event.preventDefault(); | ||
navigator.clipboard.writeText(formattedUniqueId); | ||
copyTimeoutIdRef.current += 250; | ||
|
||
const newTimeoutId = setTimeout(() => { | ||
setCopyWait(undefined); | ||
}, copyTimeoutIdRef.current); | ||
setCopyWait(newTimeoutId); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes it so that each subsequent click makes the checkmark show for 250 more milliseconds
when I said to use a ref, I meant use a ref to hold the timeout id, I meant something like
const [showCopyIcon, setShowCopyIcon] = useState<boolean>(false);
const copyTimeoutRef = useRef<number | undefined>(undefined);
// ...
const handleCopy = (event: React.MouseEvent<HTMLElement>) {
if (copyTimeoutRef.current !== undefined) {
clearTimeout(copyTimeoutRef.current);
}
event.preventDefault();
navigator.clipboard.writeText(formattedUniqueId);
showCopyIcon(true);
copyTimeoutRef.current = window.setTimeout(() => {
showCopyIcon(false);
}, 750);
};
probably should bring in a react-friendly debouncing function instead of writing this from scratch, though, since there are most likely other places that will need debouncing and it's easy to get wrong
Added a button that lets users copy the unique course ID. There's a checkmark that pops up indicating that the ID has been successfully copied. Button design follows figma wireframe.
Resolves #359
This change is