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

Commit b4e1630

Browse files
committed
refactor(communityCell): up to date
1 parent 7f12ba7 commit b4e1630

File tree

7 files changed

+77
-44
lines changed

7 files changed

+77
-44
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
3+
// import { ICON_CMD } from '../../config'
4+
import { Wrapper, CommunityLogo } from './styles/communities_logo_list'
5+
6+
import { uid } from '../../utils'
7+
8+
const tooltipOffset = JSON.stringify({ top: 1 })
9+
const CommunitiesLogoList = ({ array }) => (
10+
<Wrapper>
11+
{array.map(c => (
12+
<Wrapper key={uid.gen()}>
13+
<div
14+
data-tip={c.title}
15+
data-for="community_cell"
16+
data-offset={tooltipOffset}
17+
>
18+
<CommunityLogo src={c.logo} />
19+
</div>
20+
</Wrapper>
21+
))}
22+
</Wrapper>
23+
)
24+
25+
export default CommunitiesLogoList

components/CommunityCell/index.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ReactTooltip from 'react-tooltip'
1212
import { ICON_CMD } from '../../config'
1313

1414
import AdderCell from '../AdderCell'
15+
import CommunitiesLogoList from './CommunitiesLogoList'
1516

1617
import {
1718
Wrapper,
@@ -29,31 +30,13 @@ import { uid, makeDebugger } from '../../utils'
2930
const debug = makeDebugger('c:CommunityCell:index')
3031
/* eslint-enable no-unused-vars */
3132

32-
const tooltipOffset = JSON.stringify({ top: 1 })
33-
3433
const SingleCommunity = ({ community }) => (
3534
<Wrapper>
3635
<CommunityLogo src={community.logo} />
3736
<Title>{community.title}</Title>
3837
</Wrapper>
3938
)
4039

41-
const CommunitiesLogoArray = ({ array }) => (
42-
<Wrapper>
43-
{array.map(c => (
44-
<Wrapper key={uid.gen()}>
45-
<div
46-
data-tip={c.title}
47-
data-for="community_cell"
48-
data-offset={tooltipOffset}
49-
>
50-
<CommunityLogo src={c.logo} />
51-
</div>
52-
</Wrapper>
53-
))}
54-
</Wrapper>
55-
)
56-
5740
const CommunitiesSetter = ({ array, source, thread, onDelete }) => (
5841
<Wrapper>
5942
{array.map(c => (
@@ -91,7 +74,7 @@ const renderContent = props => {
9174
if (!R.isEmpty(array)) {
9275
return (
9376
<Wrapper>
94-
<CommunitiesLogoArray array={array} />
77+
<CommunitiesLogoList array={array} />
9578
</Wrapper>
9679
)
9780
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styled from 'styled-components'
2+
3+
import Img from '../../Img'
4+
import { theme } from '../../../utils'
5+
6+
export const Wrapper = styled.div`
7+
display: flex;
8+
align-items: center;
9+
justify-content: center;
10+
flex-wrap: wrap;
11+
max-width: 300px;
12+
`
13+
14+
export const CommunityLogo = styled(Img)`
15+
fill: ${theme('thread.articleTitle')};
16+
width: 22px;
17+
height: 22px;
18+
margin-bottom: 4px;
19+
display: block;
20+
margin-right: 5px;
21+
`

containers/CommunitiesContent/CategoriesContent.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ const columns = [
111111

112112
class CategoriesContent extends React.Component {
113113
componentDidMount() {
114-
logic.loadCategories()
115-
116114
setTimeout(() => {
117115
ReactTooltip.rebuild()
118116
}, 2000)

containers/CommunitiesContent/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ const renderChildContent = (curRoute, store, restProps) => {
6565
class CommunitiesContentContainer extends React.Component {
6666
componentDidMount() {
6767
const { communitiesContent } = this.props
68+
6869
logic.init(communitiesContent)
6970
}
7071

72+
componentWillUnmount() {
73+
logic.uninit()
74+
}
75+
7176
render() {
7277
const { communitiesContent } = this.props
7378
const { curRoute } = communitiesContent

containers/CommunitiesContent/logic.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { PAGE_SIZE } from '../../config'
2020
import S from './schema'
2121
import SR71 from '../../utils/network/sr71'
2222

23-
let sub$ = null
24-
2523
const sr71$ = new SR71({
2624
resv_event: [EVENT.LOGOUT, EVENT.LOGIN, EVENT.PREVIEW_CLOSE],
2725
})
@@ -30,6 +28,7 @@ const sr71$ = new SR71({
3028
const debug = makeDebugger('L:CommunitiesContent')
3129
/* eslint-enable no-unused-vars */
3230

31+
let sub$ = null
3332
let store = null
3433

3534
const commonFilter = page => {
@@ -56,6 +55,7 @@ export function loadCommunities(page = 1) {
5655
export function loadCategories(page = 1) {
5756
scrollIntoEle(TYPE.APP_HEADER_ID)
5857
/* const size = PAGE_SIZE.COMMON */
58+
console.log('the fuck store: ', store)
5959
store.markRoute({ page })
6060
store.markState({ categoriessLoading: true })
6161

@@ -395,10 +395,18 @@ const ErrSolver = [
395395
},
396396
]
397397

398-
export function init(selectedStore) {
399-
if (store) return false
400-
store = selectedStore
398+
export function init(_store) {
399+
store = _store
401400

402-
if (sub$) sub$.unsubscribe()
401+
if (sub$) return loadCategories()
403402
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
403+
404+
loadCategories()
405+
}
406+
407+
export function uninit() {
408+
if (!sub$) return false
409+
debug('===== do uninit')
410+
sub$.unsubscribe()
411+
sub$ = null
404412
}

stores/RouteStore/index.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,27 @@ const RouteStore = t
4040
// /racket/jobs ..
4141

4242
markRoute(query) {
43-
if (!onClient || R.isEmpty(query)) return false
43+
if (!onClient) return false
4444
const { mainPath, subPath, page } = query
45+
query = R.pickBy(v => !R.isEmpty(v), query)
4546

46-
if (mainPath) {
47-
self.mainPath = mainPath
48-
}
49-
if (subPath) {
50-
self.subPath = subPath
51-
}
47+
if (mainPath) self.mainPath = mainPath
48+
if (subPath) self.subPath = subPath
5249

53-
if (page && String(page) === '1') {
54-
query = R.omit(['page'], query)
55-
}
50+
if (page && String(page) === '1') query = R.omit(['page'], query)
5651

5752
const allQueryString = serializeQuery(query)
5853
const queryString = serializeQuery(R.omit(['mainPath', 'subPath'], query))
5954

6055
const url = `/${allQueryString}`
61-
let asPath = `/${self.mainPath}/${self.subPath}${queryString}`
62-
if (self.subPath === 'index' || self.mainPath === self.subPath) {
63-
asPath = `/${self.mainPath}${queryString}`
64-
}
56+
const asPath = `/${self.mainPath}/${self.subPath}${queryString}`
6557

6658
// NOTE: shallow option only works for same page url
6759
// if page is diffrent, it will cause page reload
68-
Router.push(url, asPath, {
69-
shallow: true,
70-
})
60+
/* console.log('push url: ', url) */
61+
Router.push(url, asPath, { shallow: true })
62+
// see: https://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page
63+
/* return Global.history.pushState({}, null, url) */
7164
},
7265
markState(sobj) {
7366
markStates(sobj, self)

0 commit comments

Comments
 (0)