Merge pull request #362 from h3poteto/iss-355

refs #355 Remove registerd hashtag
This commit is contained in:
AkiraFukushima 2018-06-02 15:47:25 +09:00 committed by GitHub
commit d25fd93a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 1 deletions

View File

@ -21,4 +21,19 @@ export default class Hashtags {
})
})
}
removeTag (tag) {
return new Promise((resolve, reject) => {
this.db.remove(
{
tagName: tag.tagName
},
{ multi: true },
(err, numRemoved) => {
if (err) return reject(err)
resolve(numRemoved)
}
)
})
}
}

View File

@ -637,6 +637,17 @@ ipcMain.on('list-hashtags', (event, _) => {
})
})
ipcMain.on('remove-hashtag', (event, tag) => {
const hashtags = new Hashtags(hashtagsDB)
hashtags.removeTag(tag)
.then(() => {
event.sender.send('response-remove-hashtag')
})
.catch((err) => {
event.sender.send('error-remove-hashtag', err)
})
})
/**
* Auto Updater
*

View File

@ -2,10 +2,15 @@
<div id="list">
<table class="tag-list">
<tbody>
<tr v-for="tag in tags" v-bind:key="tag._id" @click="openTimeline(tag.tagName)">
<tr v-for="tag in tags" v-bind:key="tag._id" @click.stop.prevent="openTimeline(tag.tagName)">
<td>
{{ tag.tagName }}
</td>
<td class="action">
<el-button type="text" @click.stop="deleteTag(tag)">
<icon name="regular/trash-alt"></icon>
</el-button>
</td>
</tr>
</tbody>
</table>
@ -28,6 +33,9 @@ export default {
methods: {
openTimeline (tag) {
this.$router.push({ path: `/${this.$route.params.id}/hashtag/${tag}` })
},
deleteTag (tag) {
this.$store.dispatch('TimelineSpace/Contents/Hashtag/List/removeTag', tag)
}
}
}
@ -51,6 +59,15 @@ export default {
&:first-child {
border-top: 1px solid var(--theme-border-color);
}
.action {
width: 20px;
.el-button /deep/ {
padding: 0;
color: var(--theme-secondary-color);
}
}
}
}
</style>

View File

@ -24,6 +24,20 @@ const List = {
})
ipcRenderer.send('list-hashtags')
})
},
removeTag ({ dispatch }, tag) {
return new Promise((resolve, reject) => {
ipcRenderer.once('response-remove-hashtag', (event, _) => {
ipcRenderer.removeAllListeners('error-remove-hashtag')
dispatch('listTags')
resolve('deleted')
})
ipcRenderer.once('error-remove-hashtag', (event, err) => {
ipcRenderer.removeAllListeners('response-remove-hashtag')
reject(err)
})
ipcRenderer.send('remove-hashtag', tag)
})
}
}
}