@@ -21,6 +21,7 @@ class Duplicator extends Component {
2121 this . handleConfirm = this . handleConfirm . bind ( this ) ;
2222 this . onChangeCheckBox = this . onChangeCheckBox . bind ( this ) ;
2323 this . closeToast = this . closeToast . bind ( this )
24+ this . addUserToEntity = this . addUserToEntity . bind ( this )
2425 }
2526
2627 handleClose ( ) {
@@ -41,40 +42,43 @@ class Duplicator extends Component {
4142 }
4243 }
4344
44- handleConfirm ( ) {
45- let db = hypertopic ( [
46- "http://argos2.test.hypertopic.org" ,
47- "http://steatite.hypertopic.org"
48- ] ) ;
49-
50- const _error = ( x ) => console . error ( x . message ) ;
45+ async handleConfirm ( ) {
46+ this . setState ( { showModalConfirmation : false , showToast : true } ) ;
5147
48+ var ids = this . state . viewpoints . concat ( this . state . corpora )
5249 let that = this
5350
51+ await Promise . all ( ids . map ( id => that . addUserToEntity ( id ) ) )
52+ //refresh page
53+ this . setState ( { showToast : false } ) ;
54+ window . location . replace ( "http://" + this . nameDuplicatedPortfolio + ".local:3000" ) ;
5455
55- this . state . viewpoints . forEach ( function ( viewpoint ) {
56- db . getView ( '/viewpoint/' + viewpoint )
57- . then ( ( x ) => {
58- x [ viewpoint ] . user . push ( that . nameDuplicatedPortfolio )
59- return x
60- } )
61- . then ( db . post )
62- . catch ( _error ) ;
63- } ) ;
56+ }
6457
65- this . state . corpora . forEach ( function ( corpus ) {
66- db . getView ( '/corpus/' + corpus )
67- . then ( ( x ) => {
68- x [ corpus ] . user . push ( that . nameDuplicatedPortfolio )
69- return x
70- } )
71- . then ( db . post )
72- . catch ( _error ) ;
73- } ) ;
58+ addUserToEntity ( user ) {
59+ let db = hypertopic ( [
60+ "http://localhost" ,
61+ "http://steatite.hypertopic.org"
62+ ] ) ;
63+
64+ const _error = ( x ) => {
65+ console . error ( x . message )
66+ return x
67+ } ;
7468
75- this . setState ( { showModalConfirmation : false , showToast : true } ) ;
76- document . location = 'http://' + this . nameDuplicatedPortfolio + '.porphyry.org/'
69+ return db . get ( { _id :user } )
70+ . then ( ( x ) => {
71+ if ( ! x . users . includes ( this . nameDuplicatedPortfolio ) )
72+ x . users . push ( this . nameDuplicatedPortfolio )
73+ return x
74+ } )
75+ . then ( db . post )
76+ . then ( ( x ) => {
77+ console . log ( x )
78+ } )
79+ . catch ( _error ) ;
7780 }
81+
7882 closeToast ( ) {
7983 this . setState ( ( ) => {
8084 return {
0 commit comments