-
Notifications
You must be signed in to change notification settings - Fork 9
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
chore: refactor homepage to if/else to preserve existing behaviour #1527
chore: refactor homepage to if/else to preserve existing behaviour #1527
Conversation
56dd050
to
34c3c8f
Compare
52b424f
to
199f675
Compare
src/hooks/useDrag.tsx
Outdated
if (typeof value === "string" && value.startsWith("textcardcard-")) { | ||
const valArr = value.split("-") | ||
const number = valArr[1] | ||
return valArr.length === 2 && !Number.isNaN(Number(number)) |
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.
Nit: I think can just use isNaN
directly without Number.isNaN
?
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.
Is !Number.isNaN(Number(number))
to assert if its a number?
In the case where value is just textcardcard-
, split gives ['textcardcard', '']
!Number.isNaN(Number(number))
evaluates to true here
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.
Eslint prefersNumber.isNaN
because of the implicit coercion inside isNaN
! I opted to use Number.isNan due to this
Good catch for the empty string, fixed in 4cf4b01
const number = valArr[1] | ||
return valArr.length === 2 && !Number.isNaN(Number(number)) | ||
} | ||
if (typeof value === "string") { |
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.
nit: can be an else if
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.
My linter is removing the else ifs here actually, since the if statement returns haha
@@ -184,6 +184,31 @@ export const useDrag: OnDragEndResponseWrapper = ( | |||
return updateHomepageState(result, homepageState) |
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 PR mainly changes the condiitonal logic from switch-case to if-else right? Why does switch-case not support
<subitem name>-<number>
?
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.
^switch case not as powerful as match
sadly enough :/
src/hooks/useDrag.tsx
Outdated
const isUpdateHomepageType = (value: any): value is UpdateHomepageType => { | ||
if (typeof value === "string" && value.startsWith("textcardcard-")) { | ||
const valArr = value.split("-") | ||
const number = valArr[1] |
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.
nit: it might be confusing to see number = valArr[1]
because the variable name number
isn't describing its usage but rather its value.
could we use possibleCardIndex
instead?
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.
Makes sense, e1e6969
199f675
to
96d0ddd
Compare
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.
lgtm - i think we've accumulated quite abit of tech debt HAHA i think is a good time to relook at how we wanna handle dnd in these pages.
just adding on doesn't look to be sustainable :/
src/hooks/useDrag.tsx
Outdated
| `textCardItem-${number}` | ||
|
||
const isUpdateHomepageType = ( | ||
value: any |
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.
nit: chaneg to unknown
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.
…1527) * chore: refactor homepage to if/else to preserve existing behaviour * fix: rebase errors * fix: check for empty string * fix: rename var * fix: add type guards to create and delete and add comments * chore: change to unknown
* chore: add validators * chore: add constants * chore: add new textcard component types * chore: add placeholder preview section * chore: add new homepageDroppableZone type * Feat: add textCards side panel * feat: update useDrag to work with subtextcards * feat: add text card parsing and change handler * Fix: add button styles and restrict cards to 4 * fix: disable save on card error * fix: rebase errors * fix: remove comments * fix: cast text cards once * chore: remove unused updateElement * fix: bug when attempting to create 2 textcard sections before adding text cards Lodash behaviour here is buggy - _.set sets the fields in multiple array items for section data, which was causing errors * chore: rename textcardcard * feat: add help overlay and add feature flag (#1528) * feat: add help overlay and add feature flag * chore: rearrange resource position in add section * IS-456: Text Cards Previews (#1516) * wip: basic cms preview * feat: refactor styles Co-authored-by: Alexander Lee <[email protected]> * feat: enable previews on text-cards * fix: lint issues * feat: update previews to match template Co-authored-by: Alexander Lee <[email protected]> --------- Co-authored-by: Alexander Lee <[email protected]> * chore: refactor homepage to if/else to preserve existing behaviour (#1527) * chore: refactor homepage to if/else to preserve existing behaviour * fix: rebase errors * fix: check for empty string * fix: rename var * fix: add type guards to create and delete and add comments * chore: change to unknown --------- Co-authored-by: Harish <[email protected]> Co-authored-by: Alexander Lee <[email protected]>
Replaces behaviour in
useDrag
for homepage to allow for handling section subitems without changing the existing behaviour. This PR modifies theswitch/cases
toif/else
instead to allow for types of the form<subitem name>-<number>
.