mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-30 17:15:16 +01:00
refs #355 Save hashtag in local db
This commit is contained in:
parent
7115ad45fc
commit
2659991091
24
src/main/hashtags.js
Normal file
24
src/main/hashtags.js
Normal file
@ -0,0 +1,24 @@
|
||||
export default class Hashtags {
|
||||
constructor (db) {
|
||||
this.db = db
|
||||
this.db.ensureIndex({fieldName: 'tagName', unique: true}, (_) => {})
|
||||
}
|
||||
|
||||
listTags () {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.db.find({}, (err, docs) => {
|
||||
if (err) return reject(err)
|
||||
resolve(docs)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
insertTag (tag) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.db.insert({tagName: tag}, (err, doc) => {
|
||||
if (err) return reject(err)
|
||||
resolve(doc)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
@ -8,12 +8,13 @@ import windowStateKeeper from 'electron-window-state'
|
||||
import simplayer from 'simplayer'
|
||||
import path from 'path'
|
||||
import openAboutWindow from 'about-window'
|
||||
import ContextMenu from 'electron-context-menu'
|
||||
|
||||
import Authentication from './auth'
|
||||
import Account from './account'
|
||||
import Streaming from './streaming'
|
||||
import Preferences from './preferences'
|
||||
import ContextMenu from 'electron-context-menu'
|
||||
import Hashtags from './hashtags'
|
||||
|
||||
/**
|
||||
* Context menu
|
||||
@ -48,6 +49,14 @@ let accountDB = new Datastore({
|
||||
filename: accountDBPath,
|
||||
autoload: true
|
||||
})
|
||||
const hashtagsDBPath = process.env.NODE_ENV === 'production'
|
||||
? userData + '/db/hashtags.db'
|
||||
: 'hashtags.db'
|
||||
let hashtagsDB = new Datastore({
|
||||
filename: hashtagsDBPath,
|
||||
autoload: true
|
||||
})
|
||||
|
||||
const preferencesDBPath = process.env.NODE_ENV === 'production'
|
||||
? userData + './db/preferences.json'
|
||||
: 'preferences.json'
|
||||
@ -608,6 +617,15 @@ ipcMain.on('save-preferences', (event, data) => {
|
||||
})
|
||||
})
|
||||
|
||||
// hashtag
|
||||
ipcMain.on('save-hashtag', (event, tag) => {
|
||||
const hashtags = new Hashtags(hashtagsDB)
|
||||
hashtags.insertTag(tag)
|
||||
.catch((err) => {
|
||||
log.error(err)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Auto Updater
|
||||
*
|
||||
|
@ -12,7 +12,7 @@
|
||||
<input v-model="tag" placeholder="Tag name" class="search-keyword" v-shortkey="['enter']" @shortkey="search" autofocus></input>
|
||||
</div>
|
||||
<div class="form-item" v-show="tagPage()">
|
||||
<el-button type="text">
|
||||
<el-button type="text" @click="save">
|
||||
<icon name="thumbtack"></icon>
|
||||
</el-button>
|
||||
</div>
|
||||
@ -43,6 +43,9 @@ export default {
|
||||
},
|
||||
back () {
|
||||
this.$router.push({ path: `/${this.id()}/hashtag` })
|
||||
},
|
||||
save () {
|
||||
this.$store.dispatch('TimelineSpace/Contents/Hashtag/saveTag', this.tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ipcRenderer } from 'electron'
|
||||
import List from './Hashtag/List'
|
||||
import Tag from './Hashtag/Tag'
|
||||
|
||||
@ -6,6 +7,11 @@ const Hashtag = {
|
||||
modules: {
|
||||
List,
|
||||
Tag
|
||||
},
|
||||
actions: {
|
||||
saveTag (_, tag) {
|
||||
ipcRenderer.send('save-hashtag', tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user