Skip to content

Commit

Permalink
Merge pull request #451 from cofacts/block-empty-replies
Browse files Browse the repository at this point in the history
Block empty replies
  • Loading branch information
MrOrz committed Sep 29, 2021
2 parents 019392e + d70a3d9 commit 7ed37f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ By default, the chatbot will be built under `en_US` locale.
During development, changing `LOCALE` in `.env` allows you to spin up dev server under a specific locale.
Please set `LOCALE` to one of `en_US`, `zh_TW` or any other language code that exists under `i18n/` directory.

When previewing translated site on local machine, sometimes the translated text does not appear.
You may need to set `BABEL_DISABLE_CACHE` (example: `BABEL_DISABLE_CACHE=1 npm run dev`) to disable
babel cache for the new translation to appear correctly.

When building using Docker, `LOCALE` can be provided via build args.

## Legal
Expand Down
14 changes: 13 additions & 1 deletion components/NewReplySection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,20 @@ const NewReplySection = withContext(
const { replyType: type, reference, text } = fields;
e.preventDefault(); // prevent reload
if (creatingReply) return;

const trimmedText = text.trim();
if (trimmedText.length === 0) {
alert(t`Please provide reply text.`);
return;
}

createReply({
variables: { type, reference, text, articleId: article.id },
variables: {
type,
reference,
text: trimmedText,
articleId: article.id,
},
});
},
[createReply, fields, article.id, creatingReply]
Expand Down
6 changes: 5 additions & 1 deletion i18n/zh_TW.po
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ msgstr "感謝您的意見。"
msgid "Your reply has been submitted."
msgstr "已經送出回應。"

#: components/NewReplySection/index.js:125
#: components/NewReplySection/index.js:137
#: lib/apollo.js:47
msgid "Please login first."
msgstr "請先登入。"
Expand Down Expand Up @@ -2373,6 +2373,10 @@ msgstr ""
"2016 年起將 chatbot 導入事實查核領域、並提供 API "
"介接教學,在此領域激起了典範轉移,專業查核組織開始推出自己的chatbot,也有第三方查詢機器人前來介接 Cofacts 資料。"

#: components/NewReplySection/index.js:111
msgid "Please provide reply text."
msgstr "請提供回應文字。"

#: pages/index.js:29
msgctxt "site title"
msgid "Cofacts"
Expand Down

0 comments on commit 7ed37f8

Please sign in to comment.