11import type * as ApiTypes from '@codeimage/api/api-types' ;
2- import { createTrackObserver } from '@codeimage/atomic-state' ;
32import { getAuth0State } from '@codeimage/store/auth/auth0' ;
43import { getRootEditorStore } from '@codeimage/store/editor' ;
54import { getFrameState } from '@codeimage/store/editor/frame' ;
65import { getEditorStore } from '@codeimage/store/editor/index' ;
76import { ProjectEditorPersistedState } from '@codeimage/store/editor/model' ;
87import { getTerminalState } from '@codeimage/store/editor/terminal' ;
8+ import { toast } from '@codeimage/ui' ;
99import { appEnvironment } from '@core/configuration' ;
1010import { createContextProvider } from '@solid-primitives/context' ;
1111import { useNavigate } from '@solidjs/router' ;
1212import {
13+ catchError ,
1314 combineLatest ,
1415 debounceTime ,
1516 EMPTY ,
@@ -30,7 +31,7 @@ import {
3031 Resource ,
3132 untrack ,
3233} from 'solid-js' ;
33- import { reconcile , unwrap } from 'solid-js/store' ;
34+ import { unwrap } from 'solid-js/store' ;
3435import { API } from '../../data-access/api' ;
3536import { useIdb } from '../../hooks/use-indexed-db' ;
3637
@@ -43,7 +44,6 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
4344 const [ activeWorkspace , setActiveWorkspace ] = createSignal <
4445 ApiTypes . GetProjectByIdApi [ 'response' ] | null
4546 > ( ) ;
46- const [ tracked , untrackCallback ] = createTrackObserver ( ) ;
4747 const authState = getAuth0State ( ) ;
4848 const frameStore = getFrameState ( ) ;
4949 const terminalStore = getTerminalState ( ) ;
@@ -155,7 +155,6 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
155155 function initRemoteDbSync ( ) {
156156 const subscription = onChange$
157157 . pipe (
158- filter ( tracked ) ,
159158 debounceTime ( 150 ) ,
160159 filter ( ( ) => authState . loggedIn ( ) ) ,
161160 tap ( ( ) => setRemoteSync ( true ) ) ,
@@ -175,63 +174,15 @@ function createEditorSyncAdapter(props: {snippetId: string}) {
175174 body : dataToSave ,
176175 params : { id : workspace . id } ,
177176 } ) ,
177+ ) . pipe (
178+ catchError ( ( ) => {
179+ toast . error ( 'An error occurred while saving' ) ;
180+ return EMPTY ;
181+ } ) ,
178182 ) ;
179183 } ) ,
180184 )
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 ( ) ;
235186
236187 return onCleanup ( ( ) => {
237188 const workspace = untrack ( activeWorkspace ) ;
0 commit comments