@@ -10,7 +10,7 @@ import { API, useAppContext } from '../context';
1010import { debounce } from '@solid-primitives/scheduled' ;
1111import { defaultTabs } from '../../src' ;
1212import type { Tab } from 'solid-repl' ;
13- import type { APIRepl , ReplFile } from './home' ;
13+ import type { APIRepl } from './home' ;
1414import { Header } from '../components/header' ;
1515import { compressToURL } from '@amoutonbrady/lz-string' ;
1616
@@ -92,7 +92,7 @@ export const Edit = (props: { horizontal: boolean }) => {
9292 output = {
9393 files : defaultTabs . map ( ( x ) => ( {
9494 name : x . name ,
95- content : x . source . split ( '\n' ) ,
95+ content : x . source ,
9696 } ) ) ,
9797 } as APIRepl ;
9898 localStorage . setItem ( 'scratchpad' , JSON . stringify ( output ) ) ;
@@ -102,21 +102,13 @@ export const Edit = (props: { horizontal: boolean }) => {
102102 } else {
103103 output = await fetch ( `${ API } /repl/${ repl } ` , {
104104 headers : { authorization : context . token ? `Bearer ${ context . token } ` : '' } ,
105- } )
106- . then ( ( r ) => r . json ( ) )
107- . then ( ( r ) => ( {
108- ...r ,
109- files : r . files . map ( ( x : ReplFile ) => ( {
110- name : x . name + ( ( x as any ) . type ? `.${ ( x as any ) . type } ` : '' ) ,
111- content : typeof x . content == 'string' ? ( x . content as string ) . split ( '\n' ) : x . content ,
112- } ) ) ,
113- } ) ) ;
105+ } ) . then ( ( r ) => r . json ( ) ) ;
114106 }
115107
116108 batch ( ( ) => {
117109 setTabs (
118110 output . files . map ( ( x ) => {
119- return { name : x . name , source : x . content . join ( '\n' ) } ;
111+ return { name : x . name , source : x . content } ;
120112 } ) ,
121113 ) ;
122114 setCurrent ( output . files [ 0 ] . name ) ;
@@ -128,29 +120,21 @@ export const Edit = (props: { horizontal: boolean }) => {
128120
129121 const updateRepl = debounce (
130122 ( ) => {
123+ const files = tabs ( ) . map ( ( x ) => ( { name : x . name , content : x . source } ) ) ;
124+
131125 if ( readonly ( ) ) {
132- localStorage . setItem (
133- 'scratchpad' ,
134- JSON . stringify ( {
135- files : tabs ( ) ! . map ( ( x ) => ( {
136- name : x . name ,
137- content : x . source . split ( '\n' ) ,
138- } ) ) ,
139- } ) ,
140- ) ;
126+ localStorage . setItem ( 'scratchpad' , JSON . stringify ( { files } ) ) ;
141127 disableFetch = true ;
142128 navigate ( '/scratchpad' ) ;
143129 return ;
130+ } else if ( scratchpad ( ) ) {
131+ localStorage . setItem ( 'scratchpad' , JSON . stringify ( { files } ) ) ;
144132 }
145133
146134 const repl = resource . latest ;
147135 if ( ! repl ) return ;
148136
149- const files = tabs ( ) . map ( ( x ) => ( { name : x . name , content : x . source . split ( '\n' ) } ) ) ;
150-
151- if ( scratchpad ( ) ) {
152- localStorage . setItem ( 'scratchpad' , JSON . stringify ( { files } ) ) ;
153- } else if ( context . token && context . user ( ) ?. display == params . user ) {
137+ if ( context . token && context . user ( ) ?. display == params . user ) {
154138 fetch ( `${ API } /repl/${ params . repl } ` , {
155139 method : 'PUT' ,
156140 headers : {
0 commit comments