Skip to content

Commit

Permalink
Merge 8d12f13 into 0093380
Browse files Browse the repository at this point in the history
  • Loading branch information
tx0c committed Apr 22, 2022
2 parents 0093380 + 8d12f13 commit 418585a
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 22 deletions.
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"sideEffects": false,
"author": "Matters <hi@matters.news>",
"engines": {
"node": ">=16.14"
"node": ">=14.x"
},
"license": "Apache-2.0",
"scripts": {
Expand Down Expand Up @@ -83,6 +83,7 @@
"graphql": "^14.7.0",
"graphql-tag": "^2.11.0",
"isomorphic-unfetch": "^3.1.0",
"js-base64": "^3.7.2",
"jump.js": "^1.0.2",
"lodash": "^4.17.21",
"next": "^12.1.0",
Expand Down
18 changes: 18 additions & 0 deletions src/common/utils/globalId.ts
@@ -0,0 +1,18 @@
import { Base64 } from 'js-base64'

// import { NODE_TYPES } from 'common/enums'
// import { UserInputError } from 'common/errors'

export const toGlobalId = ({
type,
id,
}: {
type: string
id: number | string
}) => Base64.encodeURI(`${type}:${id}`)

export const fromGlobalId = (globalId: string) => {
const [type, id] = Base64.decode(globalId).split(':')

return { type, id }
}
1 change: 1 addition & 0 deletions src/common/utils/index.ts
Expand Up @@ -25,3 +25,4 @@ export * from './firebase'
export * from './cookie'
export * from './storage'
export * from './wallet'
export * from './globalId'
14 changes: 13 additions & 1 deletion src/common/utils/route.ts
Expand Up @@ -4,9 +4,11 @@ import queryString from 'query-string'

import { PATHS, ROUTES } from '~/common/enums'

import { fromGlobalId } from './globalId'
import { parseURL } from './url'

interface ArticleArgs {
id?: string
slug: string
mediaHash: string | null
author: {
Expand Down Expand Up @@ -72,11 +74,21 @@ export const toPath = (args: ToPathArgs): { href: string } => {
switch (args.page) {
case 'articleDetail': {
const {
id,
slug,
mediaHash,
author: { userName },
} = args.article
const asUrl = `/@${userName}/${slug}-${mediaHash}`

let asUrl = `/@${userName}/${slug}-${mediaHash}`
try {
if (id) {
const { id: articleId } = fromGlobalId(id as string)
asUrl = `/@${userName}/${articleId}-${slug}-${mediaHash}`
}
} catch (err) {
console.error(`unable to parse global id:`, { id }, err)
}

return {
href: args.fragment ? `${asUrl}#${args.fragment}` : asUrl,
Expand Down
16 changes: 7 additions & 9 deletions src/components/SearchSelect/SearchingArea/index.tsx
Expand Up @@ -93,14 +93,11 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({

const [searchKey, setSearchKey] = useState('')
const [debouncedSearchKey, setdebouncedSearchKey] = useState('')
const debouncedSetSearchKey = useDebouncedCallback(
(sk0) => {
const sk = isTag ? stripPunctPrefixSuffix(sk0) : sk0
setdebouncedSearchKey(sk)
setSearchKey(sk)
},
INPUT_DEBOUNCE
)
const debouncedSetSearchKey = useDebouncedCallback((sk0) => {
const sk = isTag ? stripPunctPrefixSuffix(sk0) : sk0
setdebouncedSearchKey(sk)
setSearchKey(sk)
}, INPUT_DEBOUNCE)

// Data Fetching
const [lazySearch, { data, loading, fetchMore }] =
Expand Down Expand Up @@ -247,7 +244,8 @@ const SearchingArea: React.FC<SearchingAreaProps> = ({
searchKey &&
createTag &&
!searchNodes.some(
(node) => node.__typename === 'TagSearchResult' && node.content === searchKey
(node) =>
node.__typename === 'TagSearchResult' && node.content === searchKey
)
const canInviteEmail =
isUser &&
Expand Down
68 changes: 68 additions & 0 deletions src/views/ArticleDetail/gql.ts
Expand Up @@ -77,6 +77,74 @@ export const ARTICLE_DETAIL_PUBLIC = gql`
${CircleWall.fragments.circle.private}
`

export const ARTICLE_DETAIL_PUBLIC_BY_NODE_ID = gql`
query ArticleDetailPublicByNodeId(
$id: ID!
$includeCanSuperLike: Boolean = true
) {
article: node(input: { id: $id }) {
... on Article {
id
title
slug
mediaHash
state
cover
summary
summaryCustomized
createdAt
revisedAt
language
author {
id
paymentPointer
...UserDigestRichUserPublic
...UserDigestRichUserPrivate
}
collection(input: { first: 0 }) @connection(key: "articleCollection") {
totalCount
}
access {
type
circle {
id
...CircleWallCirclePublic
...CircleWallCirclePrivate
}
}
license
drafts {
id
mediaHash
publishState
}
...MetaInfoArticle
...ContentArticle
### ...TagListArticle
...RelatedArticles
...StateArticle
...ToolbarArticlePublic
...ToolbarArticlePrivate
...SupportWidgetArticlePublic
...SupportWidgetArticlePrivate
}
}
}
${MetaInfo.fragments.article}
${Content.fragments.article}
### $ {TagList.fragments.article}
${RelatedArticles.fragments.article}
${State.fragments.article}
${UserDigest.Rich.fragments.user.public}
${UserDigest.Rich.fragments.user.private}
${Toolbar.fragments.article.public}
${Toolbar.fragments.article.private}
${SupportWidget.fragments.article.public}
${SupportWidget.fragments.article.private}
${CircleWall.fragments.circle.public}
${CircleWall.fragments.circle.private}
`

export const ARTICLE_DETAIL_PRIVATE = gql`
query ArticleDetailPrivate(
$mediaHash: String!
Expand Down

0 comments on commit 418585a

Please sign in to comment.