Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit1eb7b39

Browse files
committed
refactor(communityCell): up to date
1 parent6f8878f commit1eb7b39

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+
importReactfrom'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+
consttooltipOffset=JSON.stringify({top:1})
9+
constCommunitiesLogoList=({ array})=>(
10+
<Wrapper>
11+
{array.map(c=>(
12+
<Wrapperkey={uid.gen()}>
13+
<div
14+
data-tip={c.title}
15+
data-for="community_cell"
16+
data-offset={tooltipOffset}
17+
>
18+
<CommunityLogosrc={c.logo}/>
19+
</div>
20+
</Wrapper>
21+
))}
22+
</Wrapper>
23+
)
24+
25+
exportdefaultCommunitiesLogoList

‎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
importAdderCellfrom'../AdderCell'
15+
importCommunitiesLogoListfrom'./CommunitiesLogoList'
1516

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

32-
consttooltipOffset=JSON.stringify({top:1})
33-
3433
constSingleCommunity=({ community})=>(
3534
<Wrapper>
3635
<CommunityLogosrc={community.logo}/>
3736
<Title>{community.title}</Title>
3837
</Wrapper>
3938
)
4039

41-
constCommunitiesLogoArray=({ array})=>(
42-
<Wrapper>
43-
{array.map(c=>(
44-
<Wrapperkey={uid.gen()}>
45-
<div
46-
data-tip={c.title}
47-
data-for="community_cell"
48-
data-offset={tooltipOffset}
49-
>
50-
<CommunityLogosrc={c.logo}/>
51-
</div>
52-
</Wrapper>
53-
))}
54-
</Wrapper>
55-
)
56-
5740
constCommunitiesSetter=({ 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-
<CommunitiesLogoArrayarray={array}/>
77+
<CommunitiesLogoListarray={array}/>
9578
</Wrapper>
9679
)
9780
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importstyledfrom'styled-components'
2+
3+
importImgfrom'../../Img'
4+
import{theme}from'../../../utils'
5+
6+
exportconstWrapper=styled.div`
7+
display: flex;
8+
align-items: center;
9+
justify-content: center;
10+
flex-wrap: wrap;
11+
max-width: 300px;
12+
`
13+
14+
exportconstCommunityLogo=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
classCategoriesContentextendsReact.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
classCommunitiesContentContainerextendsReact.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
importSfrom'./schema'
2121
importSR71from'../../utils/network/sr71'
2222

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

31+
letsub$=null
3332
letstore=null
3433

3534
constcommonFilter=page=>{
@@ -56,6 +55,7 @@ export function loadCommunities(page = 1) {
5655
exportfunctionloadCategories(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-
exportfunctioninit(selectedStore){
399-
if(store)returnfalse
400-
store=selectedStore
398+
exportfunctioninit(_store){
399+
store=_store
401400

402-
if(sub$)sub$.unsubscribe()
401+
if(sub$)returnloadCategories()
403402
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
403+
404+
loadCategories()
405+
}
406+
407+
exportfunctionuninit(){
408+
if(!sub$)returnfalse
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))returnfalse
43+
if(!onClient)returnfalse
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
constallQueryString=serializeQuery(query)
5853
constqueryString=serializeQuery(R.omit(['mainPath','subPath'],query))
5954

6055
consturl=`/${allQueryString}`
61-
letasPath=`/${self.mainPath}/${self.subPath}${queryString}`
62-
if(self.subPath==='index'||self.mainPath===self.subPath){
63-
asPath=`/${self.mainPath}${queryString}`
64-
}
56+
constasPath=`/${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)

[8]ページ先頭

©2009-2025 Movatter.jp