Skip to content

Commit

Permalink
feat(components): add word-phrase filter for WordPage
Browse files Browse the repository at this point in the history
Closes #103
  • Loading branch information
crimx committed May 21, 2018
1 parent 94ff5d4 commit 29cf96a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/_locales/wordpage/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
"zh_CN": "英文",
"zh_TW": "英文"
},
"filter-word-word": {
"en": "Word",
"zh_CN": "单词",
"zh_TW": "單字"
},
"filter-word-phrase": {
"en": "Phrase",
"zh_CN": "词组和句子",
"zh_TW": "片語和句子"
},
"title_history": {
"en": "Search History",
"zh_CN": "查词记录",
Expand Down
4 changes: 3 additions & 1 deletion src/background/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export async function getWords ({
collection.filter(record => {
const rText = shouldFilter
? (validLangs['en'] && isContainEnglish(record.text)) ||
(validLangs['ch'] && isContainChinese(record.text))
(validLangs['ch'] && isContainChinese(record.text)) ||
(validLangs['word'] && !/\s/.test(record.text)) ||
(validLangs['phra'] && /\s/.test(record.text))
: true

const rSearch = searchText
Expand Down
2 changes: 2 additions & 0 deletions src/components/WordPage/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class WordPageMain extends React.Component<WordPageMainInnerProps, WordPa
filters: [
{ text: t('filter-word-chs'), value: 'ch' },
{ text: t('filter-word-eng'), value: 'en' },
{ text: t('filter-word-word'), value: 'word' },
{ text: t('filter-word-phrase'), value: 'phra' },
],
},
{
Expand Down

0 comments on commit 29cf96a

Please sign in to comment.