Created a uniform menu for notes that works on mobile

Added list sorting
Added shared notes
Fixed some little bugs here and there
This commit is contained in:
Max G committed 2020-02-10 17:44:43 +00:00
1 parent 133a86e09e
commit 86f7f61933
23 files changed
+1393 -328

No files matched your search

+32 -21
View File
@@ -10,7 +10,7 @@ Tag.userTags = (userId) => {
JOIN note_tag ON tag.id = note_tag.tag_id
WHERE note_tag.user_id = ?
GROUP BY tag.id
ORDER BY usages DESC
ORDER BY id DESC
`, [userId])
.then( (rows, fields) => {
resolve(rows[0])
@@ -98,39 +98,50 @@ Tag.add = (tagText) => {
})
}
//
// Get all tags AND tags associated to note
//
Tag.get = (userId, noteId) => {
return new Promise((resolve, reject) => {
//Update last opened date of note
const now = Math.round((+new Date)/1000)
db.promise()
.query('UPDATE note SET opened = ? WHERE id = ? AND user_id = ? LIMIT 1', [now, noteId, userId])
.then((rows, fields) => {})
Tag.userTags(userId).then(userTags => {
db.promise()
.query(`SELECT tag_id as tagId, id as entryId
FROM note_tag
WHERE user_id = ? AND note_id = ?;`, [userId, noteId])
.then((rows, fields) => {
db.promise()
.query(`SELECT note_tag.id, tag.text FROM note_tag
JOIN tag ON (tag.id = note_tag.tag_id)
WHERE user_id = ? AND note_id = ?;`, [userId, noteId])
.then((rows, fields) => {
resolve(rows[0]) //Return all tags found by query
//pull IDs out of returned results
// let ids = rows[0].map( item => {})
resolve({'noteTagIds':rows[0], 'allTags':userTags }) //Return all tags found by query
})
.catch(console.log)
})
.catch(console.log)
})
}
//
// Get all tags for a note and concatinate into a string 'all, tags, like, this'
//
Tag.string = (userId, noteId) => {
return new Promise((resolve, reject) => {
Tag.get(userId, noteId).then(tagArray => {
db.promise()
.query(`SELECT GROUP_CONCAT(DISTINCT tag.text SEPARATOR ', ') as text
FROM note_tag
JOIN tag ON note_tag.tag_id = tag.id
WHERE user_id = ? AND note_id = ?;`, [userId, noteId])
.then((rows, fields) => {
let tagString = ''
tagArray.forEach( (tag, i) => {
if(i > 0){ tagString += ',' }
tagString += tag.text
})
//Output comma delimited list of tag strings
resolve(tagString)
let finalText = rows[0][0]['text']
if(finalText == null){
finalText = ''
}
return resolve(finalText) //Return all tags found by query
})
.catch(console.log)
})
}