Skip to content

Commit

Permalink
Merge pull request #491 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v2.1.1
  • Loading branch information
robertu7 authored Oct 31, 2019
2 parents 2efd805 + 3c319cd commit fe79e34
Show file tree
Hide file tree
Showing 47 changed files with 2,087 additions and 2,025 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ 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).

## [2.1.1] - 2019-10-31

### Changed

- Fix form bugs with `useFormik` #487
- Update pageview & prevent likebutton insertion #486 #489
- Show userName in search user popper #490

## [2.1.0] - 2019-10-29

### Added
Expand Down
1,353 changes: 812 additions & 541 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matters-web",
"version": "2.1.0",
"version": "2.1.1",
"description": "codebase of Matters' website",
"author": "",
"engines": {
Expand Down Expand Up @@ -46,54 +46,54 @@
"apollo-utilities": "^1.3.2",
"body-scroll-lock": "^2.6.4",
"classnames": "^2.2.6",
"date-fns": "^2.5.0",
"date-fns": "^2.6.0",
"express": "^4.17.1",
"formik": "^1.5.8",
"formik": "^2.0.3",
"graphql": "^14.5.8",
"graphql-tag": "^2.10.1",
"helmet": "^3.21.1",
"helmet": "^3.21.2",
"isomorphic-unfetch": "^3.0.0",
"jump.js": "^1.0.2",
"lodash": "^4.17.15",
"module-alias": "^2.2.2",
"next": "^9.1.1",
"next": "^9.1.2",
"next-with-apollo": "^4.3.0",
"nprogress": "^0.2.0",
"query-string": "^6.8.3",
"react": "^16.10.2",
"react": "^16.11.0",
"react-apollo": "^3.1.2",
"react-beautiful-dnd": "^11.0.5",
"react-beautiful-dnd": "^12.0.0",
"react-content-loader": "^4.3.2",
"react-dom": "^16.10.2",
"react-dom": "^16.11.0",
"react-quill": "^1.3.3",
"react-responsive": "^8.0.1",
"react-waypoint": "^9.0.2",
"subscriptions-transport-ws": "^0.9.16",
"use-debounce": "^3.1.0",
"validator": "^11.1.0"
"validator": "^12.0.0"
},
"devDependencies": {
"@apollo/react-testing": "3.1.2",
"@apollo/react-testing": "^3.1.2",
"@testing-library/react": "^8.0.9",
"@types/body-scroll-lock": "^2.6.1",
"@types/classnames": "^2.2.9",
"@types/dotenv": "^6.1.1",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.1",
"@types/helmet": "0.0.44",
"@types/jest": "^24.0.19",
"@types/helmet": "0.0.45",
"@types/jest": "^24.0.21",
"@types/lodash": "^4.14.144",
"@types/next-server": "^8.1.2",
"@types/nprogress": "0.2.0",
"@types/quill": "^2.0.3",
"@types/react": "^16.9.9",
"@types/react": "^16.9.11",
"@types/react-beautiful-dnd": "^11.0.3",
"@types/react-dom": "^16.9.2",
"@types/react-dom": "^16.9.3",
"@types/react-responsive": "^8.0.1",
"@types/segment-analytics": "0.0.32",
"@types/styled-jsx": "^2.2.8",
"@types/validator": "^10.11.3",
"@zeit/next-bundle-analyzer": "^0.1.2",
"apollo": "^2.19.1",
"apollo": "^2.21.0",
"babel-jest": "^24.9.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-module-resolver": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion public/static/icons/more-small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/common/enums/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const ANALYTICS = 'analytics'
export const OPEN_MODAL = 'openModal'
export const ADD_TOAST = 'addToast'
export const REMOVE_TOAST = 'removeToast'
export const REFETCH_RESPONSES = 'refetchResponses'
1 change: 1 addition & 0 deletions src/common/utils/form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './validate'
203 changes: 203 additions & 0 deletions src/common/utils/form/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { TEXT } from '~/common/enums'
import {
countWordsLength,
isValidDisplayName,
isValidEmail,
isValidPassword,
isValidUserName,
translate
} from '~/common/utils'

export const validateEmail = (value: string, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (!isValidEmail(value)) {
result = {
zh_hant: TEXT.zh_hant.invalidEmail,
zh_hans: TEXT.zh_hans.invalidEmail
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateCode = (value: string, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validatePassword = (value: string, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (!isValidPassword(value)) {
result = {
zh_hant: TEXT.zh_hant.passwordHint,
zh_hans: TEXT.zh_hans.passwordHint
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateComparedPassword = (
value: string,
comparedValue: string,
lang: Language
) => {
let result

if (!comparedValue) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (comparedValue !== value) {
result = {
zh_hant: TEXT.zh_hant.passwordNotMatch,
zh_hans: TEXT.zh_hans.passwordNotMatch
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateUserName = (value: string, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (!isValidUserName(value)) {
result = {
zh_hant: TEXT.zh_hant.userNameHint,
zh_hans: TEXT.zh_hans.userNameHint
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateComparedUserName = (
value: string,
comparedValue: string,
lang: Language
) => {
let result

if (!comparedValue) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (comparedValue !== value) {
result = {
zh_hant: TEXT.zh_hant.invalidUserName,
zh_hans: TEXT.zh_hans.invalidUserName
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateDisplayName = (
value: string,
lang: Language,
isAdmin?: boolean
) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (!isValidDisplayName(value) && !isAdmin) {
result = {
zh_hant: TEXT.zh_hant.displayNameHint,
zh_hans: TEXT.zh_hans.displayNameHint
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateDescription = (value: string, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
} else if (countWordsLength(value) > 200) {
result = {
zh_hant: `已超過 200 字,目前 ${value.length} 字`,
zh_hans: `已超过 200 字,目前 ${value.length} 字`
}
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateToS = (value: boolean, lang: Language) => {
let result

if (value === false) {
result = { zh_hant: '請勾選', zh_hans: '请勾选' }
}

if (result) {
return translate({ ...result, lang })
}
}

export const validateAvatar = (value: string | null, lang: Language) => {
let result

if (!value) {
result = {
zh_hant: TEXT.zh_hant.required,
zh_hans: TEXT.zh_hans.required
}
}

if (result) {
return translate({ ...result, lang })
}
}
1 change: 1 addition & 0 deletions src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './url'
export * from './browser'
export * from './response'
export * from './oauth'
export * from './form'
11 changes: 3 additions & 8 deletions src/components/Analytics/AnalyticsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getConfig from 'next/config'
import Router from 'next/router'
import React, { useEffect, useState } from 'react'
import React, { useEffect } from 'react'

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

Expand All @@ -9,8 +9,6 @@ const {
} = getConfig()

export const AnalyticsProvider: React.FC = ({ children }) => {
const [sessionStarted, setSessionStarted] = useState(false)

useEffect(() => {
// injects analytics var into global scope
// ref: https://github.com/segmentio/analytics-react#%EF%B8%8F-step-1-copy-the-snippet
Expand Down Expand Up @@ -82,11 +80,8 @@ export const AnalyticsProvider: React.FC = ({ children }) => {

useEffect(() => {
// initial
if (!sessionStarted) {
analytics.identifyUser()
analytics.trackPage({ path: window.location.pathname })
setSessionStarted(true)
}
analytics.identifyUser()
analytics.trackPage({ path: window.location.pathname })
Router.events.on('routeChangeComplete', (path: string) => {
analytics.trackPage({ path })
})
Expand Down
1 change: 1 addition & 0 deletions src/components/ArticleDigest/DropdownActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const DropdownActions = ({ article }: { article: DropdownActionsArticle }) => {
size="small"
id={ICON_MORE_SMALL.id}
viewBox={ICON_MORE_SMALL.viewBox}
color="grey"
/>
</button>
</Dropdown>
Expand Down
17 changes: 2 additions & 15 deletions src/components/ArticleDigest/FeatureDigest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const fragments = {
id
userName
}
oss {
todayCover
}
...DigestActionsArticle
}
${Actions.fragments.article}
Expand All @@ -41,15 +38,7 @@ const FeatureDigest = ({
article: TodayDigestArticle
onClick?: MouseEventHandler
} & ActionsControls) => {
const {
cover,
author,
slug,
mediaHash,
title,
summary,
oss: { todayCover }
} = article
const { cover, author, slug, mediaHash, title, summary } = article

if (!author || !author.userName || !slug || !mediaHash) {
return null
Expand All @@ -70,9 +59,7 @@ const FeatureDigest = ({
<div
className="cover"
style={{
backgroundImage: `url(${todayCover ||
cover ||
IMAGE_COVER_FALLBACK})`
backgroundImage: `url(${cover || IMAGE_COVER_FALLBACK})`
}}
/>
</a>
Expand Down
1 change: 1 addition & 0 deletions src/components/CommentDigest/DropdownActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const DropdownActions = ({
size="small"
id={ICON_MORE_SMALL.id}
viewBox={ICON_MORE_SMALL.viewBox}
color="grey"
/>
</button>
</Dropdown>
Expand Down
Loading

0 comments on commit fe79e34

Please sign in to comment.