Skip to content

Commit 27bbd77

Browse files
committed
MAIN_DETAIL_COPY, *_BY_SYNTAX, CLIENT_VERSION 追加
1 parent d8ae77d commit 27bbd77

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

browser/main/HomePage/ArticleDetail.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default class ArticleDetail extends React.Component {
162162
}
163163

164164
handleClipboardButtonClick (e) {
165+
activityRecord.emit('MAIN_DETAIL_COPY')
165166
clipboard.writeText(this.props.activeArticle.content)
166167
notify('Saved to Clipboard!', {
167168
body: 'Paste it wherever you want!'
@@ -293,9 +294,9 @@ export default class ArticleDetail extends React.Component {
293294
if (newArticle.title.length === 0) {
294295
newArticle.title = `Created at ${moment(newArticle.createdAt).format('YYYY/MM/DD HH:mm')}`
295296
}
296-
activityRecord.emit('ARTICLE_CREATE')
297+
activityRecord.emit('ARTICLE_CREATE', {mode: newArticle.mode})
297298
} else {
298-
activityRecord.emit('ARTICLE_UPDATE')
299+
activityRecord.emit('ARTICLE_UPDATE', {mode: newArticle.mode})
299300
}
300301

301302
dispatch(updateArticle(newArticle))

lib/activityRecord.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import keygen from 'boost/keygen'
44
import dataStore from 'boost/dataStore'
55
import { request, WEB_URL } from 'boost/api'
66

7+
const electron = require('electron')
8+
const version = electron.remote.app.getVersion()
9+
710
function isSameDate (a, b) {
811
a = moment(a).utcOffset(+540).format('YYYYMMDD')
912
b = moment(b).utcOffset(+540).format('YYYYMMDD')
@@ -81,7 +84,7 @@ export function postRecords (data) {
8184
})
8285
}
8386

84-
export function emit (type, data) {
87+
export function emit (type, data = {}) {
8588
let records = getAllRecords()
8689

8790
let index = _.findIndex(records, record => {
@@ -94,7 +97,6 @@ export function emit (type, data) {
9497
records.push(todayRecord)
9598
}
9699
else todayRecord = records[index]
97-
console.log(type)
98100
switch (type) {
99101
case 'ARTICLE_CREATE':
100102
case 'ARTICLE_UPDATE':
@@ -104,16 +106,34 @@ export function emit (type, data) {
104106
case 'FOLDER_DESTROY':
105107
case 'FINDER_OPEN':
106108
case 'FINDER_COPY':
109+
case 'MAIN_DETAIL_COPY':
107110
todayRecord[type] = todayRecord[type] == null
108111
? 1
109112
: todayRecord[type] + 1
110113

111114
break
112115
}
113116

117+
// Count ARTICLE_CREATE and ARTICLE_UPDATE again by syntax
118+
if ((type === 'ARTICLE_CREATE' || type === 'ARTICLE_UPDATE') && data.mode != null) {
119+
let recordKey = type + '_BY_SYNTAX'
120+
if (todayRecord[recordKey] == null) todayRecord[recordKey] = {}
121+
122+
todayRecord[recordKey][data.mode] = todayRecord[recordKey][data.mode] == null
123+
? 1
124+
: todayRecord[recordKey][data.mode] + 1
125+
}
126+
114127
let storeData = dataStore.getData()
115128
todayRecord.FOLDER_COUNT = _.isArray(storeData.folders) ? storeData.folders.length : 0
116129
todayRecord.ARTICLE_COUNT = _.isArray(storeData.articles) ? storeData.articles.length : 0
130+
todayRecord.CLIENT_VERSION = version
131+
132+
todayRecord.SYNTAX_COUNT = storeData.articles.reduce((sum, article) => {
133+
if (sum[article.mode] == null) sum[article.mode] = 1
134+
else sum[article.mode]++
135+
return sum
136+
}, {})
117137

118138
saveAllRecords(records)
119139
}

0 commit comments

Comments
 (0)