@@ -3,6 +3,8 @@ import './App.scss';
3
3
import Canvas from './canvas/Canvas' ;
4
4
import IntroWindow from './intro/IntroWindow' ;
5
5
6
+ var localStorage = window . localStorage ;
7
+
6
8
class App extends React . Component {
7
9
constructor ( props ) {
8
10
super ( props ) ;
@@ -11,46 +13,101 @@ class App extends React.Component {
11
13
this . setupProof = this . setupProof . bind ( this ) ;
12
14
this . openCanvas = this . openCanvas . bind ( this ) ;
13
15
this . saveProof = this . saveProof . bind ( this ) ;
16
+ this . getRecents = this . getRecents . bind ( this ) ;
14
17
this . introWindow = React . createRef ( ) ;
15
- // this.state = {
16
- // initialCSS: 'initial',
17
- // canvasOpen: false,
18
- // popupOpen: false,
19
- // proof: {
20
- // premises: [],
21
- // conclusion: '',
22
- // steps: []
23
- // }
24
- // };
25
18
this . state = {
26
19
initialCSS : 'initial' ,
27
- canvasOpen : true ,
20
+ canvasOpen : false ,
28
21
popupOpen : false ,
29
- proof : { premises : [ "({Q})(({P}){Q})" ] , conclusion : "{Q}" , steps :[ ] }
22
+ filename : '' ,
23
+ proof : {
24
+ premises : [ ] ,
25
+ conclusion : '' ,
26
+ steps : [ ]
27
+ } ,
28
+ recentDocs : this . getRecents ( )
30
29
} ;
30
+
31
+ console . log ( this . state . recentDocs )
32
+ // this.state = {
33
+ // initialCSS: 'initial',
34
+ // canvasOpen: true,
35
+ // popupOpen: false,
36
+ // proof: {premises: ["({Q})(({P}){Q})"], conclusion: "{Q}", steps:[] }
37
+ // };
38
+
39
+ this . menuItems = [
40
+ {
41
+ title : 'Exit' ,
42
+ func : ( ) => {
43
+ this . setState ( {
44
+ initialCSS : 'initial' ,
45
+ canvasOpen : false ,
46
+ popupOpen : false ,
47
+ filename : '' ,
48
+ proof : {
49
+ premises : [ ] ,
50
+ conclusion : '' ,
51
+ steps : [ ]
52
+ } ,
53
+ recentDocs : this . getRecents ( )
54
+ } )
55
+ }
56
+ } ,
57
+ 'separator' ,
58
+ {
59
+ title : 'Export' ,
60
+ func : ( ) => {
61
+ const element = document . createElement ( "a" ) ;
62
+ const file = new Blob ( [ JSON . stringify ( this . state . proof ) ] , { type : 'text/plain' } ) ;
63
+ element . href = URL . createObjectURL ( file ) ;
64
+ element . download = this . state . filename + ".egprf" ;
65
+ document . body . appendChild ( element ) ;
66
+ element . click ( ) ;
67
+ }
68
+ }
69
+ ]
31
70
}
32
71
33
- saveProof ( proof ) {
34
- this . setState ( { proof : proof } ) ;
72
+ getRecents ( ) {
73
+ let recents = localStorage . getItem ( 'recentDocs' ) ;
74
+ recents = recents ? JSON . parse ( recents ) : { }
75
+ let keys = Object . keys ( recents )
76
+ for ( let i in keys ) {
77
+ recents [ keys [ i ] ] . open = ( ) => {
78
+ this . setState ( {
79
+ filename : keys [ i ] ,
80
+ proof : recents [ keys [ i ] ]
81
+ } ) ;
82
+ this . openCanvas ( ) ;
83
+ }
84
+ }
85
+ return recents ;
86
+ }
87
+
88
+ saveProof ( filename ) {
89
+ let { recentDocs } = this . state ;
90
+ recentDocs [ filename ] = this . state . proof ;
91
+ return ( proof ) => {
92
+ recentDocs [ filename ] = proof ;
93
+ localStorage . setItem ( 'recentDocs' , JSON . stringify ( recentDocs ) ) ;
94
+ }
35
95
}
36
96
37
- setupProof ( premises , conclusion , steps ) {
97
+ setupProof ( filename , proof ) {
38
98
this . setState ( {
39
- proof : {
40
- premises : premises ,
41
- conclusion : conclusion ,
42
- steps : steps
43
- } ,
44
- initialCSS : 'initial whiteBG'
99
+ filename : filename ,
100
+ proof : proof
45
101
} ) ;
46
- this . introWindow . current . animateAway ( ) ;
47
- setTimeout ( this . openCanvas , 1000 ) ;
102
+ this . openCanvas ( ) ;
48
103
}
49
104
50
105
openCanvas ( ) {
51
- this . setState ( {
106
+ this . setState ( { initialCSS : 'initial whiteBG' } ) ;
107
+ this . introWindow . current . animateAway ( ) ;
108
+ setTimeout ( ( ) => this . setState ( {
52
109
canvasOpen : true
53
- } ) ;
110
+ } ) , 1000 ) ;
54
111
}
55
112
56
113
createNewProof ( ) {
@@ -62,7 +119,8 @@ class App extends React.Component {
62
119
return (
63
120
< div className = "App" >
64
121
< Canvas
65
- saveProof = { this . saveProof }
122
+ menuItems = { this . menuItems }
123
+ saveProof = { this . saveProof ( this . state . filename ) }
66
124
proof = { this . state . proof } />
67
125
</ div >
68
126
) ;
@@ -71,6 +129,7 @@ class App extends React.Component {
71
129
< div className = { this . state . initialCSS } >
72
130
< IntroWindow
73
131
ref = { this . introWindow }
132
+ recentDocs = { this . state . recentDocs }
74
133
setupFunc = { this . setupProof } />
75
134
</ div >
76
135
) ;
0 commit comments