@@ -9,7 +9,7 @@ import { DiscussionEmbed } from "disqus-react";
9
9
import { formatFriendlyDateForLocalTimezone , showSimpleMessage , targetedNetwork , waitUntilTrue } from "lib/util" ;
10
10
import customDaoInfo from "../../customDaoInfo" ;
11
11
import i18next from "i18next" ;
12
- import { addPost , getPosts , joinThread , subcribeToThread , threeboxLogin } from "actions/profilesActions" ;
12
+ import { addPost , getPosts , getThread , joinThread , subcribeToThread , threeboxLogin } from "actions/profilesActions" ;
13
13
import { connect } from "react-redux" ;
14
14
import { I3BoxThread , I3BoxThreadPost , IProfilesState } from "reducers/profilesReducer" ;
15
15
import { IRootState } from "reducers" ;
@@ -34,6 +34,7 @@ interface IDispatchProps {
34
34
35
35
interface IExternalStateProps {
36
36
profiles : IProfilesState ;
37
+ threeBox : any ;
37
38
}
38
39
39
40
interface IStateProps {
@@ -52,6 +53,7 @@ const mapStateToProps = (state: IRootState, ownProps: IExternalProps): IExternal
52
53
return {
53
54
...ownProps ,
54
55
profiles : state . profiles ,
56
+ threeBox : state . profiles . threeBox ,
55
57
} ;
56
58
} ;
57
59
@@ -74,12 +76,16 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
74
76
}
75
77
76
78
77
- private get3BoxThread ( ) : Promise < I3BoxThread | null > {
78
- return joinThread ( this . props . daoState . id , this . props . currentAccountAddress , this . props . profiles ) ;
79
+ private get3BoxThread ( join = false ) : Promise < I3BoxThread | null > {
80
+ if ( join ) {
81
+ return joinThread ( this . props . daoState . id , this . props . currentAccountAddress , this . props . profiles ) ;
82
+ } else {
83
+ return getThread ( this . props . daoState . id ) ;
84
+ }
79
85
}
80
86
81
- private getPosts = async ( thread ? : I3BoxThread ) => {
82
- return ( await getPosts ( thread , this . props . daoState . id ) ) . sort ( ( a , b ) =>
87
+ private getPosts = async ( thread : I3BoxThread ) => {
88
+ return ( await getPosts ( thread ) ) . sort ( ( a , b ) =>
83
89
{ return SortService . evaluateDateTime ( a . createDate , b . createDate , SortOrder . DESC ) ; } ) ;
84
90
}
85
91
@@ -90,18 +96,19 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
90
96
"DAO Name" : this . props . daoState . name ,
91
97
} ) ;
92
98
93
- const state : Partial < IStateProps > = { } ;
94
99
const thread = await this . get3BoxThread ( ) ;
95
100
if ( thread ) {
96
- subcribeToThread ( thread , this . handleNewPosts ) ;
97
- state . joinedThread = thread ;
101
+ // subcribeToThread(thread, this.handleNewPosts);
102
+ const posts = await this . getPosts ( thread ) ;
103
+ this . setState ( { threeboxPosts : posts } ) ;
98
104
}
99
- const posts = await this . getPosts ( thread ) ;
100
- state . threeboxPosts = posts ;
105
+ }
101
106
102
- this . setState ( state ) ;
107
+ componentWillUnmount ( ) {
108
+ this . setState ( { threeboxPosts : null , joinedThread : null , hasCommentInput : false , joiningThread : false } ) ;
103
109
}
104
110
111
+
105
112
private handleNewPosts = async ( ) => {
106
113
const posts = await this . getPosts ( this . state . joinedThread ) ;
107
114
this . setState ( { threeboxPosts : posts } ) ;
@@ -133,10 +140,10 @@ class DaoLandingPage extends React.Component<IProps, IStateProps> {
133
140
await waitUntilTrue ( ( ) => ! ! this . props . currentAccountAddress && getAccountIsEnabled ( ) , 15000 ) ;
134
141
await this . props . threeboxLogin ( this . props . currentAccountAddress ) ;
135
142
await waitUntilTrue ( ( ) => ! ! this . props . profiles . threeBoxSpace , 30000 ) ;
136
- const thread = await this . get3BoxThread ( ) ;
143
+ const thread = await this . get3BoxThread ( true ) ;
137
144
if ( thread ) {
138
145
subcribeToThread ( thread , this . handleNewPosts ) ;
139
- this . setState ( { joinedThread : thread } ) ;
146
+ this . setState ( { joinedThread : thread } ) ; // so we can see our new posts when we post them
140
147
} else {
141
148
showNotification ( NotificationStatus . Failure , "Unable to join the conversation" ) ;
142
149
}
0 commit comments