-
Notifications
You must be signed in to change notification settings - Fork 7
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
Restrict splash to one story #1753
Open
Georges-GNM
wants to merge
15
commits into
main
Choose a base branch
from
gl/restrict-splash-to-one-item-in-flex-gen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
995d894
wip commit - added splash and number of cards in group to insert logic
Georges-GNM e2db32a
wip commit - functioning insert to bottom of group case
Georges-GNM 6000ecd
tidy - inserting to empty splash works, inserting at bottom or top mo…
Georges-GNM 0aeabb9
include handle move logic - same level of functioning
Georges-GNM 1d92923
working move/insert to top of splash
Georges-GNM 2627db1
lint
Georges-GNM bcd61f0
remove unused imports
Georges-GNM 9ce3b34
Indicate new props as optional
Georges-GNM ca8133a
add new props to dnd test
Georges-GNM a45c6cb
remove unnecessary number of cards in group prop
Georges-GNM 86888cc
rename groupsIds to groupIds
Georges-GNM 0fd3c18
access groupIds in collection instead of taken from state and adding …
Georges-GNM f8136cf
lint
Georges-GNM d474ce4
refactor if statements to use early returns
Georges-GNM 058b84e
refactor to add dropSource variable from isDropFromCapiFeed
Georges-GNM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,13 +179,159 @@ class FrontContent extends React.Component<FrontProps, FrontState> { | |
} | ||
|
||
public handleMove = (move: Move<TCard>) => { | ||
events.dropArticle(this.props.id, 'collection'); | ||
this.props.moveCard(move.to, move.data, move.from || null, 'collection'); | ||
const numberOfArticlesAlreadyInGroup = move.to.cards?.length; | ||
|
||
// if we are inserting an article into any group that is not the splash, then we just insert | ||
if (move.to.groupName !== 'splash') { | ||
events.dropArticle(this.props.id, 'collection'); | ||
this.props.moveCard(move.to, move.data, move.from || null, 'collection'); | ||
} else { | ||
// if we're in the splash and we insert an article and there's no other article already in the splash, then we just insert | ||
if (numberOfArticlesAlreadyInGroup === 0 || undefined) { | ||
events.dropArticle(this.props.id, 'collection'); | ||
this.props.moveCard( | ||
move.to, | ||
move.data, | ||
move.from || null, | ||
'collection', | ||
); | ||
} | ||
// if we're in the splash and we insert an article and there's already another article, then we also look at the index we're inserting to | ||
// if we're inserting to index 0, i.e. top of the group, then we want to grab the pre-existing article and move it to the other group | ||
else if ( | ||
!!move.to.groupIds && | ||
move.to.cards !== undefined && | ||
move.to.index === 0 | ||
) { | ||
//we do the regular move steps for the article we're moving to splash | ||
events.dropArticle(this.props.id, 'collection'); | ||
this.props.moveCard( | ||
move.to, | ||
move.data, | ||
move.from || null, | ||
'collection', | ||
); | ||
|
||
//then we need to move the other article to the other group | ||
const otherGroup = move.to.groupIds.filter( | ||
(groupId) => groupId !== move.to.id, | ||
)[0]; | ||
const existingCardData = move.to.cards[0]; | ||
const existingCardTo = { | ||
index: 0, | ||
id: otherGroup, | ||
type: 'group', | ||
groupIds: move.to.groupIds, | ||
}; | ||
const existingCardMoveData: Move<TCard> = { | ||
data: existingCardData, | ||
from: false, | ||
to: existingCardTo, | ||
}; | ||
this.handleMove(existingCardMoveData); | ||
} | ||
|
||
// if we're in the splash and we insert an article and there's already another article, then we also look at the index we're inserting to | ||
// if we're inserting to index 1, i.e. bottom of the group, then we add this story to the other group | ||
else if ( | ||
!!move.to.groupIds && | ||
!!numberOfArticlesAlreadyInGroup && | ||
numberOfArticlesAlreadyInGroup > 0 && | ||
move.to.index > 0 | ||
) { | ||
const otherGroup = move.to.groupIds.filter( | ||
(groupId) => groupId !== move.to.id, | ||
)[0]; | ||
|
||
const amendedTo = { | ||
index: 0, | ||
id: otherGroup, | ||
type: 'group', | ||
groupIds: move.to.groupIds, | ||
}; | ||
events.dropArticle(this.props.id, 'collection'); | ||
|
||
this.props.moveCard( | ||
amendedTo, | ||
move.data, | ||
move.from || null, | ||
'collection', | ||
); | ||
} | ||
} | ||
}; | ||
|
||
public handleInsert = (e: React.DragEvent, to: PosSpec) => { | ||
events.dropArticle(this.props.id, isDropFromCAPIFeed(e) ? 'feed' : 'url'); | ||
this.props.insertCardFromDropEvent(e, to, 'collection'); | ||
const numberOfArticlesAlreadyInGroup = to.cards?.length; | ||
|
||
// if we are inserting an article into any group that is not the splash, then we just insert | ||
if (to.groupName !== 'splash') { | ||
events.dropArticle(this.props.id, isDropFromCAPIFeed(e) ? 'feed' : 'url'); | ||
this.props.insertCardFromDropEvent(e, to, 'collection'); | ||
} else { | ||
// if we're in the splash and we insert an article and there's no other article already in the splash, then we just insert | ||
if (numberOfArticlesAlreadyInGroup === 0 || undefined) { | ||
events.dropArticle( | ||
this.props.id, | ||
isDropFromCAPIFeed(e) ? 'feed' : 'url', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
); | ||
this.props.insertCardFromDropEvent(e, to, 'collection'); | ||
} | ||
// if we're in the splash and we insert an article and there's already another article, then we also look at the index we're inserting to | ||
// if we're inserting to index 0, i.e. top of the group, then we want to grab the pre-existing article and move it to the other group | ||
else if (!!to.groupIds && to.cards !== undefined && to.index === 0) { | ||
// we do the regular insert steps for the article we're inserting to splash | ||
events.dropArticle( | ||
this.props.id, | ||
isDropFromCAPIFeed(e) ? 'feed' : 'url', | ||
); | ||
this.props.insertCardFromDropEvent(e, to, 'collection'); | ||
|
||
//then we need to move the other article to the other group | ||
|
||
const otherGroup = to.groupIds.filter( | ||
(groupId) => groupId !== to.id, | ||
)[0]; | ||
const existingCardData = to.cards[0]; | ||
const existingCardTo = { | ||
index: 0, | ||
id: otherGroup, | ||
type: 'group', | ||
groupIds: to.groupIds, | ||
}; | ||
const existingCardMoveData: Move<TCard> = { | ||
data: existingCardData, | ||
from: false, | ||
to: existingCardTo, | ||
}; | ||
this.handleMove(existingCardMoveData); | ||
} | ||
|
||
// if we're in the splash and we insert an article and there's already another article, then we also look at the index we're inserting to | ||
// if we're inserting to index 1, i.e. bottom of the group, then we add this story to the other group | ||
else if ( | ||
!!to.groupIds && | ||
!!numberOfArticlesAlreadyInGroup && | ||
numberOfArticlesAlreadyInGroup > 0 && | ||
to.index > 0 | ||
) { | ||
const otherGroup = to.groupIds.filter( | ||
(groupId) => groupId !== to.id, | ||
)[0]; | ||
|
||
const amendedTo = { | ||
index: 0, | ||
id: otherGroup, | ||
type: 'group', | ||
groupIds: to.groupIds, | ||
}; | ||
events.dropArticle( | ||
this.props.id, | ||
isDropFromCAPIFeed(e) ? 'feed' : 'url', | ||
); | ||
this.props.insertCardFromDropEvent(e, amendedTo, 'collection'); | ||
} | ||
} | ||
}; | ||
|
||
public render() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 find the nested if else quite difficult to parse, what would you think about refactoring this code to use early returns instead? I think it might make this decision logic easier to follow.