Skip to content

Commit

Permalink
Merge pull request #352 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v1.10.0
  • Loading branch information
robertu7 authored Jul 29, 2019
2 parents bfd2904 + 6290f8f commit bff440b
Show file tree
Hide file tree
Showing 45 changed files with 2,363 additions and 16,719 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ steps:
environment:
CODECOV_TOKEN: f109cbf6-b6c7-4a08-ad03-981bc4cd1fe8
MATTERS_ENV: test
API_URL: http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/
API_URL: http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/graphql
commands:
- npm install codecov -g
- npm run test
Expand Down
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ENV=development
SITE_DOMAIN=http://localhost:3000
ASSET_DOMAIN=https://assets-develop.matters.news
API_URL=http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/
API_URL=http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/graphql
WS_URL=ws://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/graphql
OAUTH_URL=http://matters-server-develop.ap-southeast-1.elasticbeanstalk.com/oauth
SEGMENT_KEY=3gE20MjzN9qncFqlKV0pDvNO7Cp2gWU3
FB_APP_ID=823885921293850
SENTRY_DSN=
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.10.0] - 2019-07-29

### Changed

- Remove response tip. #345
- Fix missing custom `<meta>` tags in UserArticle page #344
- Store feed sorter type in local via Apollo. #343
- CommentDraft @client; Remove <SelfActivationModal>; #341
- Local Schema for "Official.gatewayUrls" #340

## [1.9.0] - 2019-07-02

### Changed

- Fix styles of about page #336
- Alter article's design in Response #335
- Infinite article feed in the search result page #334
- Clear search input after the user selected search results #333
- Alter meta tags of user profile pages #332
- Share to Douban #327

## [1.8.0] - 2019-06-24

### Changed
Expand Down
13 changes: 13 additions & 0 deletions apollo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
client: {
name: 'Matters Web',
service: {
name: 'matters',
url: 'https://server-develop.matters.news/graphql'
},
includes: [
'+(pages|views|components)/**/*.{ts,tsx}',
'./common/utils/types/**/*.ts'
]
}
}
16 changes: 9 additions & 7 deletions bin/buildFragmentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ if (dotEnvResult.error) {
console.error(dotEnvResult.error)
}

fetch(`${process.env.API_URL}/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
variables: {},
query: `
fetch(process.env.API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
variables: {},
query: `
{
__schema {
types {
Expand All @@ -26,8 +28,8 @@ fetch(`${process.env.API_URL}/graphql`, {
}
}
`
})
})
})
.then(result => result.json())
.then(result => {
// here we're filtering out any type information unrelated to unions or interfaces
Expand Down
8 changes: 8 additions & 0 deletions common/enums/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ROUTE_KEY =
| 'AUTH_LOGIN'
| 'AUTH_SIGNUP'
| 'AUTH_FORGET'
| 'OAUTH_AUTHORIZE'
| 'MISC_ABOUT'
| 'MISC_FAQ'
| 'MISC_TOS'
Expand Down Expand Up @@ -188,6 +189,13 @@ export const ROUTES: Array<{
as: '/forget'
},

// OAuth
{
key: 'OAUTH_AUTHORIZE',
href: '/OAuthAuthorize',
as: '/oauth/authorize'
},

// Misc
{
key: 'MISC_ABOUT',
Expand Down
37 changes: 21 additions & 16 deletions common/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ const offset = (el: HTMLElement) => {
}

// copy to clipboard
const copyToClipboard = (str: string) => {
// Create new element
const el = document.createElement('textarea')
// Set value (string to be copied)
el.value = str
// Set non-editable to avoid focus and move outside of view
el.setAttribute('readonly', '')
el.style.position = 'absolute'
el.style.left = '-9999px'
document.body.appendChild(el)
// Select text inside element
el.select()
// Copy text to clipboard
document.execCommand('copy')
// Remove temporary element
document.body.removeChild(el)
const copyToClipboard = async (str: string) => {
const navigator = window.navigator
if (navigator && navigator.clipboard) {
await navigator.clipboard.writeText(str)
} else {
// Create new element
const el = document.createElement('textarea')
// Set value (string to be copied)
el.value = str
// Set non-editable to avoid focus and move outside of view
el.setAttribute('readonly', '')
el.style.position = 'absolute'
el.style.left = '-9999px'
document.body.appendChild(el)
// Select text inside element
el.select()
// Copy text to clipboard
document.execCommand('copy')
// Remove temporary element
document.body.removeChild(el)
}
}

const getAttributes = (name: string, str: string): string[] | [] => {
Expand Down
7 changes: 7 additions & 0 deletions common/utils/resolvers/clientPreference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (_: any) => {
return {
id: 'local',
feedSortType: 'hottest',
__typename: 'ClientPreference'
}
}
7 changes: 7 additions & 0 deletions common/utils/resolvers/commentDraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (_: any, { input: { id } }: { input: { id: string } }) => {
return {
id,
content: '',
__typename: 'CommentDraft'
}
}
61 changes: 61 additions & 0 deletions common/utils/resolvers/gatewayUrls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fetch from 'isomorphic-unfetch'

const TEST_HASH = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a'
const PUBLIC_GATEWAYS: string[] = [
'https://d26g9c7mfuzstv.cloudfront.net/ipfs/',
'https://ipfs.io/ipfs/',
'https://gateway.ipfs.io/ipfs/',
'https://ipfs.infura.io/ipfs/',
'https://ipfs.jes.xxx/ipfs/',
'https://siderus.io/ipfs/',
'https://ipfs.eternum.io/ipfs/',
'https://hardbin.com/ipfs/',
'https://ipfs.wa.hle.rs/ipfs/',
'https://cloudflare-ipfs.com/ipfs/',
'https://gateway.pinata.cloud/ipfs/',
'https://ipfs.sloppyta.co/ipfs/',
'https://ipfs.busy.org/ipfs/',
'https://ipfs.greyh.at/ipfs/',
'https://gateway.serph.network/ipfs/'
]

function timeout(ms: number, promise: any) {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('timeout'))
}, ms)
promise.then(resolve, reject)
})
}

// check accessbility for a given hash and gateway
const checkGateway = async (
hash: string,
gatewayUrl: string
): Promise<boolean> => {
const testUrl = `${gatewayUrl}${hash}#x-ipfs-companion-no-redirect`

try {
// const res = await fetch(testUrl)
const res = (await timeout(
2000,
fetch(testUrl)
)) as fetch.IsomorphicResponse
if (res && res.ok) {
return true
}
return false
} catch (err) {
console.log(`Gateway not alive, skipping: ${gatewayUrl}`)
return false
}
}

export default async () => {
const checkers = await Promise.all(
PUBLIC_GATEWAYS.map(url =>
checkGateway(TEST_HASH, url).then((alive: boolean) => ({ url, alive }))
)
)
return checkers.filter(({ alive }) => alive).map(({ url }) => url)
}
13 changes: 13 additions & 0 deletions common/utils/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import clientPreference from './clientPreference'
import commentDraft from './commentDraft'
import gatewayUrls from './gatewayUrls'

export default {
Query: {
clientPreference,
commentDraft
},
Official: {
gatewayUrls
}
}
4 changes: 1 addition & 3 deletions common/utils/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const toPath = (args: ToPathArgs): { href: string; as: string } => {
case 'articleDetail':
const asUrl = `/@${args.userName}/${args.slug}-${args.mediaHash}`
return {
href: `${PATHS.ARTICLE_DETAIL.href}?userName=${args.userName}&slug=${
args.slug
}&mediaHash=${args.mediaHash}`,
href: `${PATHS.ARTICLE_DETAIL.href}?userName=${args.userName}&slug=${args.slug}&mediaHash=${args.mediaHash}`,
as: args.fragment ? `${asUrl}#${args.fragment}` : asUrl
}
case 'draftDetail':
Expand Down
35 changes: 35 additions & 0 deletions common/utils/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import gql from 'graphql-tag'

export default gql`
extend type Query {
commentDraft(input: CommentDraftInput!): CommentDraft!
clientPreference(input: ClientPreferenceInput!): ClientPreference!
}
extend type Official {
gatewayUrls: [URL!]
}
type CommentDraft {
id: ID!
content: String!
}
input CommentDraftInput {
id: ID!
}
type ClientPreference {
id: ID!
feedSortType: FeedSortType
}
input ClientPreferenceInput {
id: ID!
}
enum FeedSortType {
hottest
newest
}
`
6 changes: 5 additions & 1 deletion common/utils/withApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import introspectionQueryResultData from '~/common/gql/fragmentTypes.json'
import { genSentryActionId } from '~/common/utils'

// import { setupPersistCache } from './cache'
import resolvers from './resolvers'
import typeDefs from './types'

const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData
Expand Down Expand Up @@ -123,6 +125,8 @@ export default withApollo(({ ctx, headers, initialState }) => {
sentryLink,
dataLink({ headers })
]),
cache: inMemoryCache
cache: inMemoryCache,
resolvers,
typeDefs
})
})
2 changes: 1 addition & 1 deletion components/Analytics/AnalyticsListener.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, wait } from '@testing-library/react'
import React from 'react'
import { render, wait } from 'react-testing-library'

import { analytics } from '~/common/utils'

Expand Down
Loading

0 comments on commit bff440b

Please sign in to comment.