From 30ec2c8df868a24ede235d0e6390b95c90063e29 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Thu, 1 Oct 2020 15:37:09 +0800 Subject: [PATCH 1/7] [article] add LINE fab --- pages/article/[id].js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pages/article/[id].js b/pages/article/[id].js index 632c1749..ed051012 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -16,7 +16,10 @@ import { usePushToDataLayer } from 'lib/gtm'; import { format, formatDistanceToNow } from 'lib/dateWithLocale'; import isValid from 'date-fns/isValid'; +import { LINE_URL } from 'constants/urls'; +import AddIcon from '@material-ui/icons/AddCircleOutline'; +import Fab from '@material-ui/core/Fab'; import AppLayout from 'components/AppLayout'; import Ribbon from 'components/Ribbon'; import Hyperlinks from 'components/Hyperlinks'; @@ -127,6 +130,24 @@ const useStyles = makeStyles(theme => ({ textOverflow: 'ellipsis', lineClamp: 5, }, + lineFab: { + position: 'fixed', + zIndex: theme.zIndex.speedDial, + right: 20, + bottom: 20, + background: theme.palette.common.green1, + color: '#fff', + height: 52, + borderRadius: 32, + + '&:hover': { + background: theme.palette.common.green2, + }, + }, + lineFabText: { + lineHeight: '20px', + margin: '0 12px', + }, })); const LOAD_ARTICLE = gql` @@ -430,6 +451,24 @@ function ArticlePage() { onClose={() => setFlashMessage('')} message={flashMessage} /> + {!currentUser && ( + + + + LINE 機器人 +
+ 查謠言詐騙 +
+
+ )} ); } From cacddaa830fe83db4410e98b9f63fad136ef768f Mon Sep 17 00:00:00 2001 From: MrOrz Date: Thu, 1 Oct 2020 15:59:24 +0800 Subject: [PATCH 2/7] [ArticleReply] show more of the reply text --- components/ArticleReply/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/ArticleReply/index.js b/components/ArticleReply/index.js index 2ca8514d..b4b38b93 100644 --- a/components/ArticleReply/index.js +++ b/components/ArticleReply/index.js @@ -209,7 +209,9 @@ const ArticleReply = React.memo( )}
- {nl2br(linkify(reply.text))} + + {nl2br(linkify(reply.text))} +
{renderReference()} From 6605a517b5e13610474cc84fc9d4848370e52cd7 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Thu, 1 Oct 2020 16:12:02 +0800 Subject: [PATCH 3/7] Add trailing text to copied text in clipboard --- pages/article/[id].js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pages/article/[id].js b/pages/article/[id].js index ed051012..4fe851c7 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -267,6 +267,19 @@ function ArticlePage() { setFlashMessage(error.toString()); }, []); + const handleCopy = useCallback( + e => { + const selection = document.getSelection(); + e.clipboardData.setData( + 'text/plain', + selection.toString() + + `\n\n節錄自 Cofacts 真的假的:https://cofacts.org/article/${query.id} | 加 LINE 查謠言:${LINE_URL}` + ); + e.preventDefault(); + }, + [query.id] + ); + const handleFormClose = () => setShowForm(false); const article = data?.GetArticle; @@ -311,7 +324,7 @@ function ArticlePage() { {ellipsis(article.text, { wordCount: 100 })} | {t`Cofacts`} -
+
Date: Thu, 1 Oct 2020 16:17:50 +0800 Subject: [PATCH 4/7] [article] Use window.location.origin + window.location.pathname for more flexible article URL --- pages/article/[id].js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pages/article/[id].js b/pages/article/[id].js index 4fe851c7..70265074 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -267,18 +267,15 @@ function ArticlePage() { setFlashMessage(error.toString()); }, []); - const handleCopy = useCallback( - e => { - const selection = document.getSelection(); - e.clipboardData.setData( - 'text/plain', - selection.toString() + - `\n\n節錄自 Cofacts 真的假的:https://cofacts.org/article/${query.id} | 加 LINE 查謠言:${LINE_URL}` - ); - e.preventDefault(); - }, - [query.id] - ); + const handleCopy = useCallback(e => { + const selection = document.getSelection(); + e.clipboardData.setData( + 'text/plain', + selection.toString() + + `\n\n節錄自 Cofacts 真的假的:${window.location.origin}${window.location.pathname} | 加 LINE 查謠言:${LINE_URL}` + ); + e.preventDefault(); + }, []); const handleFormClose = () => setShowForm(false); From 71199540b5a45b7f2554be9e304672ce6b2ef38b Mon Sep 17 00:00:00 2001 From: MrOrz Date: Thu, 1 Oct 2020 16:22:05 +0800 Subject: [PATCH 5/7] [article] refine string inserted into clipboard --- pages/article/[id].js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/article/[id].js b/pages/article/[id].js index 70265074..0e7959fb 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -269,10 +269,12 @@ function ArticlePage() { const handleCopy = useCallback(e => { const selection = document.getSelection(); + const articleUrl = window.location.origin + window.location.pathname; + e.clipboardData.setData( 'text/plain', selection.toString() + - `\n\n節錄自 Cofacts 真的假的:${window.location.origin}${window.location.pathname} | 加 LINE 查謠言:${LINE_URL}` + `\n📋 節錄自 Cofacts 真的假的:${articleUrl}\n🤔 在 LINE 看到可疑訊息?加「真的假的」好友,查謠言與詐騙 ➡️ ${LINE_URL}` ); e.preventDefault(); }, []); From 3acd6f524dcdd65a98855de5bbef226672700b1f Mon Sep 17 00:00:00 2001 From: MrOrz Date: Thu, 1 Oct 2020 16:26:31 +0800 Subject: [PATCH 6/7] [ArticleReply] insert LINE promotion in text to share --- components/ArticleReply/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/ArticleReply/index.js b/components/ArticleReply/index.js index b4b38b93..26fd2150 100644 --- a/components/ArticleReply/index.js +++ b/components/ArticleReply/index.js @@ -4,6 +4,7 @@ import gql from 'graphql-tag'; import { Box, Divider } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; +import { LINE_URL } from 'constants/urls'; import { nl2br, linkify } from 'lib/text'; import { TYPE_NAME } from 'constants/replyType'; import ExpandableText from 'components/ExpandableText'; @@ -130,13 +131,18 @@ const ArticleReply = React.memo( const classes = useStyles({ replyType }); const renderFooter = () => { + const articleUrl = + typeof window !== 'undefined' + ? // Construct Article URL without search strings (usually gibberish 1st-party trackers) + window.location.origin + window.location.pathname + : ''; const copyText = typeof window !== 'undefined' ? `${TYPE_NAME[reply.type]} \n【${t`Reason`}】${( reply.text || '' - ).trim()}\n↓${t`Details`}↓\n${ - window.location.href - }\n↓${t`Reference`}↓\n${reply.reference}` + ).trim()}\n↓${t`Details`}↓\n${articleUrl}\n↓${t`Reference`}↓\n${ + reply.reference + }\n--\n🤔 在 LINE 看到可疑訊息?加「真的假的」好友,查謠言與詐騙 ➡️ ${LINE_URL}` : ''; return ( From 2309b8d796b2fb16e3acc3b28d66d4053e7375d1 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Sun, 4 Oct 2020 23:01:53 +0800 Subject: [PATCH 7/7] [article] insert text to clipboard only on article & reply so that the text insertion do not mess up with reply authoring --- pages/article/[id].js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/article/[id].js b/pages/article/[id].js index 0e7959fb..e380b1ab 100644 --- a/pages/article/[id].js +++ b/pages/article/[id].js @@ -323,7 +323,7 @@ function ArticlePage() { {ellipsis(article.text, { wordCount: 100 })} | {t`Cofacts`} -
+
- + {nl2br( linkify(text, { props: { @@ -423,6 +423,7 @@ function ArticlePage() { mt={3} id="current-replies" ref={replySectionRef} + onCopy={handleCopy} >

{t`${article.articleReplies.length} replies to the message`}