Skip to content

Commit

Permalink
Merge pull request #4449 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v5.0.2
  • Loading branch information
gary02 authored May 24, 2024
2 parents e331939 + 718cd91 commit 330bb95
Show file tree
Hide file tree
Showing 49 changed files with 678 additions and 597 deletions.
4 changes: 0 additions & 4 deletions lang/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@
"defaultMessage": "Please set your transcation password.",
"description": "PAYMENT_PASSWORD_NOT_SET"
},
"Ayepqz": {
"defaultMessage": "Remove",
"description": "src/components/Tag/index.tsx"
},
"B2As08": {
"defaultMessage": "That's all",
"description": "src/components/Interaction/InfiniteScroll/EndOfResults/index.tsx"
Expand Down
4 changes: 0 additions & 4 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@
"defaultMessage": "Please set your transcation password.",
"description": "PAYMENT_PASSWORD_NOT_SET"
},
"Ayepqz": {
"defaultMessage": "Remove",
"description": "src/components/Tag/index.tsx"
},
"B2As08": {
"defaultMessage": "That's all",
"description": "src/components/Interaction/InfiniteScroll/EndOfResults/index.tsx"
Expand Down
4 changes: 0 additions & 4 deletions lang/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@
"defaultMessage": "请先设定交易密码",
"description": "PAYMENT_PASSWORD_NOT_SET"
},
"Ayepqz": {
"defaultMessage": "移除",
"description": "src/components/Tag/index.tsx"
},
"B2As08": {
"defaultMessage": "没有更多",
"description": "src/components/Interaction/InfiniteScroll/EndOfResults/index.tsx"
Expand Down
4 changes: 0 additions & 4 deletions lang/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@
"defaultMessage": "請先設定交易密碼",
"description": "PAYMENT_PASSWORD_NOT_SET"
},
"Ayepqz": {
"defaultMessage": "移除",
"description": "src/components/Tag/index.tsx"
},
"B2As08": {
"defaultMessage": "沒有更多",
"description": "src/components/Interaction/InfiniteScroll/EndOfResults/index.tsx"
Expand Down
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": "5.0.1",
"version": "5.0.2",
"description": "codebase of Matters' website",
"author": "Matters <[email protected]>",
"engines": {
Expand Down
48 changes: 0 additions & 48 deletions src/components/Context/ArticleAppreciation/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/Context/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './ActiveCommentEditor'
export * from './ArticleAppreciation'
export * from './CommentDrafts'
export * from './DraftDetailState'
export * from './Features'
Expand Down
5 changes: 2 additions & 3 deletions src/components/Dialogs/TagListDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormattedMessage } from 'react-intl'

import { Dialog, Tag, useDialogSwitch } from '~/components'
import { Dialog, ListTag, useDialogSwitch } from '~/components'
import { DigestTagFragment } from '~/gql/graphql'

import styles from './styles.module.css'
Expand Down Expand Up @@ -41,9 +41,8 @@ const BaseDialog = ({ tags, children }: TagListDialogProps) => {
<ul className={styles.tags}>
{tags.map((tag) => (
<li key={tag.id}>
<Tag
<ListTag
tag={tag}
type="list"
hasCount={false}
textIconProps={{ color: 'black', weight: 'medium' }}
/>
Expand Down
6 changes: 2 additions & 4 deletions src/components/Editor/Sidebar/Tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { analytics } from '~/common/utils'
import {
EditorSearchSelectDialog,
Icon,
InlineTag,
// SearchSelectNode,
Tag,
} from '~/components'
import { SearchSelectNode } from '~/components/Forms/SearchSelectForm'
import { DigestTagFragment } from '~/gql/graphql'
Expand Down Expand Up @@ -63,10 +63,8 @@ const SidebarTags = ({
<ul className={styles.list}>
{tags.map((tag) => (
<li key={tag.id}>
<Tag
<InlineTag
tag={tag}
type="inline"
is="span"
onRemoveTag={() => {
editTags(tags.filter((t) => t.content !== tag.content))
analytics.trackEvent('click_button', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormattedMessage } from 'react-intl'

import { Tag } from '~/components'
import { InlineTag } from '~/components'
import { SelectTag } from '~/components/SearchSelect/SearchingArea'
import { EditorRecommendedTagsQuery } from '~/gql/graphql'

Expand Down Expand Up @@ -30,10 +30,8 @@ const RecommendedTags: React.FC<RecommendedTagsProps> = ({
<ul className={styles.tagList}>
{tags.map((tag) => (
<li key={tag.id}>
<Tag
<InlineTag
tag={tag}
type="inline"
is="span"
onClick={!disabled ? () => onAddTag(tag) : undefined}
/>
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tag, Translate } from '~/components'
import { InlineTag, Translate } from '~/components'
import { SelectTag } from '~/components/SearchSelect/SearchingArea'
import { EditorRecommendedTagsQuery } from '~/gql/graphql'

Expand All @@ -23,13 +23,7 @@ const SelectedTags: React.FC<SelectedTagsProps> = ({ tags, onRemoveTag }) => {
<ul className={styles.tagList}>
{tags.map((tag) => (
<li key={tag.id}>
<Tag
tag={tag}
type="inline"
active
is="span"
onRemoveTag={() => onRemoveTag(tag)}
/>
<InlineTag tag={tag} active onRemoveTag={() => onRemoveTag(tag)} />
</li>
))}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Editor/TagCustomStagingArea/gql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag'

import { Tag } from '~/components'
import { ListTag } from '~/components/Tag'

export const EDITOR_RECOMMENDED_TAGS = gql`
query EditorRecommendedTags($userName: String!) {
Expand All @@ -16,5 +16,5 @@ export const EDITOR_RECOMMENDED_TAGS = gql`
}
}
}
${Tag.fragments.tag}
${ListTag.fragments.tag}
`
4 changes: 2 additions & 2 deletions src/components/Notice/NoticeTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gql from 'graphql-tag'

import { toPath } from '~/common/utils'
import { LinkWrapper } from '~/components'
import { Tag } from '~/components/Tag'
import { ListTag } from '~/components/Tag'
import { NoticeTagFragment } from '~/gql/graphql'

import styles from './styles.module.css'
Expand Down Expand Up @@ -34,7 +34,7 @@ NoticeTag.fragments = {
id
...DigestTag
}
${Tag.fragments.tag}
${ListTag.fragments.tag}
`,
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchSelect/SearchSelectNode/Tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames'
import { ReactComponent as IconCircleCheckFill } from '@/public/static/icons/24px/circle-check-fill.svg'
import { ReactComponent as IconCircleEmpty } from '@/public/static/icons/24px/circle-empty.svg'
import { TEST_ID } from '~/common/enums'
import { Card, Icon, Tag } from '~/components'
import { Card, Icon, ListTag } from '~/components'
import { DigestTagFragment } from '~/gql/graphql'

import styles from '../styles.module.css'
Expand Down Expand Up @@ -33,7 +33,7 @@ const SearchSelectTag: React.FC<SearchSelectTagProps> = ({
testId={TEST_ID.SEARCH_RESULTS_ITEM}
>
<section className={nodeClass}>
<Tag tag={tag} type="list" hasCount is="span" />
<ListTag tag={tag} hasCount is="span" />

<span className={styles.iconSelect}>
{inStagingArea && selected && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,13 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
// Used to match links of the format like👇
// https://matters.town/a/{shortHash}
const regex = new RegExp(
`^https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/a/[a-zA-Z0-9]+$`
`^https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/a/[a-zA-Z0-9]+`
)
if (searchType === 'Article' && isUrl(key) && regex.test(key)) {
const urlObj = parseURL(key)
const shortHash = urlObj.pathname.split('/a/')[1].split('?')[0]
setMode('article_url')
lazyArticleUrlQuery({
variables: { shortHash },
})
lazyArticleUrlQuery({ variables: { shortHash } })
} else {
const type = searchType
lazySearch({
Expand Down
6 changes: 4 additions & 2 deletions src/components/SearchSelect/SearchingArea/gql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import gql from 'graphql-tag'

import { ArticleDigestDropdown, Tag, UserDigest } from './internal'
import { ArticleTag } from '~/components/Tag'

import { ArticleDigestDropdown, UserDigest } from './internal'

export const SELECT_SEARCH = gql`
query SelectSearch(
Expand Down Expand Up @@ -48,7 +50,7 @@ export const SELECT_SEARCH = gql`
}
${UserDigest.Mini.fragments.user}
${ArticleDigestDropdown.fragments.article}
${Tag.fragments.tag}
${ArticleTag.fragments.tag}
`

export const LIST_VIEWER_ARTICLES = gql`
Expand Down
6 changes: 2 additions & 4 deletions src/components/SearchSelect/SearchingArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,13 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
// Used to match links of the format like👇
// https://matters.town/a/{shortHash}
const regex = new RegExp(
`^https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/a/[a-zA-Z0-9]+$`
`^https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/a/[a-zA-Z0-9]+`
)
if (searchType === 'Article' && isUrl(key) && regex.test(key)) {
const urlObj = parseURL(key)
const shortHash = urlObj.pathname.split('/a/')[1].split('?')[0]
setMode('article_url')
lazyArticleUrlQuery({
variables: { shortHash },
})
lazyArticleUrlQuery({ variables: { shortHash } })
} else {
const type = searchType === 'Invitee' ? 'User' : searchType
lazySearch({
Expand Down
20 changes: 20 additions & 0 deletions src/components/Tag/ArticleTag/ArticleTag.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import mockRouter from 'next-router-mock'
import { describe, expect, it, vi } from 'vitest'

import { render, screen } from '~/common/utils/test'
import { ArticleTag } from '~/components'
import { MOCK_TAG } from '~/stories/mocks'

describe('<ArticleTag>', () => {
it('should render an ArticleTag', () => {
const handleClick = vi.fn()
render(<ArticleTag tag={MOCK_TAG} onClick={handleClick} />)

const $name = screen.getByText(new RegExp(MOCK_TAG.content, 'i'))
expect($name).toBeInTheDocument()

$name.click()
expect(mockRouter.asPath).toContain(MOCK_TAG.slug)
expect(handleClick).toBeCalledTimes(1)
})
})
65 changes: 65 additions & 0 deletions src/components/Tag/ArticleTag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import classNames from 'classnames'
import gql from 'graphql-tag'
import Link from 'next/link'

import { ReactComponent as IconHashTag } from '@/public/static/icons/24px/hashtag.svg'
import { clampTag, toPath } from '~/common/utils'
import { Icon, TextIcon, TextIconProps } from '~/components'
import { DigestTagFragment } from '~/gql/graphql'

import styles from './styles.module.css'

interface ArticleTagProps {
tag: DigestTagFragment
textIconProps?: TextIconProps
canClamp?: boolean
onClick?: () => void
}

export const ArticleTag = ({
tag,
textIconProps: customTextIconProps,
canClamp = false,
onClick,
}: ArticleTagProps) => {
const tagClasses = classNames({
[styles.article]: 'article',
[styles.clickable]: !!onClick,
})

const tagName = canClamp ? clampTag(tag.content) : tag.content

const path = toPath({
page: 'tagDetail',
tag,
})

const textIconProps: TextIconProps = {
size: 14,
spacing: 0,
weight: 'normal',
icon: <Icon icon={IconHashTag} color="greyDarker" />,
...customTextIconProps,
}

return (
<Link {...path} legacyBehavior>
<a className={tagClasses} onClick={onClick}>
<TextIcon {...textIconProps} size={textIconProps.size} allowUserSelect>
<span className={styles.name}>{tagName}</span>
</TextIcon>
</a>
</Link>
)
}

ArticleTag.fragments = {
tag: gql`
fragment DigestTag on Tag {
id
content
numArticles
numAuthors
}
`,
}
Loading

0 comments on commit 330bb95

Please sign in to comment.