Skip to content

Commit

Permalink
Merge pull request #4274 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v4.30.2
  • Loading branch information
robertu7 committed Apr 15, 2024
2 parents c2bde39 + 15153a0 commit 3278912
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NEXT_PUBLIC_FACEBOOK_CLIENT_ID=1072677713882819
NEXT_PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY=0x4AAAAAAAKiedvR5qiLUhIs
NEXT_PUBLIC_NOMAD_MATTERS_CAMPAIGN_LINK=/@rsdyobw/22048-launching-the-nomad-matters-initiative
NEXT_PUBLIC_BILLBOARD_ADDRESS=0x6a72820E1CCCba1B1FE02E37881cEa3F9Aa6375C
NEXT_PUBLIC_BILLBOARD_TOKEN_ID=1
NEXT_PUBLIC_BILLBOARD_TOKEN_ID=6
NEXT_PUBLIC_BILLBOARD_IMAGE_URL=matters-billboard-ad-dev.s3.ap-southeast-1.amazonaws.com/
DEBUG=false
PLAYWRIGHT_RUNTIME_ENV=ci
Expand Down
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ NEXT_PUBLIC_LOGBOOKS_URL=https://logbooks-vercel.matters.town
NEXT_PUBLIC_ALCHEMY_KEY=1dMo8xjAFo8M6Y4sQ45WTD3Zie2-MA4C
NEXT_PUBLIC_NOMAD_MATTERS_CAMPAIGN_LINK=/@rsdyobw/22048-launching-the-nomad-matters-initiative
NEXT_PUBLIC_BILLBOARD_ADDRESS=0x6a72820E1CCCba1B1FE02E37881cEa3F9Aa6375C
NEXT_PUBLIC_BILLBOARD_TOKEN_ID=1
NEXT_PUBLIC_BILLBOARD_TOKEN_ID=6
NEXT_PUBLIC_BILLBOARD_IMAGE_URL=matters-billboard-ad-dev.s3.ap-southeast-1.amazonaws.com/
DEBUG=false
PLAYWRIGHT_RUNTIME_ENV=local
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": "4.30.1",
"version": "4.30.2",
"description": "codebase of Matters' website",
"author": "Matters <hi@matters.town>",
"engines": {
Expand Down
6 changes: 0 additions & 6 deletions src/components/Book/Collection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useEffect } from 'react'

import BOOK_COVER from '@/public/static/images/book-cover.png'
import { TEST_ID } from '~/common/enums'
import { countStrWidth } from '~/common/utils'
import {
IconCamera24,
ResponsiveImage,
Expand Down Expand Up @@ -35,13 +34,8 @@ const BookCollection: React.FC<BookCollectionProps> = ({
getColor()
}, [cover])

const titleWidth = countStrWidth(title)
const hasNonCJK = title.length * 2 !== titleWidth

const jacketClasses = classNames({
[styles.jacket]: true,
[styles.titleLg]: hasNonCJK ? titleWidth <= 10 : titleWidth <= 12,
[styles.titleMd]: titleWidth > 12 && titleWidth <= 28 && !hasNonCJK,
})

return (
Expand Down
29 changes: 7 additions & 22 deletions src/components/Book/Collection/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
width: 7.5rem;
height: 10rem;
overflow: hidden;
text-align: left;
white-space: initial;
border-radius: 0.5rem;
box-shadow:
0 2px 2px 0 rgb(255 255 255 / 50%) inset,
Expand Down Expand Up @@ -47,7 +49,7 @@
}

& .jacket {
@mixin flex-start-center;
@mixin flex-start-start;

position: absolute;
right: 0;
Expand All @@ -60,31 +62,14 @@
& .title {
@mixin line-clamp;

padding-top: var(--spacing-x-tight);
padding-right: var(--spacing-x-tight);
padding-left: var(--spacing-x-base);
font-size: var(--font-size-xs);
font-size: var(--font-size-sm);
font-weight: var(--font-weight-normal);
line-height: 1.0625rem;
line-height: 1.25rem;
color: var(--color-white);
-webkit-line-clamp: 3;
}

&.titleMd {
& .title {
font-size: var(--font-size-sm-s);
line-height: 1.25rem;
}
}

&.titleLg {
@mixin flex-start-start;

padding-top: var(--spacing-x-tight);

& .title {
font-size: var(--font-size-md);
line-height: 1.5rem;
}
-webkit-line-clamp: 2;
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/components/FileUploader/CoverUploader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ export const CoverUploader = ({
{isCollection && (
<section className={styles.collection}>
<section className={styles.collectionContent}>
{
<Book.Collection
title={bookTitle || ''}
cover={cover}
hasMask
loading={loading}
/>
}
<Book.Collection
title={bookTitle || ''}
cover={cover}
hasMask
loading={loading}
/>
</section>
</section>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
return
}
}

// searching
useEffect(() => {
if (debouncedSearchKey) {
Expand Down Expand Up @@ -306,8 +307,8 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
node={node}
onClick={addNodeToStaging}
selected={
stagingNodes.findIndex((SN) => {
return SN.node.id === node.id
stagingNodes.findIndex((sn) => {
return sn.node.id === node.id
}) !== -1
}
inSearchingArea
Expand Down Expand Up @@ -339,6 +340,7 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
</InfiniteScroll>
)}

{/* URL Search */}
{isArticleUrlMode && !searching && !hasArticle && <EmptySearch />}

{isArticleUrlMode &&
Expand All @@ -350,8 +352,8 @@ const EditorSearchingArea: React.FC<SearchingAreaProps> = ({
onClick={addNodeToStaging}
selected={
stagingNodes.findIndex(
(SN) =>
SN.node.id ===
(sn) =>
sn.node.id ===
(articleUrlData.node?.__typename === 'Article' &&
articleUrlData.node.id)
) !== -1
Expand Down
1 change: 1 addition & 0 deletions src/components/SearchSelect/SearchingArea/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SELECT_SEARCH = gql`
first: $first
exclude: $exclude
includeAuthorTags: $includeAuthorTags
quicksearch: true
}
) {
pageInfo {
Expand Down
84 changes: 69 additions & 15 deletions src/components/SearchSelect/SearchingArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { useDebouncedCallback } from 'use-debounce'
import { INPUT_DEBOUNCE } from '~/common/enums'
import {
analytics,
isUrl,
isValidEmail,
mergeConnections,
normalizeTag, // stripTagAllPunct, // stripPunctPrefixSuffix,
normalizeTag,
parseURL,
toGlobalId, // stripTagAllPunct, // stripPunctPrefixSuffix,
} from '~/common/utils'
import {
EmptySearch,
Expand All @@ -19,6 +22,7 @@ import {
} from '~/components'
import { toUserDigestMiniPlaceholder } from '~/components/UserDigest/Mini'
import {
ArticleUrlQueryQuery,
ListViewerArticlesQuery,
SearchExclude,
SearchFilter,
Expand All @@ -28,7 +32,7 @@ import {
import SearchSelectNode from '../SearchSelectNode'
import styles from '../styles.module.css'
import CreateTag from './CreateTag'
import { LIST_VIEWER_ARTICLES, SELECT_SEARCH } from './gql'
import { ARTICLE_URL_QUERY, LIST_VIEWER_ARTICLES, SELECT_SEARCH } from './gql'
import InviteEmail from './InviteEmail'
import SearchInput, {
SearchInputProps,
Expand Down Expand Up @@ -69,7 +73,7 @@ type SearchingAreaProps = {
inviteEmail?: boolean
} & Pick<SearchInputProps, 'autoFocus'>

type Mode = 'search' | 'list'
type Mode = 'search' | 'list' | 'article_url'

const SearchingArea: React.FC<SearchingAreaProps> = ({
searchType,
Expand All @@ -94,6 +98,7 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
const [mode, setMode] = useState<Mode>(hasListMode ? 'list' : 'search')
const isSearchMode = mode === 'search'
const isListMode = mode === 'list'
const isArticleUrlMode = mode === 'article_url'

const [searching, setSearching] = useState(false)
const [searchingNodes, setSearchingNodes] = useState<SelectNode[]>([])
Expand All @@ -117,6 +122,14 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
loadList,
{ data: listData, loading: listLoading, fetchMore: fetchMoreList },
] = useLazyQuery<ListViewerArticlesQuery>(LIST_VIEWER_ARTICLES)
const [
lazyArticleUrlQuery,
{ data: articleUrlData, loading: articleUrlLoding },
] = usePublicLazyQuery<ArticleUrlQueryQuery>(
ARTICLE_URL_QUERY,
{},
{ publicQuery: !viewer.isAuthed }
)

// pagination
const { edges: searchEdges, pageInfo: searchPageInfo } = data?.search || {}
Expand Down Expand Up @@ -160,16 +173,34 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
.filter((node) => node.articleState === 'active') || []
const listNodeIds = listNode.map((n) => n.id).join(',')
const search = (key: string) => {
const type = searchType === 'Invitee' ? 'User' : searchType
lazySearch({
variables: {
key,
type,
filter: searchFilter,
exclude: searchExclude,
first: 10,
},
})
// Used to match links of the format like👇
// https://matters.town/@az/12-来自matters的第一封信-致好朋友-zdpuAnuMKxNv6SUj7kTRzgrWRdp9q4aMMKHJ6TGtn8tp4FwX2
const regex = new RegExp(
`^https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/@\\w+/\\d+.*$`
)
if (searchType === 'Article' && isUrl(key) && regex.test(key)) {
const urlObj = parseURL(key)
const paths = urlObj.pathname.split('-')
const subPaths = paths[0].split('/')
const articleId = subPaths?.[subPaths.length - 1]
setMode('article_url')
lazyArticleUrlQuery({
variables: {
id: toGlobalId({ type: 'Article', id: articleId }),
},
})
} else {
const type = searchType === 'Invitee' ? 'User' : searchType
lazySearch({
variables: {
key,
type,
filter: searchFilter,
exclude: searchExclude,
first: 10,
},
})
}
}

// handling changes from search input
Expand All @@ -182,11 +213,14 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
toSearchingArea()
}

if (hasListMode) {
setMode(value ? 'search' : 'list')
setMode('search')

if (hasListMode && !value) {
setMode('list')
return
}
}

const onSearchInputFocus = () => {
if (hasListMode) {
if (!searchKey) {
Expand All @@ -196,6 +230,7 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
return
}
}

const onSearchInputBlur = () => {
if (isSearchMode) {
return
Expand Down Expand Up @@ -239,8 +274,14 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
setSearchingNodes(listNode)
}, [listLoading, listNodeIds])

// article url
useEffect(() => {
setSearching(articleUrlLoding)
}, [articleUrlLoding])

const hasNodes = searchNodes.length > 0
const haslistNode = listNode.length > 0
const hasArticle = !!articleUrlData?.node
const canCreateTag =
isTag &&
searchKey &&
Expand Down Expand Up @@ -335,6 +376,19 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
</ul>
</InfiniteScroll>
)}

{/* URL Search */}
{isArticleUrlMode && !searching && !hasArticle && <EmptySearch />}

{isArticleUrlMode &&
!searching &&
hasArticle &&
articleUrlData?.node?.__typename === 'Article' && (
<SearchSelectNode
node={articleUrlData.node}
onClick={addNodeToStaging}
/>
)}
</section>
)}
</section>
Expand Down

0 comments on commit 3278912

Please sign in to comment.