Modrinth/store/user.js
Prospector 212bb33142
Projects overhaul for creators (#827)
* Projects page

* Continue work on bulk edit

* editLinks is now bulkEdit

* Bulk Edit Links completed

* Edit URL clear fields.

* Create project button + other bulk buttons.

* Pagination (w/o reactivity.)

* Apply suggestions from code review

Co-authored-by: triphora <emmaffle@modrinth.com>

* Sorting fixed, broken page count though?

* Only make editable projects selectable + remove delete button

* Shorthand

* Start using computed

* Fix pagination

* Add Pagination Switching

* Final Style Changes

* Cleanup

* Action Affects dropdown

* Switch to checkbox swizzle

* Projects dashboard, the most hellish thing I have ever worked on

* Rewrite project dashboard without tables

* why's that there

* Fix mod message icon

* New project settings page

* Remove extra slash

* Bulk project route and improve styling of links UI

* Remove beta label from Monetization

* Relevant page links in project settings

* Don't vertically center header rows

* Improve error messages, add remove project icon button, add saving feedback, begin project checklist, fix license settings

* Remove contextual link from project settings, disable WIP checklist

* Fix bulk edit

* Project checklist, add featured gallery image to project pages, fix random bugs

* Remove old check

* Remove icon border on grid mode and hide project status card when unnecessary

* Fix build

* Make checklist progress smaller and add collapsing

* Remove uneven gap on nav cards

* Improve wrapping of checklist

* Replace project settings header link with status

* Fix bugs + status stuff

* Fix warns + compile error

* Update wording

* Hide environment type nag for project types without it

* Make member dropdown match

Co-authored-by: mineblock11 <93472213+mineblock11@users.noreply.github.com>
Co-authored-by: triphora <emmaffle@modrinth.com>
Co-authored-by: Jai A <jaiagr+gpg@pm.me>
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
2023-01-07 18:37:47 -07:00

133 lines
3.3 KiB
JavaScript

export const state = () => ({
notifications: [],
follows: [],
projects: [],
lastUpdated: 0,
})
export const mutations = {
SET_NOTIFICATIONS(state, notifications) {
state.notifications = notifications
},
SET_FOLLOWS(state, follows) {
state.follows = follows
},
SET_PROJECTS(state, projects) {
state.projects = projects
},
SET_LAST_UPDATED(state, lastUpdated) {
state.lastUpdated = lastUpdated
},
}
export const actions = {
async fetchAll({ commit, state, rootState }, { force = false } = {}) {
if (
rootState.auth.user &&
rootState.auth.user.id &&
(force || Date.now() - state.lastUpdated > 300000)
) {
try {
const [notifications, follows, projects] = (
await Promise.all([
this.$axios.get(
`user/${rootState.auth.user.id}/notifications`,
rootState.auth.headers
),
this.$axios.get(
`user/${rootState.auth.user.id}/follows`,
rootState.auth.headers
),
this.$axios.get(
`user/${rootState.auth.user.id}/projects`,
rootState.auth.headers
),
])
).map((it) => it.data)
commit('SET_NOTIFICATIONS', notifications)
commit('SET_FOLLOWS', follows)
commit('SET_PROJECTS', projects)
commit('SET_LAST_UPDATED', Date.now())
} catch (err) {
console.error(err)
}
}
},
async fetchNotifications({ commit, rootState }) {
if (rootState.auth.user && rootState.auth.user.id) {
try {
const notifications = (
await this.$axios.get(
`user/${rootState.auth.user.id}/notifications`,
rootState.auth.headers
)
).data
commit('SET_NOTIFICATIONS', notifications)
} catch (err) {
console.error(err)
}
}
},
async fetchFollows({ commit, rootState }) {
if (rootState.auth.user && rootState.auth.user.id) {
try {
const follows = (
await this.$axios.get(
`user/${rootState.auth.user.id}/follows`,
rootState.auth.headers
)
).data
commit('SET_FOLLOWS', follows)
} catch (err) {
console.error(err)
}
}
},
async fetchProjects({ commit, rootState }) {
if (rootState.auth.user && rootState.auth.user.id) {
try {
const projects = (
await this.$axios.get(
`user/${rootState.auth.user.id}/projects`,
rootState.auth.headers
)
).data
commit('SET_PROJECTS', projects)
} catch (err) {
console.error(err)
}
}
},
followProject({ commit, state, rootState }, project) {
commit('SET_FOLLOWS', state.follows.concat(project))
setTimeout(() => {
this.$axios.post(
`project/${project.id}/follow`,
{},
rootState.auth.headers
)
})
},
unfollowProject({ commit, state, rootState }, project) {
commit(
'SET_FOLLOWS',
state.follows.filter((x) => x.id !== project.id)
)
setTimeout(() => {
this.$axios.delete(`project/${project.id}/follow`, rootState.auth.headers)
})
},
deleteNotification({ commit, state, rootState }, id) {
commit(
'SET_NOTIFICATIONS',
state.notifications.filter((x) => x.id !== id)
)
},
}