Skip to content

Commit

Permalink
Merge pull request #2946 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v4.11.0
  • Loading branch information
robertu7 authored Nov 23, 2022
2 parents daa8d93 + 3254952 commit d0c3186
Show file tree
Hide file tree
Showing 47 changed files with 493 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npm run format -- --list-different && \
npm run lint
npm run lint
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matters-web",
"version": "4.10.0",
"version": "4.11.0",
"description": "codebase of Matters' website",
"sideEffects": false,
"author": "Matters <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions src/common/enums/errorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const ERROR_CODES = {

// Verification Code
CODE_INVALID: 'CODE_INVALID',
CODE_INACTIVE: 'CODE_INACTIVE',
CODE_EXPIRED: 'CODE_EXPIRED',

// GQL
Expand Down
6 changes: 6 additions & 0 deletions src/common/enums/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export enum PAYMENT_CURRENCY {
USDT = 'USDT',
}

export enum QUOTE_CURRENCY {
TWD = 'TWD',
HKD = 'HKD',
USD = 'USD',
}

export enum CHAIN {
POLYGON = 'Polygon',
}
Expand Down
2 changes: 0 additions & 2 deletions src/common/enums/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export const ROUTES: {
{ key: 'FOLLOW', pathname: '/follow' },
{ key: 'AUTHORS', pathname: '/authors' },
{ key: 'SEARCH', pathname: '/search' },
{ key: 'SETTINGS', pathname: '/settings' },

// experient page for recommendation engine testing
{ key: 'RECOMMENDATION', pathname: '/recommendation' },

Expand Down
24 changes: 16 additions & 8 deletions src/common/enums/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export const TEXT = {
circleEdited: '圍爐已更新',
clear: '清空',
close: '關閉',
CODE_EXPIRED: '驗證碼已過期',
CODE_INVALID: '驗證碼不正確',
CODE_EXPIRED: '驗證碼已過期,請重新發送',
CODE_INACTIVE: '驗證碼已失效,請使用最新驗證碼或重新發送',
CODE_INVALID: '驗證碼不正確,請檢查輸入內容或重新發送',
collectedOnly: '只看衍生作品',
COMMENT_NOT_FOUND: '評論不存在',
comment: '評論',
Expand Down Expand Up @@ -102,7 +103,7 @@ export const TEXT = {
editUserProfile: '編輯資料',
email: '電子信箱',
emptySearchResults: '不好意思,什麼都沒搜到',
enterCustomAmount: '輸入自訂金額',
enterCustomAmount: '輸入金額',
enterDisplayName: '請輸入姓名',
enterEmail: '請輸入電子信箱',
enterNewEmail: '請輸入新電子信箱',
Expand Down Expand Up @@ -165,6 +166,7 @@ export const TEXT = {
hintPaymentPointer: '錢包地址以“$”開頭',
hintTerm: '我們的用戶協議和隱私政策發生了更改,請閱讀並同意後繼續使用。',
hintUserName: '4-15 個字元,僅支持英文、數字或下劃線',
hintVerificationCode: '驗證碼有效期 20 分鐘',
history: '足跡',
hkd: '港幣',
hottest: '熱門',
Expand Down Expand Up @@ -450,8 +452,9 @@ export const TEXT = {
circleEdited: '围炉已更新',
clear: '清空',
close: '关闭',
CODE_EXPIRED: '验证码已过期',
CODE_INVALID: '验证码不正确',
CODE_EXPIRED: '验证码已过期,请重新发送',
CODE_INACTIVE: '验证码已失效,请使用最新验证码或重新发送',
CODE_INVALID: '验证码不正确,请检查输入内容或重新发送',
collectedOnly: '只看衍生作品',
COMMENT_NOT_FOUND: '评论不存在',
comment: '评论',
Expand Down Expand Up @@ -492,7 +495,7 @@ export const TEXT = {
editUserProfile: '编辑资料',
email: '邮箱',
emptySearchResults: '不好意思,什么都没搜到',
enterCustomAmount: '输入自订金额',
enterCustomAmount: '输入金额',
enterDisplayName: '请输入姓名',
enterEmail: '请输入邮箱',
enterNewEmail: '请输入新邮箱',
Expand Down Expand Up @@ -555,6 +558,7 @@ export const TEXT = {
hintPaymentPointer: '钱包地址以“$”开头',
hintTerm: '我们的用户协议和隐私政策发生了更改,请阅读并同意后继续使用。',
hintUserName: '4-15 个字符,仅支持英文、数字或下划线',
hintVerificationCode: '验证码有效期 20 分钟',
history: '足迹',
hkd: '港币',
hottest: '热门',
Expand Down Expand Up @@ -840,8 +844,11 @@ export const TEXT = {
circleEdited: 'Circle Edited',
clear: 'Clear',
close: 'Cancel',
CODE_EXPIRED: 'Verification code expired',
CODE_INVALID: 'Invalid verification code',
CODE_EXPIRED: 'Verification code expired, try resend',
CODE_INACTIVE:
'Verification code is no longer valid. Please use the latest code we sent, or try resend',
CODE_INVALID:
'Incorrect verification code. Please check your input, or try resend',
collapseComment: 'Collapse response',
collectedOnly: 'Articles Only',
COMMENT_NOT_FOUND: 'Response not found',
Expand Down Expand Up @@ -961,6 +968,7 @@ export const TEXT = {
hintUserDescription: 'Recommended within 50 words and 200 words maximum.',
hintUserName:
'Must be between 4-15 characters long. Only English alphabets, numbers and underline are accepted.',
hintVerificationCode: 'Code will expire after 20 minutes',
history: 'History',
hkd: 'HKD',
hottest: 'Trending',
Expand Down
16 changes: 9 additions & 7 deletions src/components/ArticleDigest/DropdownActions/RemoveTagButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
TextIcon,
Translate,
useMutation,
useRoute,
} from '~/components'
import updateTagArticlesCount from '~/components/GQL/updates/tagArticlesCount'

Expand Down Expand Up @@ -44,16 +43,19 @@ const fragments = {
`,
}

const RemoveTagButton = ({ article }: { article: RemoveTagButtonArticle }) => {
const { getQuery } = useRoute()
const id = getQuery('tagId')

const RemoveTagButton = ({
article,
tagId,
}: {
article: RemoveTagButtonArticle
tagId: string
}) => {
const [deleteArticlesTags] = useMutation<DeleteArticlesTags>(
DELETE_ARTICLES_TAGS,
{
variables: { id, articles: [article.id] },
variables: { id: tagId, articles: [article.id] },
update: (cache) => {
updateTagArticlesCount({ cache, type: 'decrement', id })
updateTagArticlesCount({ cache, type: 'decrement', id: tagId })
},
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import gql from 'graphql-tag'

import {
IconAdd24,
Menu,
TextIcon,
Translate,
useMutation,
useRoute,
} from '~/components'
import { IconAdd24, Menu, TextIcon, Translate, useMutation } from '~/components'

import { ADD_TOAST } from '~/common/enums'

Expand Down Expand Up @@ -46,11 +39,11 @@ const fragments = {

const SetTagSelectedButton = ({
article,
tagId,
}: {
article: SetTagSelectedButtonArticle
tagId: string
}) => {
const { getQuery } = useRoute()
const tagId = getQuery('tagId')
const [update] = useMutation<SetTagSelected>(SET_TAG_SELECTED, {
variables: { id: tagId, articles: [article.id] },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TextIcon,
Translate,
useMutation,
useRoute,
} from '~/components'

import { ADD_TOAST } from '~/common/enums'
Expand Down Expand Up @@ -52,11 +51,11 @@ const fragments = {

const SetTagUnselectedButton = ({
article,
tagId,
}: {
article: SetTagUnselectedButtonArticle
tagId: string
}) => {
const { getQuery } = useRoute()
const tagId = getQuery('tagId')
const [update] = useMutation<SetTagUnselected>(SET_TAG_UNSELECTED, {
variables: { id: tagId, articles: [article.id] },
update: (cache) => {
Expand All @@ -65,7 +64,11 @@ const SetTagUnselectedButton = ({
const {
TAG_ARTICLES_PUBLIC: query,
} = require('~/components/GQL/queries/tagArticles')
const variables = { id: tagId, selected: true }
const variables = {
id: tagId,
selected: true,
sortBy: 'byCreatedAtDesc',
}
const data = cache.readQuery<TagArticlesPublic>({ query, variables })
const node = _get(data, 'node', {}) as TagArticlesPublic_node_Tag
if (
Expand Down
58 changes: 26 additions & 32 deletions src/components/ArticleDigest/DropdownActions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import _find from 'lodash/find'
import _isEmpty from 'lodash/isEmpty'
import _pickBy from 'lodash/pickBy'
import _some from 'lodash/some'
import { useContext } from 'react'

import {
Expand All @@ -16,7 +14,6 @@ import {
Menu,
ShareDialog,
Translate,
useRoute,
ViewerContext,
} from '~/components'

Expand Down Expand Up @@ -54,8 +51,12 @@ export interface DropdownActionsControls {
// based on type
inCard?: boolean
inUserArticles?: boolean
inTagDetailLatest?: boolean
inTagDetailSelected?: boolean

// tag
tagDetailId?: string
hasSetTagSelected?: boolean
hasSetTagUnselected?: boolean
hasRemoveTag?: boolean

morePublicActions?: React.ReactNode
}
Expand All @@ -73,7 +74,7 @@ interface Controls {
hasSticky: boolean
hasArchive: boolean
hasSetTagSelected: boolean
hasSetTagUnSelected: boolean
hasSetTagUnselected: boolean
hasRemoveTag: boolean
hasEdit: boolean
}
Expand All @@ -90,6 +91,7 @@ type BaseDropdownActionsProps = DropdownActionsProps & Controls & DialogProps

const BaseDropdownActions = ({
article,
tagDetailId,

icon,
size,
Expand All @@ -105,7 +107,7 @@ const BaseDropdownActions = ({
hasSticky,
hasArchive,
hasSetTagSelected,
hasSetTagUnSelected,
hasSetTagUnselected,
hasRemoveTag,
hasEdit,

Expand All @@ -128,7 +130,7 @@ const BaseDropdownActions = ({
hasSticky ||
hasArchive ||
hasSetTagSelected ||
hasSetTagUnSelected ||
hasSetTagUnselected ||
hasRemoveTag

const Content = ({ isInDropdown }: { isInDropdown?: boolean }) => (
Expand All @@ -150,9 +152,15 @@ const BaseDropdownActions = ({
{hasSticky && <StickyButton article={article} />}

{hasArchive && <ArchiveArticle.Button openDialog={openArchiveDialog} />}
{hasSetTagSelected && <SetTagSelectedButton article={article} />}
{hasSetTagUnSelected && <SetTagUnselectedButton article={article} />}
{hasRemoveTag && <RemoveTagButton article={article} />}
{hasSetTagSelected && tagDetailId && (
<SetTagSelectedButton article={article} tagId={tagDetailId} />
)}
{hasSetTagUnselected && tagDetailId && (
<SetTagUnselectedButton article={article} tagId={tagDetailId} />
)}
{hasRemoveTag && tagDetailId && (
<RemoveTagButton article={article} tagId={tagDetailId} />
)}
{hasEdit && <EditButton article={article} />}
</Menu>
)
Expand Down Expand Up @@ -195,29 +203,15 @@ const DropdownActions = (props: DropdownActionsProps) => {

inCard,
inUserArticles,
inTagDetailLatest,
inTagDetailSelected,

hasSetTagSelected,
hasSetTagUnselected,
hasRemoveTag,
} = props
const { getQuery } = useRoute()
const viewer = useContext(ViewerContext)

const isArticleAuthor = viewer.id === article.author.id
const isActive = article.articleState === 'active'
const isInTagDetail = inTagDetailLatest || inTagDetailSelected

// check permission if in tag detail
let canEditTag = false
if (isInTagDetail) {
const tagId = getQuery('tagId')
const tag = _find(article.tags || [], (item) => item.id === tagId)
const isEditor = _some(
tag?.editors || [],
(editor) => editor.id === viewer.id
)
const isCreator = tag?.creator?.id === viewer.id
canEditTag =
isEditor || isCreator || viewer.info.email === '[email protected]'
}

const forbid = () => {
window.dispatchEvent(
Expand Down Expand Up @@ -247,9 +241,9 @@ const DropdownActions = (props: DropdownActionsProps) => {
!viewer.isInactive
),
hasArchive: isArticleAuthor && isActive && !viewer.isArchived,
hasSetTagSelected: !!(inTagDetailLatest && canEditTag),
hasSetTagUnSelected: !!(inTagDetailSelected && canEditTag),
hasRemoveTag: !!(isInTagDetail && canEditTag),
hasSetTagSelected: !!hasSetTagSelected,
hasSetTagUnselected: !!hasSetTagUnselected,
hasRemoveTag: !!hasRemoveTag,
hasEdit: isActive && isArticleAuthor,
}

Expand Down
7 changes: 5 additions & 2 deletions src/components/ArticleDigest/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ type MemoizedArticleDigestFeed = React.MemoExoticComponent<

export const ArticleDigestFeed = React.memo(
BaseArticleDigestFeed,
({ article: prevArticle }, { article }) => {
({ article: prevArticle, ...prevProps }, { article, ...props }) => {
return (
prevArticle.subscribed === article.subscribed &&
prevArticle.articleState === article.articleState &&
prevArticle.sticky === article.sticky &&
prevArticle.author.isFollowee === article.author.isFollowee
prevArticle.author.isFollowee === article.author.isFollowee &&
prevProps.hasSetTagSelected === props.hasSetTagSelected &&
prevProps.hasSetTagUnselected === props.hasSetTagUnselected &&
prevProps.hasRemoveTag === props.hasRemoveTag
)
}
) as MemoizedArticleDigestFeed
Expand Down
3 changes: 3 additions & 0 deletions src/components/Context/Viewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const ViewerFragments = {
articles(input: { first: 0 }) {
totalCount
}
settings {
currency
}
}
`,
},
Expand Down
1 change: 1 addition & 0 deletions src/components/CurrencyFormatter/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}

& .subCurrency {
padding-top: var(--spacing-x-tight);
font-size: var(--font-size-xs);
color: var(--color-grey);
}
Expand Down
Loading

0 comments on commit d0c3186

Please sign in to comment.