Skip to content

Commit

Permalink
Merge pull request #337 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v1.9.0
  • Loading branch information
robertu7 authored Jul 2, 2019
2 parents 452ad76 + e1f32f9 commit bfd2904
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 115 deletions.
3 changes: 2 additions & 1 deletion common/enums/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const SHARE_TYPE = {
TWITTER: 'twitter',
EMAIL: 'email',
FACEBOOK: 'facebook',
WEIBO: 'weibo'
WEIBO: 'weibo',
DOUBAN: 'douban'
}

export const FEED_TYPE = {
Expand Down
2 changes: 1 addition & 1 deletion components/ArticleDigest/Fingerprint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const Fingerprint = ({ article }: { article: FingerprintArticle }) => {
color="green"
weight="medium"
>
<Translate zh_hans="打开分布式入口" zh_hant="打開分佈式入口" />
<Translate zh_hans="分布式入口" zh_hant="分佈式入口" />
</TextIcon>
<style jsx>{styles}</style>
</button>
Expand Down
35 changes: 13 additions & 22 deletions components/ArticleDigest/ResponseDigest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import gql from 'graphql-tag'
import Link from 'next/link'

import { ArticleDigest } from '~/components'
import IconLive from '~/components/Icon/Live'
import { Translate } from '~/components/Language'
import { UserDigest } from '~/components/UserDigest'

import { TEXT, UrlFragments } from '~/common/enums'
import { toPath } from '~/common/utils'
import { TEXT } from '~/common/enums'

import Actions, { ActionsControls } from '../Actions'
import { Fingerprint } from '../Fingerprint'
Expand Down Expand Up @@ -44,19 +43,13 @@ const ResponseDigest = ({
}: { article: ResponseDigestArticle } & {
hasFingerprint?: boolean
} & ActionsControls) => {
const { author, slug, mediaHash, title, live } = article
const { author, slug, mediaHash, live } = article

if (!author || !author.userName || !slug || !mediaHash) {
return null
}

const path = toPath({
page: 'articleDetail',
userName: author.userName,
slug,
mediaHash,
fragment: live ? UrlFragments.COMMENTS : ''
})
const remadeArticle = { ...article, state: article.articleState }

return (
<section className="container">
Expand All @@ -77,17 +70,15 @@ const ResponseDigest = ({
{!hasFingerprint && live && <IconLive />}
</div>

<div className="content-wrap">
<div className="title">
<Link {...path}>
<a>
<p>{title}</p>
</a>
</Link>
</div>
<div className="description">
<Actions article={article} type="response" {...actionControls} />
</div>
<div className="digest-wrap">
<ArticleDigest.Sidebar
type="collection"
article={remadeArticle}
hasCover
hasAuthor
hasBookmark
extraContainerClass="no-padding"
/>
</div>

<style jsx>{styles}</style>
Expand Down
16 changes: 7 additions & 9 deletions components/ArticleDigest/ResponseDigest/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:root {
--digest-response-cover-size: 10rem;
}

.container {
margin: var(--spacing-default) 0;
}
Expand All @@ -20,13 +24,7 @@
}
}

.content-wrap {
padding-left: var(--spacing-x-loose);

font-size: var(--font-size-sm); /* fallback */
font-size: calc(var(--font-size-sm) + 1px);

& .title {
padding-bottom: 1rem;
}
.digest-wrap {
margin-top: 0.75rem;
margin-left: 2.5rem;
}
10 changes: 9 additions & 1 deletion components/ArticleDigest/SidebarDigest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type SidebarDigestProps = {
article: SidebarDigestArticle
hasCover?: boolean
disabled?: boolean
extraContainerClass?: string
} & ActionsControls

const fragments = {
Expand All @@ -44,6 +45,7 @@ const SidebarDigest = ({
article,
hasCover,
disabled,
extraContainerClass,
...actionControls
}: SidebarDigestProps) => {
const { author, slug, mediaHash, title, live, state } = article
Expand All @@ -60,6 +62,12 @@ const SidebarDigest = ({
mediaHash,
fragment: live ? UrlFragments.COMMENTS : ''
})
const containerClasses = classNames({
container: true,
...(extraContainerClass
? { [extraContainerClass]: extraContainerClass }
: {})
})
const contentClasses = classNames({
content: true,
'no-cover': !cover,
Expand All @@ -69,7 +77,7 @@ const SidebarDigest = ({
})

return (
<section className="container">
<section className={containerClasses}>
<div className={contentClasses}>
<div className="left">
<Link {...path}>
Expand Down
4 changes: 4 additions & 0 deletions components/ArticleDigest/SidebarDigest/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@
pointer-events: none;
}
}

.no-padding {
padding: 0;
}
7 changes: 6 additions & 1 deletion components/CollectionEditor/CollectForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _debounce from 'lodash/debounce'
import _get from 'lodash/get'
import { FC, useContext, useState } from 'react'
import { FC, useContext, useRef, useState } from 'react'
import { QueryResult } from 'react-apollo'

import ArticleList from '~/components/Dropdown/ArticleList'
Expand Down Expand Up @@ -29,6 +29,7 @@ const CollectForm: FC<Props> = ({ onAdd }) => {
const { lang } = useContext(LanguageContext)
const [search, setSearch] = useState('')
const [instance, setInstance] = useState<PopperInstance | null>(null)
const inputNode: React.RefObject<HTMLInputElement> | null = useRef(null)

const hideDropdown = () => {
if (instance) {
Expand Down Expand Up @@ -73,11 +74,15 @@ const CollectForm: FC<Props> = ({ onAdd }) => {
onAdd(article)
setSearch('')
hideDropdown()
if (inputNode && inputNode.current) {
inputNode.current.value = ''
}
}}
/>
}
>
<input
ref={inputNode}
type="search"
placeholder={translate({
zh_hant: '搜尋作品標題…',
Expand Down
7 changes: 4 additions & 3 deletions components/Editor/modules/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ class Mention {
return
}

const tempMentionCharPos = this.mentionCharPos
this.quill.deleteText(
this.mentionCharPos,
this.cursorPos - this.mentionCharPos,
'user'
)
this.quill.insertEmbed(this.mentionCharPos, 'mention', data, 'user')
this.quill.insertText(this.mentionCharPos + 1, ' ', 'user')
this.quill.setSelection(this.mentionCharPos + 2, 'user')
this.quill.insertEmbed(tempMentionCharPos, 'mention', data, 'user')
this.quill.insertText(tempMentionCharPos + 1, ' ', 'user')
this.quill.setSelection(tempMentionCharPos + 2, 'user')
}

hasValidChars(s: string) {
Expand Down
3 changes: 2 additions & 1 deletion components/Head/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ const BaseHead: React.FC<WithRouterProps & HeadProps> = props => {

{/* PWA */}
<link rel="apple-touch-icon" key="apple-touch-icon" href={ICON_192} />
<meta name="theme-color" key="theme-color" content="#ffffff" />
<meta name="application-name" key="application-name" content="Matters" />
<meta name="theme-color" key="theme-color" content="#0d6763" />
<meta
name="apple-mobile-web-app-status-bar-style"
key="apple-mobile-web-app-status-bar-style"
Expand Down
3 changes: 3 additions & 0 deletions static/icons/share-douban.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions views/ArticleDetail/Comments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withRouter, WithRouterProps } from 'next/router'
import { useEffect } from 'react'
import { QueryResult } from 'react-apollo'

import { LoadMore, Translate } from '~/components'
import { LoadMore, Spinner, Translate } from '~/components'
import { CommentDigest } from '~/components/CommentDigest'
import EmptyComment from '~/components/Empty/EmptyComment'
import CommentForm from '~/components/Form/CommentForm'
Expand Down Expand Up @@ -77,7 +77,7 @@ const Main: React.FC<WithRouterProps> = ({ router }) => {
refetch
}: QueryResult & { data: ArticleCommentsType }) => {
if (!data || !data.article) {
return null
return <Spinner />
}

const connectionPath = 'article.comments'
Expand Down
6 changes: 3 additions & 3 deletions views/ArticleDetail/Responses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { withRouter, WithRouterProps } from 'next/router'
import { useContext, useEffect, useState } from 'react'
import { QueryResult } from 'react-apollo'

import { Icon, LoadMore, Translate } from '~/components'
import { Icon, LoadMore, Spinner, Translate } from '~/components'
import { ArticleDigest } from '~/components/ArticleDigest'
import { CommentDigest } from '~/components/CommentDigest'
import EmptyResponse from '~/components/Empty/EmptyResponse'
Expand Down Expand Up @@ -173,7 +173,7 @@ const Main: React.FC<WithRouterProps> = ({ router }) => {
refetch
}: QueryResult & { data: ArticleResponsesType }) => {
if (!data || !data.article) {
return null
return <Spinner />
}

const connectionPath = 'article.responses'
Expand Down Expand Up @@ -284,7 +284,7 @@ const Main: React.FC<WithRouterProps> = ({ router }) => {
{_has(response, 'title') ? (
<ArticleDigest.Response
article={response}
hasDateTime
hasAuthor
hasBookmark
/>
) : (
Expand Down
47 changes: 47 additions & 0 deletions views/ArticleDetail/Toolbar/ShareButton/Douban.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import _get from 'lodash/get'

import { Icon } from '~/components/Icon'
import { TextIcon } from '~/components/TextIcon'

import { ANALYTICS_EVENTS, SHARE_TYPE } from '~/common/enums'
import { analytics, dom, objectToGetParams } from '~/common/utils'
import ICON_SHARE_DOUBAN from '~/static/icons/share-douban.svg?sprite'

const Douban = () => (
<button
type="button"
onClick={() => {
const url = window.location.href
const text = window.document.title
const description = dom
.$('meta[name="description"]')
.getAttribute('content')
const shareUrl =
'http://www.douban.com/share/service' +
objectToGetParams({
href: url,
name: text,
text: description
})
analytics.trackEvent(ANALYTICS_EVENTS.SHARE, {
type: SHARE_TYPE.DOUBAN,
url
})
return window.open(shareUrl)
}}
>
<TextIcon
icon={
<Icon
id={ICON_SHARE_DOUBAN.id}
viewBox={ICON_SHARE_DOUBAN.viewBox}
size="small"
/>
}
spacing="tight"
text="豆瓣"
/>
</button>
)

export default Douban
8 changes: 4 additions & 4 deletions views/ArticleDetail/Toolbar/ShareButton/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { ADD_TOAST } from '~/common/enums/events'
import { dom } from '~/common/utils'
import ICON_SHARE_LINK from '~/static/icons/share-link.svg?sprite'

import Douban from './Douban'
import Email from './Email'
import Facebook from './Facebook'
import LINE from './LINE'
import styles from './styles.css'
import Telegram from './Telegram'
import Twitter from './Twitter'
import WeChat from './WeChat'
import Weibo from './Weibo'
import WhatsApp from './WhatsApp'

Expand Down Expand Up @@ -47,7 +47,7 @@ const ShareModal = () => {
<LINE />
<WhatsApp />
<Telegram />
<WeChat />
<Douban />
</div>

<div className="right">
Expand All @@ -71,9 +71,9 @@ const ShareModal = () => {
spacing="xtight"
textPlacement="left"
>
<span onClick={copy}>
<button onClick={copy} type="button">
<Translate zh_hant="點擊複製" zh_hans="点击复制" />
</span>
</button>
</TextIcon>
<input
id="shareLinkInput"
Expand Down
2 changes: 1 addition & 1 deletion views/ArticleDetail/Toolbar/ShareButton/Weibo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Weibo = () => (
onClick={() => {
const url = window.location.href
const text = window.document.title
const cover = dom.$('meta[property="og:image').getAttribute('content')
const cover = dom.$('meta[property="og:image"]').getAttribute('content')
const shareUrl =
'http://service.weibo.com/share/share.php' +
objectToGetParams({
Expand Down
11 changes: 2 additions & 9 deletions views/Home/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,7 @@ export default () => {
loading,
fetchMore
}: QueryResult & { data: FeedArticleConnection }) => {
if (
loading &&
!(
data &&
data.viewer &&
data.viewer.recommendation &&
data.viewer.recommendation.feed
)
) {
if (loading && !_get(data, 'viewer.recommendation.feed')) {
return <Placeholder.ArticleDigestList />
}

Expand Down Expand Up @@ -171,6 +163,7 @@ export default () => {
)}
</ul>
</InfiniteScroll>

{!match && pageInfo.hasNextPage && (
<LoadMore onClick={loadMore} loading={loading} />
)}
Expand Down
5 changes: 4 additions & 1 deletion views/Misc/About/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
main {
margin-bottom: calc(-1 * var(--spacing-x-loose));
}

h2 {
@mixin font-serif;
font-size: 1.7rem;
Expand Down Expand Up @@ -58,7 +62,6 @@ h2 {
& img {
display: block;
margin: 0 auto;
width: 20rem;
height: 20rem;
}

Expand Down
Loading

0 comments on commit bfd2904

Please sign in to comment.