|
@@ -10,7 +10,9 @@ const mutations = {};
|
|
|
const modules = {
|
|
|
auth: {
|
|
|
namespaced: true,
|
|
|
- state: {},
|
|
|
+ state: {
|
|
|
+ userIdMap: {}
|
|
|
+ },
|
|
|
getters: {},
|
|
|
actions: {
|
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
@@ -100,49 +102,17 @@ const modules = {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
- }
|
|
|
- },
|
|
|
- mutations: {}
|
|
|
- },
|
|
|
- playlists: {
|
|
|
- namespaced: true,
|
|
|
- state: {
|
|
|
- editing: ""
|
|
|
- },
|
|
|
- getters: {},
|
|
|
- actions: {
|
|
|
- editPlaylist: ({ commit }, id) => commit("editPlaylist", id)
|
|
|
- },
|
|
|
- mutations: {
|
|
|
- editPlaylist(state, id) {
|
|
|
- state.editing = id;
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- userIdMap: {
|
|
|
- namespaced: true,
|
|
|
- state: {
|
|
|
- userIdMap: {},
|
|
|
- currentlyGettingUsernameFrom: {}
|
|
|
- },
|
|
|
- getters: {},
|
|
|
- actions: {
|
|
|
- getUsernameFromId: ({ commit }, userId) => {
|
|
|
- /* eslint-disable-next-line no-unused-vars */
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- if (
|
|
|
- typeof state.userIdMap.userIdMap[userId] !== "string" &&
|
|
|
- !state.userIdMap.currentlyGettingUsernameFrom[userId]
|
|
|
- ) {
|
|
|
- commit("gettingUsername", userId);
|
|
|
+ },
|
|
|
+ getUsernameFromId: ({ commit, state }, userId) => {
|
|
|
+ return new Promise(resolve => {
|
|
|
+ if (typeof state.userIdMap[userId] !== "string") {
|
|
|
io.getSocket(socket => {
|
|
|
socket.emit(
|
|
|
"users.getUsernameFromId",
|
|
|
userId,
|
|
|
res => {
|
|
|
- commit("noLongerGettingUsername", userId);
|
|
|
if (res.status === "success") {
|
|
|
- commit("gotUsername", {
|
|
|
+ commit("mapUserId", {
|
|
|
userId,
|
|
|
username: res.data
|
|
|
});
|
|
@@ -151,25 +121,30 @@ const modules = {
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
- } else if (
|
|
|
- !state.userIdMap.currentlyGettingUsernameFrom[userId]
|
|
|
- )
|
|
|
- return resolve(state.userIdMap.userIdMap[userId]);
|
|
|
- else return resolve();
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
mutations: {
|
|
|
- gettingUsername(state, userId) {
|
|
|
- state.currentlyGettingUsernameFrom[userId] = true;
|
|
|
- },
|
|
|
- noLongerGettingUsername(state, userId) {
|
|
|
- state.currentlyGettingUsernameFrom[userId] = true;
|
|
|
- },
|
|
|
- gotUsername(state, data) {
|
|
|
+ mapUserId(state, data) {
|
|
|
state.userIdMap["Z" + data.userId] = data.username;
|
|
|
}
|
|
|
}
|
|
|
+ },
|
|
|
+ playlists: {
|
|
|
+ namespaced: true,
|
|
|
+ state: {
|
|
|
+ editing: ""
|
|
|
+ },
|
|
|
+ getters: {},
|
|
|
+ actions: {
|
|
|
+ editPlaylist: ({ commit }, id) => commit("editPlaylist", id)
|
|
|
+ },
|
|
|
+ mutations: {
|
|
|
+ editPlaylist(state, id) {
|
|
|
+ state.editing = id;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|