1
1
import type * as ApiTypes from '@codeimage/api/api-types' ;
2
- import { createTrackObserver } from '@codeimage/atomic-state' ;
3
2
import { getAuth0State } from '@codeimage/store/auth/auth0' ;
4
3
import { getRootEditorStore } from '@codeimage/store/editor' ;
5
4
import { getFrameState } from '@codeimage/store/editor/frame' ;
6
5
import { getEditorStore } from '@codeimage/store/editor/index' ;
7
6
import { ProjectEditorPersistedState } from '@codeimage/store/editor/model' ;
8
7
import { getTerminalState } from '@codeimage/store/editor/terminal' ;
8
+ import { toast } from '@codeimage/ui' ;
9
9
import { appEnvironment } from '@core/configuration' ;
10
10
import { createContextProvider } from '@solid-primitives/context' ;
11
11
import { useNavigate } from '@solidjs/router' ;
12
12
import {
13
+ catchError ,
13
14
combineLatest ,
14
15
debounceTime ,
15
16
EMPTY ,
@@ -30,7 +31,7 @@ import {
30
31
Resource ,
31
32
untrack ,
32
33
} from 'solid-js' ;
33
- import { reconcile , unwrap } from 'solid-js/store' ;
34
+ import { unwrap } from 'solid-js/store' ;
34
35
import { API } from '../../data-access/api' ;
35
36
import { useIdb } from '../../hooks/use-indexed-db' ;
36
37
@@ -43,7 +44,6 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
43
44
const [ activeWorkspace , setActiveWorkspace ] = createSignal <
44
45
ApiTypes . GetProjectByIdApi [ 'response' ] | null
45
46
> ( ) ;
46
- const [ tracked , untrackCallback ] = createTrackObserver ( ) ;
47
47
const authState = getAuth0State ( ) ;
48
48
const frameStore = getFrameState ( ) ;
49
49
const terminalStore = getTerminalState ( ) ;
@@ -155,7 +155,6 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
155
155
function initRemoteDbSync ( ) {
156
156
const subscription = onChange$
157
157
. pipe (
158
- filter ( tracked ) ,
159
158
debounceTime ( 150 ) ,
160
159
filter ( ( ) => authState . loggedIn ( ) ) ,
161
160
tap ( ( ) => setRemoteSync ( true ) ) ,
@@ -175,63 +174,15 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
175
174
body : dataToSave ,
176
175
params : { id : workspace . id } ,
177
176
} ) ,
177
+ ) . pipe (
178
+ catchError ( ( ) => {
179
+ toast . error ( 'An error occurred while saving' ) ;
180
+ return EMPTY ;
181
+ } ) ,
178
182
) ;
179
183
} ) ,
180
184
)
181
- . subscribe ( updatedSnippet => {
182
- untrackCallback ( ( ) => {
183
- const activeEditorIndex = editorStore . state . editors . findIndex (
184
- ( { id} ) => id === editorStore . state . activeEditorId ,
185
- ) ;
186
-
187
- frameStore . setStore ( state => ( {
188
- ...state ,
189
- visible : updatedSnippet . frame . visible ,
190
- opacity : updatedSnippet . frame . opacity ,
191
- radius : updatedSnippet . frame . radius ?? state . radius ,
192
- padding : updatedSnippet . frame . padding ,
193
- background : updatedSnippet . frame . background ?? state . background ,
194
- } ) ) ;
195
- editorStore . setState (
196
- reconcile (
197
- {
198
- activeEditorId :
199
- updatedSnippet . editorTabs [ activeEditorIndex ] . id ??
200
- updatedSnippet . editorTabs [ 0 ] . id ,
201
- options : {
202
- focused : true ,
203
- themeId : updatedSnippet . editorOptions . themeId ,
204
- showLineNumbers : updatedSnippet . editorOptions . showLineNumbers ,
205
- fontId : updatedSnippet . editorOptions . fontId ,
206
- fontWeight : updatedSnippet . editorOptions . fontWeight ,
207
- } ,
208
- editors : updatedSnippet . editorTabs . map ( editor => ( {
209
- code : editor . code ,
210
- id : editor . id ,
211
- tab : {
212
- tabName : editor . tabName ,
213
- } ,
214
- languageId : editor . languageId ,
215
- } ) ) ,
216
- } ,
217
- { merge : true } ,
218
- ) ,
219
- ) ;
220
- terminalStore . setState ( state => ( {
221
- ...state ,
222
- type : updatedSnippet . terminal . type ,
223
- opacity : updatedSnippet . terminal . opacity ,
224
- showWatermark : updatedSnippet . terminal . showWatermark ?? false ,
225
- showHeader : updatedSnippet . terminal . showHeader ,
226
- background : updatedSnippet . terminal . background ?? state . background ,
227
- showGlassReflection : updatedSnippet . terminal . showGlassReflection ,
228
- alternativeTheme : updatedSnippet . terminal . alternativeTheme ,
229
- accentVisible : updatedSnippet . terminal . accentVisible ,
230
- textColor : updatedSnippet . terminal . textColor ?? state . textColor ,
231
- shadow : updatedSnippet . terminal . shadow ,
232
- } ) ) ;
233
- } ) ;
234
- } ) ;
185
+ . subscribe ( ) ;
235
186
236
187
return onCleanup ( ( ) => {
237
188
const workspace = untrack ( activeWorkspace ) ;
0 commit comments