diff --git a/src/_locales/content/messages.json b/src/_locales/content/messages.json index 066c43454..e7a02c92d 100644 --- a/src/_locales/content/messages.json +++ b/src/_locales/content/messages.json @@ -59,13 +59,16 @@ "zh_TW": "關閉字典視窗", "en": "Close the panel" }, - "fromSaladict": { "zh_CN": "来自沙拉查词面板", "zh_TW": "来自沙拉查詞介面", "en": "From Saladict Panel" }, - + "wordEditorDeleteConfirm": { + "zh_CN": "从单词本中移除?", + "zh_TW": "于單字本中移除?", + "en": "Delete from Notebook?" + }, "wordEditorTitle": { "zh_CN": "保存到生词本", "zh_TW": "保存到單字本", diff --git a/src/content/components/WordCards/_style.scss b/src/content/components/WordCards/_style.scss index f4212ecf6..ef7bf5e43 100644 --- a/src/content/components/WordCards/_style.scss +++ b/src/content/components/WordCards/_style.scss @@ -24,6 +24,7 @@ .wordCards-Card { list-style-type: none; + position: relative; display: block; overflow: hidden; margin: 0 0 10px 0; @@ -35,6 +36,18 @@ background: #fcf8e3; } +.wordCards-CardClose { + position: absolute; + top: 5px; + right: 5px; + border: none; + font-size: 20px; + font-weight: bold; + color: #8a6d3b; + background: transparent; + cursor: pointer; +} + .wordCards-CardTitle { margin: 0 0 0.5em; text-align: center; diff --git a/src/content/components/WordCards/index.tsx b/src/content/components/WordCards/index.tsx index 01b4cf78d..f21a15e24 100644 --- a/src/content/components/WordCards/index.tsx +++ b/src/content/components/WordCards/index.tsx @@ -1,10 +1,11 @@ import React from 'react' import { translate } from 'react-i18next' import { TranslationFunction } from 'i18next' -import { Word } from '@/background/database' +import { Word } from '@/_helpers/record-manager' export interface WordCardsProps { words: Word[] + deleteCard: (word: Word) => any } export class WordCards extends React.PureComponent { @@ -12,6 +13,7 @@ export class WordCards extends React.PureComponent +

{word.text}

{word.trans &&
diff --git a/src/content/components/WordEditor/index.tsx b/src/content/components/WordEditor/index.tsx index 54972be69..e2a20ef31 100644 --- a/src/content/components/WordEditor/index.tsx +++ b/src/content/components/WordEditor/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import { translate } from 'react-i18next' import { TranslationFunction } from 'i18next' import { SelectionInfo } from '@/_helpers/selection' -import { Word } from '@/background/database' +import { Word, deleteWords } from '@/_helpers/record-manager' import WordCards from '../WordCards' export interface WordEditorDispatchers { @@ -75,12 +75,17 @@ export class WordEditor extends React.PureComponent date !== word.date) } - if (words.length > 0) { - this.setState({ relatedWords: words }) - } + this.setState({ relatedWords: words }) }) } + deleteCard = (word: Word) => { + if (window.confirm(this.props.t('wordEditorDeleteConfirm'))) { + deleteWords('notebook', [word.date]) + .then(this.getRelatedWords) + } + } + componentDidMount () { this.getRelatedWords() } @@ -170,7 +175,7 @@ export class WordEditor extends React.PureComponent - {relatedWords.length > 0 && } + {relatedWords.length > 0 && }