Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 2005ebb

Browse files
authored
refactor(prod): debug prod data & adjust (#1205)
* chore(pages): rename fetchData -> loader, inspired by remix * refactor(community-digest): add trend-line to content & re-org * fix(drewer): edge case judge & cyper & tags display adjust * chore(cper): map hint & style adjust * chore(community): use articleCount field * chore(cper-map): scrollbar adjust & clean up * chore(cper-map): adjust style * refactor(community-digest): re-org number status * chore(error-links): fix wrong links & footer logo adjust * chore(cpers-map): adjust note text * chore(cpers-map): adjust note text * chore(cpers-map): re-org & adjust styles * chore(cpers-map): re-org ranking & loading style
1 parent 1a270ea commit 2005ebb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+472
-336
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"cross-env": "^7.0.2",
6363
"css-doodle": "^0.21.6",
6464
"express": "^4.16.4",
65+
"g2": "^2.3.13",
6566
"glob": "^7.1.2",
6667
"graphql": "^15.5.1",
6768
"graphql-request": "3.5.0",

src/containers/content/ExploreContent/CommunityCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { TCommunity, TID } from '@/spec'
66
import { NON_FILL_COMMUNITY } from '@/constant'
77
import { prettyNum, cutRest } from '@/utils/helper'
88

9-
import TrendLine from '@/widgets/TrendLine'
109
import { SpaceGrow } from '@/widgets/Common'
10+
import { TrendLine } from '@/widgets/dynamic'
1111

1212
import SubscribeBtn from './SubscribeBtn'
1313

src/containers/content/ExploreContent/NotFound.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC, memo } from 'react'
22
import Link from 'next/link'
33

4+
import { ROUTE } from '@/constant'
45
import { cutRest } from '@/utils/helper'
56

67
import {
@@ -26,7 +27,7 @@ const NotFound: FC<TProps> = ({ searchValue }) => {
2627
</EmptyTitle>
2728
<EmptyDesc>
2829
若没有你感兴趣的社区, 你可以
29-
<Link href="/create/community" passHref>
30+
<Link href={`/${ROUTE.APPLY_COMMUNITY}`} passHref>
3031
<IssueLink>参与创建</IssueLink>
3132
</Link>
3233
</EmptyDesc>

src/containers/content/ExploreContent/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const pagedCommunities = gql`
88
${F.community}
99
contributesDigest
1010
subscribersCount
11+
articlesCount
1112
viewerHasSubscribed @include(if: $userHasLogin)
1213
}
1314
${F.pagi}
@@ -22,6 +23,7 @@ const searchCommunities = gql`
2223
${F.community}
2324
contributesDigest
2425
subscribersCount
26+
articlesCount
2527
viewerHasSubscribed @include(if: $userHasLogin)
2628
}
2729
${F.pagi}

src/containers/thread/CperMapThread/GeoMap.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@ import ReactResizeDetector from 'react-resize-detector'
44
import uid from '@/utils/uid'
55
import { buildLog } from '@/utils/logger'
66

7-
import { Br } from '@/widgets/Common'
8-
import NoticeBar from '@/widgets/NoticeBar'
97
import fetchGeoData from './geo_data'
8+
import { MapWrapper, RealMap, NoticeWrapper, TheLink } from './styles'
109

11-
import { MapWrapper, RealMap, NoticeWrapper } from './styles'
12-
13-
// TODO import it globaly, g2 is too big to load in time (> 400KB)
14-
// import G2 from 'g2'
10+
import G2 from 'g2'
1511

1612
/* eslint-disable-next-line */
1713
const log = buildLog('c:LocationMap')
1814

15+
// see example at https://antv.vision/old-site/g2/demo/10-map/map-projection.html
1916
class LocationMap extends React.Component {
2017
constructor(props) {
2118
super(props)
2219
this.chart = null
23-
// if id start with number, is not valid
24-
// see https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers
2520
this.chartId = `id-${uid.gen()}`
2621

2722
const { curTheme } = props
@@ -68,7 +63,7 @@ class LocationMap extends React.Component {
6863
G2.track(false)
6964

7065
this.chart.forceFit()
71-
// animate it's to "dragy"
66+
// animate it's to0 "dragy"
7267
this.chart.animate(false)
7368
this.chart.legend(false)
7469
this.chart.tooltip({ title: null })
@@ -159,8 +154,8 @@ class LocationMap extends React.Component {
159154
})
160155
.catch((ex) => log('parsing failed', ex))
161156
}
162-
/* eslint-enable no-undef */
163157

158+
/* eslint-enable no-undef */
164159
render() {
165160
return (
166161
<MapWrapper>
@@ -174,8 +169,22 @@ class LocationMap extends React.Component {
174169
/>
175170
<RealMap id={this.chartId} />
176171
<NoticeWrapper>
177-
上图显示数据为本站已注册用户在中国境内的分布范围,数据由 IP
178-
地址根据第三方地图服务商获得,仅供参考。
172+
地理坐标信息由注册用户 IP
173+
地址根据第三方地图服务商获得(城市定位仅限国内)。由定位失败或科学上网等因素导致的误差后期会专门提供手动矫正措施。全球范围内的访问数据可
174+
<TheLink
175+
href="https://plausible.io/coderplanets.com/countries"
176+
target="_blank"
177+
>
178+
参考这里
179+
</TheLink>
180+
(台湾地区单独统计,
181+
<TheLink
182+
href="https://en.wikipedia.org/wiki/ISO_3166-2:TW"
183+
target="_blank"
184+
>
185+
非技术原因
186+
</TheLink>
187+
,本站不持任何政治立场)。
179188
</NoticeWrapper>
180189
</MapWrapper>
181190
)

src/containers/thread/CperMapThread/MapLoading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC, memo } from 'react'
22

3-
import { LavaLampLoading } from '@/widgets/dynamic'
3+
import LavaLampLoading from '@/widgets/Loading/LavaLampLoading'
44
import { Wrapper, LoadingIcon, Desc } from './styles/map_loading'
55

66
const MapLoading: FC = () => (

src/containers/thread/CperMapThread/NumDashboard.tsx renamed to src/containers/thread/CperMapThread/RankingBoard.tsx

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import { FC, memo } from 'react'
22
import { sort, isEmpty } from 'ramda'
33

44
import CustomScroller from '@/widgets/CustomScroller'
5-
// import { ICON_CMD } from '../../config'
6-
import DotDivider from '@/widgets/DotDivider'
75

86
import {
97
Wrapper,
10-
SumWrapper,
11-
DetailText,
128
DashItem,
139
Divider,
1410
Title,
15-
Num,
1611
Chart,
1712
ChartBar,
18-
} from './styles/num_dashboard'
13+
TotalWrapper,
14+
TotalNum,
15+
} from './styles/raning_board'
1916

2017
type TMarker = {
2118
city: string
@@ -32,42 +29,56 @@ type TProps = {
3229
geoData: TMarker[]
3330
}
3431

35-
const NumDashboard: FC<TProps> = ({ total, geoData }) => {
32+
const RankingBoard: FC<TProps> = ({ total, geoData }) => {
3633
if (isEmpty(geoData)) return null
3734

3835
const sortGeo = sortByValue(geoData) || []
3936
const maxValue = sortGeo[0].value || 0
37+
const topList = sortGeo.slice(0, 3)
38+
const restList = sortGeo.slice(3)
4039

4140
return (
4241
<Wrapper>
43-
{/* <SumWrapper>
44-
总人数: {total} <DotDivider />{' '}
45-
</SumWrapper> */}
42+
{topList.map((item) => (
43+
<div key={item.value + item.city}>
44+
<DashItem>
45+
<Title active>{item.city}</Title>
46+
<Chart>
47+
<ChartBar
48+
width={`${Math.floor((item.value / maxValue) * 100)}%`}
49+
active
50+
/>
51+
</Chart>
52+
</DashItem>
53+
</div>
54+
))}
55+
<Divider />
56+
4657
<CustomScroller
4758
direction="vertical"
48-
height="200px"
59+
height="180px"
4960
showShadow={false}
50-
autoHide
61+
autoHide={false}
5162
>
52-
{sortGeo.map((item, idx) => (
63+
{restList.map((item) => (
5364
<div key={item.value + item.city}>
5465
<DashItem>
55-
<Title active={idx <= 2}>{item.city}</Title>
56-
{/* <DotDivider radius={3} space={3} />
57-
<Num>{item.value}人</Num> */}
66+
<Title>{item.city}</Title>
5867
<Chart>
5968
<ChartBar
6069
width={`${Math.floor((item.value / maxValue) * 100)}%`}
61-
active={idx <= 2}
6270
/>
6371
</Chart>
6472
</DashItem>
65-
<Divider show={idx === 2} />
6673
</div>
6774
))}
6875
</CustomScroller>
76+
<Divider />
77+
<TotalWrapper>
78+
总数: <TotalNum>{total}</TotalNum>
79+
</TotalWrapper>
6980
</Wrapper>
7081
)
7182
}
7283

73-
export default memo(NumDashboard)
84+
export default memo(RankingBoard)

src/containers/thread/CperMapThread/RealMap.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/containers/thread/CperMapThread/index.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,49 @@
44
*
55
*/
66

7-
import { FC, memo } from 'react'
7+
import { FC } from 'react'
88
import dynamic from 'next/dynamic'
9+
import { useTheme } from 'styled-components'
910

1011
import { buildLog } from '@/utils/logger'
12+
import { pluggedIn } from '@/utils/mobx'
13+
14+
import RankingBoard from './RankingBoard'
1115
import MapLoading from './MapLoading'
1216

1317
import { Wrapper } from './styles'
18+
import type { TStore } from './store'
19+
import { useInit } from './logic'
1420

1521
/* eslint-disable-next-line */
1622
const log = buildLog('C:CperMapThread')
1723

18-
export const RealMap = dynamic(() => import('./RealMap'), {
19-
/* eslint-disable react/display-name */
20-
loading: () => <MapLoading />,
24+
const GeoMap = dynamic(() => import('./GeoMap'), {
2125
ssr: false,
2226
})
2327

24-
const CperMapThread: FC = () => {
28+
type TProps = {
29+
cperMapThread?: TStore
30+
}
31+
32+
const CperMapThreadContainer: FC<TProps> = ({ cperMapThread: store }) => {
33+
useInit(store)
34+
const theme = useTheme()
35+
36+
const { geoInfosData, geoDataLoading, curCommunity, curTheme } = store
37+
const ready = !geoDataLoading
38+
const markers = geoDataLoading ? [] : geoInfosData
39+
40+
if (!ready) {
41+
return <MapLoading />
42+
}
43+
2544
return (
2645
<Wrapper>
27-
<RealMap />
46+
<RankingBoard total={curCommunity.subscribersCount} geoData={markers} />
47+
<GeoMap markers={markers} curTheme={curTheme} theme={theme} />
2848
</Wrapper>
2949
)
3050
}
3151

32-
export default memo(CperMapThread)
52+
export default pluggedIn(CperMapThreadContainer) as FC<TProps>

0 commit comments

Comments
 (0)