import config from '../config.js'
import MapStore from './mapStore'

class Comments extends MapStore {
    ajaxParams(key) {
        let api = config.apiurl_comments,
            url = `${api}/thread/${key}`,
            method = 'get'
        return {url, method}
    }
    processResponse(response) {
        return response.json.comments
    }
}

let comments = new Comments('comments')

export default comments

@@ -38,145 +38,755 @@
 ort 
-MapStore from './mapStore'%0A%0Aclass Comments extends MapStore %7B%0A    ajaxParams(key) %7B%0A        let api = config.apiurl_comments,%0A           
+ajax from '../utils/ajax.js'%0Aimport MapStore from './mapStore'%0Aimport auth from './auth'%0A%0Avar api = config.apiurl_comments%0A%0Aclass Comments extends MapStore %7B%0A    constructor(signal) %7B%0A        super(signal)%0A        this.on(riot.VEC('sendComment'), params =%3E this.sendComment(params))%0A        this.on(riot.VEC('sendReply'), params =%3E this.sendReply(params))%0A    %7D%0A    ajaxParams(key) %7B%0A        let url = %60$%7Bapi%7D/thread/$%7Bkey%7D%60,%0A            method = 'get'%0A        return %7Burl, method%7D%0A    %7D%0A    processResponse(response) %7B%0A        return response.json.comments%0A    %7D%0A%0A    updateThread(key, comments) %7B%0A        this._map%5Bkey%5D = comments%0A        this.triggerChanged(key)%0A    %7D%0A%0A    // Add comment to a thread%0A    async sendComment(params) %7B%0A        let
  url
@@ -797,35 +797,43 @@
 $%7Bapi%7D/thread/$%7B
-key
+params.code
 %7D%60,%0A            
@@ -836,77 +836,311 @@
     
-method = 'get'%0A        return %7Burl, method%7D
+data = %7B%0A                'token': await auth.getMicroToken(),%0A                'text': params.text,%0A            %7D%0A        this.updateThread(params.code, this.processResponse(%0A            await ajax(%7Burl, data, method: 'post'%7D)))
 %0A    
-%7D%0A
     
-processResponse
+    // .then(this.processResponse.bind(this))%0A            // .then(
 (res
@@ -1137,32 +1137,35 @@
 .then((response)
+ =%3E
  %7B%0A        retur
@@ -1163,37 +1163,526 @@
     
-return response.json.comments
+    //     this._map%5Bparams.code%5D = response%0A            //     this.triggerChanged(params.code)%0A            // %7D)%0A            // this.trigger(riot.SEC('comments'), this.username)%0A    %7D%0A%0A    // Reply to a comment%0A    async sendReply(params) %7B%0A        let url = api + params.url,%0A            data = %7B%0A                'token': await auth.getMicroToken(),%0A                'text': params.text,%0A            %7D%0A        this.updateThread(params.code, this.processResponse(%0A            await ajax(%7Burl, data, method: 'post'%7D)))
 %0A   

store for comments