-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'plus-1-feature-move' into dev
- Loading branch information
Showing
6 changed files
with
79 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { data } from '../../data.js'; | ||
import { renderList } from '../components/render-list.js'; | ||
|
||
/** | ||
* Entry point for users move a words between the list. | ||
* It is called each time the user clicks the "remembered" or "overlooked" button. | ||
* | ||
* @param {Event} event - The event triggered when the user clicks the button. | ||
*/ | ||
|
||
export const moveItemHandler = (event) => { | ||
/* -- entry point for moving words -- */ | ||
// debugger; | ||
/* -- check the target -- */ | ||
/* -- gather user input from DOM -- */ | ||
// when event happened on "remembered button". | ||
if (event.target.id === 'remembered-button') { | ||
// find the checked items | ||
const checkedNewBox = Array.from( | ||
document.getElementsByClassName('new-list-checkbox'), | ||
).filter((ele) => ele.checked); | ||
const itemsToMove = checkedNewBox.map( | ||
(ele) => | ||
ele.parentElement.parentElement.children[1].children[0].innerHTML, | ||
); | ||
// get rid of the checked items from new list, update data. | ||
data.newWords = data.newWords.filter((ele) => !itemsToMove.includes(ele)); | ||
// add items to remembered list | ||
data.rememberedWords.push(...itemsToMove); | ||
} | ||
// when event happened on "overlooked button". | ||
if (event.target.id === 'overlooked-button') { | ||
// find the checked items | ||
const checkedNewBox = Array.from( | ||
document.getElementsByClassName('rem-list-checkbox'), | ||
).filter((ele) => ele.checked); | ||
const itemsToMove = checkedNewBox.map( | ||
(ele) => | ||
ele.parentElement.parentElement.children[1].children[0].innerHTML, | ||
); | ||
// get rid of the checked items from remembered list, update data. | ||
data.rememberedWords = data.newWords.filter( | ||
(ele) => !itemsToMove.includes(ele), | ||
); | ||
// add items to remembered list | ||
data.newWords.push(...itemsToMove); | ||
} | ||
|
||
/* -- re-render UI -- */ | ||
renderList(data); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { moveItemHandler } from '../handlers/move-word.js'; | ||
|
||
document | ||
.getElementById('remembered-button') | ||
.addEventListener('click', moveItemHandler); | ||
document | ||
.getElementById('overlooked-button') | ||
.addEventListener('click', moveItemHandler); |
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