1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Adds functionality to display tags under the open note. (#893)

* Adds functionality to display tags under the open note.

Towards #469

Signed-off-by: Abijeet <abijeetpatro@gmail.com>

* Ensured tags in the dialog box and under the note appear in the same order.

Few formatting tweaks.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>

* Fixes issues raised during code review.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>

* Refactored code to always display tags in ascending order.

This changes the order of the tags in the dialog box and below the tag title.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
Abijeet Patro
2018-11-08 03:46:05 +05:30
committed by Laurent Cozic
parent 28fa83c406
commit 18717bac79
7 changed files with 181 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ const defaultState = {
itemIndex: 0,
itemCount: 0,
},
selectedNoteTags: []
};
const stateUtils = {};
@@ -122,11 +123,14 @@ function handleItemDelete(state, action) {
return newState;
}
function updateOneItem(state, action) {
function updateOneItem(state, action, keyName = '') {
let itemsKey = null;
if (action.type === 'TAG_UPDATE_ONE') itemsKey = 'tags';
if (action.type === 'FOLDER_UPDATE_ONE') itemsKey = 'folders';
if (action.type === 'MASTERKEY_UPDATE_ONE') itemsKey = 'masterKeys';
if (keyName) itemsKey = keyName;
else {
if (action.type === 'TAG_UPDATE_ONE') itemsKey = 'tags';
if (action.type === 'FOLDER_UPDATE_ONE') itemsKey = 'folders';
if (action.type === 'MASTERKEY_UPDATE_ONE') itemsKey = 'masterKeys';
}
let newItems = state[itemsKey].splice(0);
let item = action.item;
@@ -214,6 +218,17 @@ function changeSelectedNotes(state, action) {
throw new Error('Unreachable');
}
function removeItemFromArray(array, property, value) {
for (let i = 0; i !== array.length; ++i) {
let currentItem = array[i];
if (currentItem[property] === value) {
array.splice(i, 1);
break;
}
}
return array;
}
const reducer = (state = defaultState, action) => {
let newState = state;
@@ -359,6 +374,7 @@ const reducer = (state = defaultState, action) => {
case 'TAG_DELETE':
newState = handleItemDelete(state, action);
newState.selectedNoteTags = removeItemFromArray(newState.selectedNoteTags.splice(0), 'id', action.id);
break;
case 'FOLDER_UPDATE_ALL':
@@ -405,6 +421,18 @@ const reducer = (state = defaultState, action) => {
break;
case 'TAG_UPDATE_ONE':
newState = updateOneItem(state, action);
newState = updateOneItem(newState, action, 'selectedNoteTags');
break;
case 'NOTE_TAG_REMOVE':
newState = updateOneItem(state, action, 'tags');
let tagRemoved = action.item;
newState.selectedNoteTags = removeItemFromArray(newState.selectedNoteTags.splice(0), 'id', tagRemoved.id);;
break;
case 'FOLDER_UPDATE_ONE':
case 'MASTERKEY_UPDATE_ONE':
@@ -506,7 +534,7 @@ const reducer = (state = defaultState, action) => {
case 'SEARCH_DELETE':
newState = handleItemDelete(state, action);
break;
break;
case 'SEARCH_SELECT':
@@ -557,6 +585,11 @@ const reducer = (state = defaultState, action) => {
newState.decryptionWorker = decryptionWorker;
break;
case 'SET_NOTE_TAGS':
newState = Object.assign({}, state);
newState.selectedNoteTags = action.items;
break;
}
} catch (error) {
error.message = 'In reducer: ' + error.message + ' Action: ' + JSON.stringify(action);