@@ -16,6 +16,7 @@ import {
1616 onSignedOut ,
1717 startSessionHeartbeat ,
1818} from '../clients/firebase' ;
19+ import { dehydrateProject , rehydrateProject } from '../clients/projectStorage' ;
1920
2021import {
2122 updateProjectSource ,
@@ -83,7 +84,6 @@ class Workspace extends React.Component {
8384 let gistId = null ;
8485 let snapshotKey = null ;
8586 let isExperimental = false ;
86- let rehydratedProject = null ;
8787 if ( location . search ) {
8888 const query = qs . parse ( location . search . slice ( 1 ) ) ;
8989 if ( query . gist ) {
@@ -94,14 +94,7 @@ class Workspace extends React.Component {
9494 }
9595 isExperimental = Object . keys ( query ) . includes ( 'experimental' ) ;
9696 }
97- const dehydrated = localStorage . getItem ( 'popcode-project-state' ) ;
98- if ( dehydrated ) {
99- const rehydrated = JSON . parse ( dehydrated ) ;
100- if ( Date . now ( ) - rehydrated . dehydratedAt <= 5 * 60 * 1000 ) {
101- rehydratedProject = rehydrated . project ;
102- }
103- }
104- localStorage . removeItem ( 'popcode-project-state' ) ;
97+ const rehydratedProject = rehydrateProject ( ) ;
10598 history . replaceState ( { } , '' , location . pathname ) ;
10699 this . props . dispatch ( applicationLoaded ( {
107100 snapshotKey,
@@ -124,11 +117,7 @@ class Workspace extends React.Component {
124117 _handleUnload ( ) {
125118 const { currentProject} = this . props ;
126119 if ( ! isNull ( currentProject ) && ! isPristineProject ( currentProject ) ) {
127- const dehydrated = JSON . stringify ( {
128- dehydratedAt : Date . now ( ) ,
129- project : currentProject ,
130- } ) ;
131- localStorage . setItem ( 'popcode-project-state' , dehydrated ) ;
120+ dehydrateProject ( currentProject ) ;
132121 }
133122 }
134123
0 commit comments