Browse Source

Implement ajax functionality for lock thread

sbkwgh 8 years ago
parent
commit
865f990ffb
2 changed files with 20 additions and 4 deletions
  1. 4 4
      src/components/routes/Thread.vue
  2. 16 0
      src/store/modules/thread.js

+ 4 - 4
src/components/routes/Thread.vue

@@ -3,10 +3,10 @@
 		<div class='thread_side_bar'>
 			<menu-button
 				:options='[
-					{ event: "lock_thread", value: thread.locked ? "Unlock thread" : "Lock thread" },
+					{ event: "lock_thread", value: $store.state.thread.locked ? "Unlock thread" : "Lock thread" },
 					{ event: "remove_posts", value: "Remove posts" }
 				]'
-				@lock_thread='lockThread'
+				@lock_thread='setThreadLockedState'
 			>
 				<button class='button'>
 					<span class='fa fa-cogs' style='margin-right: 0.25rem;'></span>
@@ -122,8 +122,8 @@
 			editorState () { return this.$store.state.thread.editor.show }
 		},
 		methods: {
-			lockThread () {
-				
+			setThreadLockedState () {
+				this.$store.dispatch('setThreadLockedState', this)
 			},
 			showEditor () {
 				this.$store.commit('setThreadEditorState', true);

+ 16 - 0
src/store/modules/thread.js

@@ -4,6 +4,7 @@ const state = {
 	thread: '',
 	threadId: undefined,
 	posts: [],
+	locked: false,
 	reply: {
 		username: '',
 		id: null
@@ -85,6 +86,7 @@ const actions = {
 				commit('setThread', res.data)
 				dispatch('setTitle', res.data.name)
 				commit('setNextURL', res.data.meta.nextURL)
+				commit('setLocked', res.data.locked)
 				commit('setPreviousURL', res.data.meta.previousURL)
 				commit('setNextURL', res.data.meta.nextURL)
 				commit('setPreviousURL', res.data.meta.previousURL)
@@ -154,6 +156,17 @@ const actions = {
 				commit('setNextURL', baseURL + (post.postNumber-1))
 			}
 		}
+	},
+	setThreadLockedState ({ state, commit }, vue) {
+		vue.axios
+			.put('/api/v1/thread/' + state.threadId, { locked: !state.locked })
+			.then(res => {
+				commit('setLocked', !state.locked)
+			})
+			.catch((e) => {
+				console.log(e)
+				AjaxErrorHandler(vue.$store)
+			})
 	}
 }
 
@@ -225,6 +238,9 @@ const mutations = {
 	},
 	setMentions (state, mentions) {
 		state.mentions = mentions
+	},
+	setLocked (state, value) {
+		state.locked = value
 	}
 }