Skip to content

Instantly share code, notes, and snippets.

@zilahir
Created July 2, 2020 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zilahir/77c8b545912fe0e0b94d98ee9a5c38c0 to your computer and use it in GitHub Desktop.
Save zilahir/77c8b545912fe0e0b94d98ee9a5c38c0 to your computer and use it in GitHub Desktop.
tags
function handleTagClick(tag, thisLevel) {
reduxDispatch(getContentByTagId(tag.tag_id, authToken))
setLastClickedTag(tag)
const childTagIds = tag.relations.relation
const isRendered = tagState[thisLevel + 2]
if (isRendered) {
const tempTagState = tagState
Object.keys(tagState).map(curr => {
if (curr > thisLevel + 1) {
setTimeout(() => {
toggleAnimated(currAnimated => ({
...currAnimated,
[curr]: false,
}))
}, 100)
setTimeout(() => {
dispatch({
type: UP,
payload: {
levelToDelete: curr,
},
})
level(-1)
}, 200)
}
return true
})
}
if (childTagIds && !isRendered) {
const thisLevelTags = []
childTagIds.map(childTagId => {
const found = childTag(childTagId, currentLevel + 1)
if (found) {
thisLevelTags.push({
...found,
})
}
return true
})
if (thisLevelTags.length > 0) {
dispatch({
type: DOWN,
payload: {
level: currentLevel + 1,
tags: thisLevelTags,
},
})
setTimeout(() => {
toggleAnimated(currAnimated => (
{
...currAnimated,
[currentLevel + 1]: true,
}
))
}, 10)
level(1)
}
} else if (!childTagIds && (tagState[thisLevel + 1])) {
toggleAnimated(currAnimated => ({
...currAnimated,
[thisLevel + 1]: false,
}))
level(-1)
setTimeout(() => {
dispatch({
type: UP,
payload: {
levelToDelete: thisLevel + 1,
},
})
}, 500)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment