Skip to content
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

for - 5: feature edit #24

Merged
merged 43 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e4f8f37
feature add
AlinaTaoRao Feb 25, 2022
881e2fa
lint
AlinaTaoRao Feb 25, 2022
95b55c2
lint
AlinaTaoRao Feb 25, 2022
ebc463d
lint test
AlinaTaoRao Feb 25, 2022
ac22134
rewrite render list functin
AlinaTaoRao Feb 26, 2022
a779427
lint
AlinaTaoRao Feb 26, 2022
4563590
feature remove word
AlinaTaoRao Feb 26, 2022
f991479
lint
AlinaTaoRao Feb 26, 2022
1c81258
edited intro and remove word function
AlinaTaoRao Feb 27, 2022
8a4d5fc
edited sort feature
AlinaTaoRao Feb 27, 2022
b661abb
edited sort string test
AlinaTaoRao Feb 27, 2022
e74dd79
edit Enter key feature
AlinaTaoRao Feb 27, 2022
da675de
edited feature move words
AlinaTaoRao Feb 27, 2022
282c9bb
add feature edit
AlinaTaoRao Mar 2, 2022
53a71cd
remove edit discarde version
AlinaTaoRao Mar 2, 2022
5c57b58
fix linting error
AlinaTaoRao Mar 2, 2022
f9b860c
fix linting Cognitive Complexity in js, add empty line css
AlinaTaoRao Mar 2, 2022
f005263
fix lint problem
AlinaTaoRao Mar 2, 2022
732f5a1
fix lint error
AlinaTaoRao Mar 2, 2022
d80d0df
lint error
AlinaTaoRao Mar 2, 2022
252243b
fix cognitive complexity issue
AlinaTaoRao Mar 2, 2022
def8516
add target-logic
AlinaTaoRao Mar 2, 2022
c4938b3
Fix lint error
AlinaTaoRao Mar 2, 2022
b7cc3db
fix lint error
AlinaTaoRao Mar 2, 2022
240d1c4
fix lint error
AlinaTaoRao Mar 2, 2022
79c4870
add edit listerner when render
AlinaTaoRao Mar 2, 2022
2d7e47c
fix lint error
AlinaTaoRao Mar 2, 2022
b9fcfc3
lint error
AlinaTaoRao Mar 2, 2022
bf47fdb
split into two independant handlers
AlinaTaoRao Mar 3, 2022
fec12dc
fix lint try1
AlinaTaoRao Mar 3, 2022
e96b701
fix lint try2
AlinaTaoRao Mar 3, 2022
4b8e502
Further splitting of Enter handlers
AlinaTaoRao Mar 3, 2022
e115da9
fix lint try 3
AlinaTaoRao Mar 3, 2022
5117014
peel listener from render & refractor edit handler
AlinaTaoRao Mar 3, 2022
315468a
Enable lint
AlinaTaoRao Mar 3, 2022
a8625e5
added feature update components
AlinaTaoRao Mar 3, 2022
09311e3
fix lint
AlinaTaoRao Mar 3, 2022
47a1027
fix lint error 'document undefined'
AlinaTaoRao Mar 3, 2022
cc2edda
replace label with text field
AlinaTaoRao Mar 3, 2022
3e70d09
css media
AlinaTaoRao Mar 4, 2022
6047d0d
fix linting 1
AlinaTaoRao Mar 4, 2022
5d5e6aa
fix lint 2
AlinaTaoRao Mar 4, 2022
4c67f96
fix lint "no-missing-end-of-source-newline"
AlinaTaoRao Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions client/data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* @property {string[]} words - An array of words that the user has provided.
* @property {string[]} newWords - An array of words that the user has provided.
* @property {string[]} rememberedWords - An array of words that the user has moved from new words list.
* @property {string} sort - A string indicating the order string should be displayed in the UI.
*/
export const data = {
words: [],
sort: 'oldest',
newWords: [],
rememberedWords: [],
sortType: 'oldest',
// Below properties are for feature edit
// isEditing: false,
isEditingNew: false,
isEditingRem: false,
indexWordNew: null,
indexWordRemembered: null,
};
Binary file added client/public/description-edit-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/public/pen-to-square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/trash-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/public/trash-can.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions client/src/components/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Procedures

## renderList

- Render components to UI.
- It export to:
- init
- handlers
105 changes: 105 additions & 0 deletions client/src/components/render-list-bak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Render components to UI.
*
* @param {object} [data = {}] - An object which contain two word lists and a sort type.
*/
export const renderList = (data) => {
// debugger;
// get words to render
const toRenderNew = data.newWords;
const toRenderRemembered = data.rememberedWords;

// create table element for new list and remembered list
const tableElNew = document.createElement('table');
const tableElRemembered = document.createElement('table');

// create components for new list
for (const item of toRenderNew) {
// create tr and td
const trElNew = document.createElement('tr');
const tdElNewForCheck = document.createElement('td');
const tdElNewForLabel = document.createElement('td');
const tdElNewForEdit = document.createElement('td');
const tdElNewForTrash = document.createElement('td');

// create table data items
const inputElNewForCheck = document.createElement('input');
inputElNewForCheck.type = 'checkbox';
inputElNewForCheck.className = 'new-list-checkbox'; // set class name for check box of new list.
const labelElNewForWord = document.createElement('label');
// const labelElNewForWord = document.createElement('input');
labelElNewForWord.className = 'new-list-label'; // set class name of label for edit in new list.
labelElNewForWord.innerText = item;
labelElNewForWord.tabIndex = '-1';
// use img instead of icon
const imgElNewForEdit = document.createElement('img');
const imgElNewForTrash = document.createElement('img');
imgElNewForEdit.src = 'client/public/description-edit-3.png';
imgElNewForTrash.src = 'client/public/trash-2.png';
imgElNewForEdit.className = 'new-pen';
imgElNewForTrash.className = 'new-trash';

// append to td
tdElNewForCheck.appendChild(inputElNewForCheck); // check box
tdElNewForLabel.appendChild(labelElNewForWord); // label with word
tdElNewForEdit.appendChild(imgElNewForEdit); // pen icon
tdElNewForTrash.appendChild(imgElNewForTrash); // trash icon

// append to tr
trElNew.appendChild(tdElNewForCheck);
trElNew.appendChild(tdElNewForLabel);
trElNew.appendChild(tdElNewForEdit);
trElNew.appendChild(tdElNewForTrash);
// append to table
tableElNew.appendChild(trElNew);
}

// create components for remembered list
for (const ele of toRenderRemembered) {
// create tr and td
const trElRemembered = document.createElement('tr');
const tdElRememberedForCheck = document.createElement('td');
const tdElRememberedForLabel = document.createElement('td');
const tdElRememberedForEdit = document.createElement('td');
const tdElRememberedForTrash = document.createElement('td');

// create table data items
const inputElRememberedForCheck = document.createElement('input');
inputElRememberedForCheck.type = 'checkbox';
inputElRememberedForCheck.className = 'rem-list-checkbox'; // set class name for check box of remembered list.
const labelElRememberedForWord = document.createElement('label');
// const labelElRememberedForWord = document.createElement('input');
labelElRememberedForWord.className = 'rem-list-label'; // set class name of label for edit in remembered list.
labelElRememberedForWord.innerText = ele;
labelElRememberedForWord.tabIndex = '-1';
// use img instead of icon
const imgElRememberedForEdit = document.createElement('img');
const imgElRememberedForTrash = document.createElement('img');
imgElRememberedForEdit.src = 'client/public/description-edit-3.png';
imgElRememberedForTrash.src = 'client/public/trash-2.png';
imgElRememberedForEdit.className = 'rem-pen';
imgElRememberedForTrash.className = 'rem-trash';

// append to td
tdElRememberedForCheck.appendChild(inputElRememberedForCheck); // check box
tdElRememberedForLabel.appendChild(labelElRememberedForWord); // label with word
tdElRememberedForEdit.appendChild(imgElRememberedForEdit); // pen icon
tdElRememberedForTrash.appendChild(imgElRememberedForTrash); // trash icon

// append to tr
trElRemembered.appendChild(tdElRememberedForCheck);
trElRemembered.appendChild(tdElRememberedForLabel);
trElRemembered.appendChild(tdElRememberedForEdit);
trElRemembered.appendChild(tdElRememberedForTrash);
// append to table
tableElRemembered.appendChild(trElRemembered);
}

// clear container and append new tables to container
document.getElementById('new-list-container').innerHTML = '';
document.getElementById('remembered-list-container').innerHTML = '';
document.getElementById('new-list-container').appendChild(tableElNew);
document
.getElementById('remembered-list-container')
.appendChild(tableElRemembered);
};
146 changes: 137 additions & 9 deletions client/src/components/render-list.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,140 @@
// document this function!
export const renderList = (toRender = []) => {
const ulEl = document.createElement('ul');

for (const nextItem of toRender) {
const liEl = document.createElement('li');
liEl.innerText = nextItem;
ulEl.appendChild(liEl);
/**
* Render components of the New table on the UI.
*
* @param {object} [data = {}] - An object which contain two word lists and a sort type.
*/
const renderListNew = (data) => {
// debugger;

// get words to render
const toRenderNew = data.newWords;
// create table element for new list
const tableElNew = document.createElement('table');

// create components for new list
for (const item of toRenderNew) {
// create tr and td
const trElNew = document.createElement('tr');
const tdElNewForCheck = document.createElement('td');
const tdElNewForLabel = document.createElement('td');
const tdElNewForEdit = document.createElement('td');
const tdElNewForTrash = document.createElement('td');

// create table data items
const inputElNewForCheck = document.createElement('input');
inputElNewForCheck.type = 'checkbox';
inputElNewForCheck.className = 'new-list-checkbox'; // set class name for check box of new list.
const inputElNewForTextField = document.createElement('input');
inputElNewForTextField.type = 'text';
inputElNewForTextField.className = 'new-list-text'; // set class name of text field in new list.
inputElNewForTextField.disabled = true; // disable the text field at creation
inputElNewForTextField.value = item;

// use img instead of icon
const imgElNewForEdit = document.createElement('img');
const imgElNewForTrash = document.createElement('img');
imgElNewForEdit.src = 'client/public/description-edit-3.png';
imgElNewForTrash.src = 'client/public/trash-2.png';
imgElNewForEdit.className = 'new-pen';
imgElNewForTrash.className = 'new-trash';

// append to td
tdElNewForCheck.appendChild(inputElNewForCheck); // check box
tdElNewForLabel.appendChild(inputElNewForTextField); // text field with word
tdElNewForEdit.appendChild(imgElNewForEdit); // pen icon
tdElNewForTrash.appendChild(imgElNewForTrash); // trash icon
// append to tr
trElNew.appendChild(tdElNewForCheck);
trElNew.appendChild(tdElNewForLabel);
trElNew.appendChild(tdElNewForEdit);
trElNew.appendChild(tdElNewForTrash);
// append to table
tableElNew.appendChild(trElNew);
}

return ulEl;
// clear container and append new tables to container
document.getElementById('new-list-container').innerHTML = '';
document.getElementById('new-list-container').appendChild(tableElNew);
};

/**
* Render components of the Rem table on the UI.
*
* @param {object} [data = {}] - An object which contain two word lists and a sort type.
*/
const renderListRem = (data) => {
// debugger;
// get words to render
const toRenderRemembered = data.rememberedWords;

// create table element for remembered list
const tableElRemembered = document.createElement('table');

// create components for remembered list
for (const item of toRenderRemembered) {
// create tr and td
const trElRemembered = document.createElement('tr');
const tdElRememberedForCheck = document.createElement('td');
const tdElRememberedForLabel = document.createElement('td');
const tdElRememberedForEdit = document.createElement('td');
const tdElRememberedForTrash = document.createElement('td');

// create table data items
const inputElRememberedForCheck = document.createElement('input');
inputElRememberedForCheck.type = 'checkbox';
inputElRememberedForCheck.className = 'rem-list-checkbox'; // set class name for check box of remembered list.
const inputElRemForTextField = document.createElement('input');
inputElRemForTextField.type = 'text';
inputElRemForTextField.className = 'rem-list-text'; // set class name of text field in new list.
inputElRemForTextField.disabled = true; // disable the text field at creation
inputElRemForTextField.value = item;

// use img instead of icon
const imgElRememberedForEdit = document.createElement('img');
const imgElRememberedForTrash = document.createElement('img');
imgElRememberedForEdit.src = 'client/public/description-edit-3.png';
imgElRememberedForTrash.src = 'client/public/trash-2.png';
imgElRememberedForEdit.className = 'rem-pen';
imgElRememberedForTrash.className = 'rem-trash';

// append to td
tdElRememberedForCheck.appendChild(inputElRememberedForCheck); // check box
tdElRememberedForLabel.appendChild(inputElRemForTextField); // text field with word
tdElRememberedForEdit.appendChild(imgElRememberedForEdit); // pen icon
tdElRememberedForTrash.appendChild(imgElRememberedForTrash); // trash icon
// append to tr
trElRemembered.appendChild(tdElRememberedForCheck);
trElRemembered.appendChild(tdElRememberedForLabel);
trElRemembered.appendChild(tdElRememberedForEdit);
trElRemembered.appendChild(tdElRememberedForTrash);
// append to table
tableElRemembered.appendChild(trElRemembered);
}

// clear container and append new tables to container
document.getElementById('remembered-list-container').innerHTML = '';
document
.getElementById('remembered-list-container')
.appendChild(tableElRemembered);
};

/**
* Render components to UI.
*
* @param {object} [data = {}] - An object which contain two word lists and a sort type.
* @param {string} [listToRender = ''] - A string indicates which table(s) to render.
*/
export const renderList = (data, listToRender = '') => {
// debugger;
switch (listToRender) {
case 'New':
renderListNew(data);
break;
case 'Rem':
renderListRem(data);
break;
default:
renderListNew(data);
renderListRem(data);
}
};
10 changes: 10 additions & 0 deletions client/src/handlers/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Handlers

## inputWord

- Entry point for users adding a word to the list. It is called each time the user clicks the "add word" button.
- It import from:
- data
- logic
- components
- It export to
- listeners
Loading