forked from FreeTubeApp/FreeTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlights comments. FreeTubeApp#783
- Loading branch information
Showing
13 changed files
with
228 additions
and
12 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
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
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
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,79 @@ | ||
import { DBHighlightedCommentHandlers } from '../../../datastores/handlers/index' | ||
|
||
const state = { | ||
videoHighlightedComments: {} | ||
} | ||
|
||
const getters = { | ||
getHighlightedComments: (state) => (videoId) => ( | ||
videoId in state.videoHighlightedComments | ||
? state.videoHighlightedComments[videoId] | ||
: []) | ||
} | ||
|
||
const actions = { | ||
async addVideoId({ commit }, payload) { | ||
try { | ||
await DBHighlightedCommentHandlers.create(payload) | ||
commit('addVideoId', payload) | ||
} catch (errMessage) { | ||
console.error(errMessage) | ||
} | ||
}, | ||
async addHighlightedComment({ commit }, payload) { | ||
try { | ||
await DBHighlightedCommentHandlers.upsertHighlightedCommentByVideoId(payload.comment, payload.videoId) | ||
commit('upsertHighlightedCommentToVideo', payload.comment, payload.videoId) | ||
} catch (errMessage) { | ||
console.error(errMessage) | ||
} | ||
}, | ||
|
||
async grabAllHighlightedComments({ commit, dispatch, state }) { | ||
try { | ||
const payload = await DBHighlightedCommentHandlers.find() | ||
commit('setAllHighlightedComments', payload) | ||
} catch (errMessage) { | ||
console.error(errMessage) | ||
} | ||
} | ||
} | ||
|
||
const mutations = { | ||
addVideoId(state, videoId) { | ||
if (!(videoId in state.videoHighlightedComments)) { | ||
state.videoHighlightedComments[videoId] = [] | ||
} | ||
}, | ||
upsertHighlightedCommentToVideo(state, comment, videoId) { | ||
if (videoId in state.videoHighlightedComments) { | ||
const comments = state.videoHighlightedComments[videoId] | ||
const existingCommentIndex = comments.findIndex(c => c.text === comment.text) | ||
if (existingCommentIndex === -1) { | ||
state.videoHighlightedComments[videoId].push(comment) | ||
} | ||
} else { | ||
state.videoHighlightedComments[videoId] = [comment] | ||
} | ||
}, | ||
|
||
setAllHighlightedComments(state, payload) { | ||
if (Array.isArray(payload) && payload.length > 0) { | ||
payload.forEach(entry => { | ||
if (!(entry._id in state.videoHighlightedComments)) { | ||
state.videoHighlightedComments[entry._id] = [] | ||
} | ||
state.videoHighlightedComments[entry._id] = ( | ||
state.videoHighlightedComments[entry._id].concat( | ||
entry.comments.map(x => JSON.parse(x)))) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export default { | ||
state, | ||
getters, | ||
actions, | ||
mutations | ||
} |
Oops, something went wrong.