@@ -14,9 +14,10 @@ import { connect } from "react-redux";
14
14
import { I3BoxThread , I3BoxThreadPost , IProfilesState } from "reducers/profilesReducer" ;
15
15
import { IRootState } from "reducers" ;
16
16
import { enableWalletProvider , getAccountIsEnabled } from "arc" ;
17
- import { showNotification } from "reducers/notifications" ;
17
+ import { NotificationStatus , showNotification } from "reducers/notifications" ;
18
18
import AccountPopup from "components/Account/AccountPopup" ;
19
19
import AccountProfileName from "components/Account/AccountProfileName" ;
20
+ import { SortOrder , SortService } from "lib/sortService" ;
20
21
21
22
type IExternalProps = {
22
23
daoState : IDAOState ;
@@ -35,6 +36,7 @@ interface IExternalStateProps {
35
36
interface IStateProps {
36
37
threeboxPosts ?: Array < I3BoxThreadPost > ;
37
38
joinedThread ?: I3BoxThread ;
39
+ joiningThread ?: boolean ;
38
40
}
39
41
40
42
const mapDispatchToProps = {
@@ -62,6 +64,7 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
62
64
this . state = {
63
65
threeboxPosts : null ,
64
66
joinedThread : null ,
67
+ joiningThread : false ,
65
68
} ;
66
69
}
67
70
@@ -70,6 +73,10 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
70
73
return joinThread ( this . props . daoState . id , this . props . currentAccountAddress , this . props . profiles ) ;
71
74
}
72
75
76
+ private getPosts = async ( ) => {
77
+ return ( await getPosts ( this . props . daoState . id ) ) . sort ( ( a , b ) =>
78
+ { return SortService . evaluateDateTime ( a . createDate , b . createDate , SortOrder . DESC ) ; } ) ;
79
+ }
73
80
public async componentDidMount ( ) : Promise < void > {
74
81
Analytics . track ( "Page View" , {
75
82
"Page Name" : Page . DAOLanding ,
@@ -83,14 +90,14 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
83
90
subcribeToThread ( thread , this . handleNewPosts ) ;
84
91
state . joinedThread = thread ;
85
92
}
86
- const posts = await getPosts ( this . props . daoState . id ) ;
93
+ const posts = await this . getPosts ( ) ;
87
94
state . threeboxPosts = posts ;
88
95
89
96
this . setState ( state ) ;
90
97
}
91
98
92
99
private handleNewPosts = async ( ) => {
93
- const posts = await getPosts ( this . props . daoState . id ) ;
100
+ const posts = await this . getPosts ( ) ;
94
101
this . setState ( { threeboxPosts : posts } ) ;
95
102
}
96
103
@@ -108,19 +115,34 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
108
115
}
109
116
110
117
private startDiscussion = async ( ) => {
111
- if ( ! this . state . joinedThread ) {
112
- if ( ! await enableWalletProvider ( { showNotification : this . props . showNotification } ) ) {
113
- return ;
114
- } else {
115
- await waitUntilTrue ( ( ) => ! ! this . props . currentAccountAddress && getAccountIsEnabled ( ) , 60000 ) ;
116
- await this . props . threeboxLogin ( this . props . currentAccountAddress ) ;
117
- await waitUntilTrue ( ( ) => ! ! this . props . profiles . threeBoxSpace , 60000 ) ;
118
- const thread = await this . get3BoxThread ( ) ;
119
- if ( thread ) {
120
- subcribeToThread ( thread , this . handleNewPosts ) ;
121
- this . setState ( { joinedThread : thread } ) ;
118
+ let joining = false ;
119
+ try {
120
+ if ( ! this . state . joinedThread ) {
121
+ joining = true ;
122
+ this . setState ( { joiningThread : true } ) ;
123
+ await waitUntilTrue ( ( ) => this . state . joiningThread , 10000 ) ;
124
+
125
+ if ( ! await enableWalletProvider ( { showNotification : this . props . showNotification } ) ) {
126
+ return ;
127
+ } else {
128
+ await waitUntilTrue ( ( ) => ! ! this . props . currentAccountAddress && getAccountIsEnabled ( ) , 15000 ) ;
129
+ await this . props . threeboxLogin ( this . props . currentAccountAddress ) ;
130
+ await waitUntilTrue ( ( ) => ! ! this . props . profiles . threeBoxSpace , 30000 ) ;
131
+ const thread = await this . get3BoxThread ( ) ;
132
+ if ( thread ) {
133
+ subcribeToThread ( thread , this . handleNewPosts ) ;
134
+ this . setState ( { joinedThread : thread } ) ;
135
+ } else {
136
+ showNotification ( NotificationStatus . Failure , "Unable to join the conversation" ) ;
137
+ }
122
138
}
123
139
}
140
+ } catch ( ex ) {
141
+ showNotification ( NotificationStatus . Failure , `Unable to join the conversation: ${ ex ?. message ?? "unknown error" } ` ) ;
142
+ } finally {
143
+ if ( joining ) {
144
+ this . setState ( { joiningThread : false } ) ;
145
+ }
124
146
}
125
147
}
126
148
@@ -173,8 +195,10 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
173
195
< div className = { css . headerText } > Discuss { daoState . name } </ div >
174
196
< div className = { css . discussionWarning } > IMPORTANT! We are moving from Disqus to 3Box for commenting! Before long, all the Disqus comments will disappear. So for a short time we are making both systems available here so that you may copy important comments from Disqus into 3Box, before the Disqus comments all disappear.</ div >
175
197
< div className = { css . startDiscussionButton } >
176
- { ( ( this . state . threeboxPosts !== null ) && ( ! this . state . threeboxPosts . length || ! this . state . joinedThread ) ) ?
177
- < a onClick = { this . startDiscussion } > { this . state . threeboxPosts . length ? "Join the Conversation" : "Start a Conversation" } </ a >
198
+ { ! this . state . joinedThread ?
199
+ < a onClick = { this . startDiscussion } > { this . state . threeboxPosts ?. length ? "Join the Conversation" : "Start a Conversation" }
200
+ { this . state . joiningThread ? < img className = { css . loading } src = "/assets/images/Icon/Loading-white.svg" /> : "" }
201
+ </ a >
178
202
: ""
179
203
}
180
204
</ div >
@@ -188,12 +212,16 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
188
212
< div className = { css . threeboxposts } >
189
213
{ this . state . threeboxPosts . map ( ( post , index ) => {
190
214
return ( < div key = { index } className = { css . threeboxpost } >
191
- < div className = { css . author } >
192
- < AccountPopup accountAddress = { post . author } daoState = { daoState } />
193
- < AccountProfileName accountAddress = { post . author } accountProfile = { this . props . profiles [ post . author ] } daoAvatarAddress = { daoState . address } />
215
+ < div className = { css . column1 } >
216
+ < AccountPopup accountAddress = { post . author } daoState = { daoState } width = { 38 } />
217
+ </ div >
218
+ < div className = { css . column2 } >
219
+ < div className = { css . info } >
220
+ < div className = { css . author } > < AccountProfileName accountAddress = { post . author } accountProfile = { this . props . profiles [ post . author ] } daoAvatarAddress = { daoState . address } /> </ div >
221
+ < div className = { css . createdOn } > { formatFriendlyDateForLocalTimezone ( post . createDate ) } </ div >
222
+ </ div >
223
+ < div className = { css . message } > { post . message } </ div >
194
224
</ div >
195
- < div className = { css . createdOn } > ({ formatFriendlyDateForLocalTimezone ( post . createDate ) } )</ div >
196
- < div className = { css . message } > { post . message } </ div >
197
225
</ div > ) ;
198
226
} )
199
227
}
0 commit comments