Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

PTL-19 Navigation Arrows #58

Merged
merged 10 commits into from
Mar 23, 2022
Merged

PTL-19 Navigation Arrows #58

merged 10 commits into from
Mar 23, 2022

Conversation

lukiekang
Copy link

Add functionality to allow the navigation arrow buttons to work.

Not entirely sure on my use of Enum here but otherwise hopefully pretty straightforward.

RIGHT = '-rotate-90'
}

const handleNavigationButtonClick = navigationDirection => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These nested functions should really be prepended with an underscore, since they are technically private functions that can not be accessed outside of the scope of the parent function.

const _handleNavigationButtonClick

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think this was a a common pattern in JS? I went down a rabbit hole of researching this its up for debate... I think it being a const with its normal const scoping rules is sufficient imo:

airbnb/javascript#490
https://eslint.org/docs/rules/no-underscore-dangle.html

If oyu feel strongly this should be a thing though, happy to do it.

const currentAssetIndex = assetArray.findIndex(asset => asset.environment === selectedAssetEnvironment)
const firstAssetEnvironment = assetArray[0].environment
const lastAssetEnvironment = assetArray[assetArray.length - 1].environment
let newEnvironment = selectedAssetEnvironment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no benefit to giving the newEnvironment variable a default value equal to selectedAssetEnvironment since one of the conditions underneath will always be true, and so in the end, newEnvironment will never equal selectedAssetEnvironment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this was a fallback for an earlier implementation.

let newEnvironment = selectedAssetEnvironment

if (navigationDirection === NavigationDirection.LEFT) {
newEnvironment = selectedAssetEnvironment === firstAssetEnvironment ? lastAssetEnvironment : assetArray[currentAssetIndex - 1].environment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would do away with the firstAssetEnvironment and lastAssetEnvironment variables and just focus on the index moving positions.

newEnvironment = currentIndex === assetArray.length - 1 ? assetArray[0].environment : assetArray[currentAssetIndex + 1].environment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reworked this slightly, I was trying to make the logic more parsable so I have mostly done what you suggested.

const assetArray = Object.values(selectedAssetGroup)
const isUniqueAcrossEnvironments = assetArray.filter(asset => asset !== null).length === 1

enum NavigationDirection {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably just leave these as plain strings, so as to not over engineer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it maybe easier to read as the Enums vs the classname it relates to but its not a big deal so changed it, see what you think :)

const imageClasses = imageDimensions ? 'opacity-100 transition-opacity duration-500' : 'opacity-0 transition-opacity'

const selectedAssetEnvironment = useAppSelector(getSelectedAssetEnvironment)
const selectedAssetGroup = useAppSelector(getSelectedAssetGroup)

const selectedAsset = selectedAssetGroup[selectedAssetEnvironment]
const {hasMultipleImagesOfThisType, typeIndex, image, heading, isError, environment} = selectedAsset
const {hasMultipleImagesOfThisType, typeIndex, image, heading, environment} = selectedAsset

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the isError value on the PlanAsset type be removed completely now that this modal relies on it's own internal state to determine if there is an error or not?

Refer to line 36 in the Asset component.

@lukiekang lukiekang merged commit 127ffdc into develop Mar 23, 2022
@cpressland cpressland deleted the ptl-19-navigation-arrows branch April 3, 2024 21:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants