Skip to content

Commit 251ed54

Browse files
Merge pull request #101 from Digital-Alchemy-TS/chrisdrackett/issue100
update to make types available on first model
2 parents 7343464 + 45ab4f8 commit 251ed54

5 files changed

Lines changed: 47 additions & 26 deletions

File tree

apps/client/src/components/Editor/init.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
4141
allowSyntheticDefaultImports: true,
4242
esModuleInterop: true,
4343
typeRoots: ["/globals.ts"],
44+
// Optimize worker performance
45+
maxNodeModuleJsDepth: 0, // Don't check node_modules JS files
46+
skipLibCheck: true, // Skip type checking of declaration files
4447
})
4548

4649
// # Configure Prettier
@@ -144,6 +147,13 @@ const unsubscribe = subscribe(store.apiStatus, () => {
144147

145148
ata()(header)
146149

150+
// Create a dummy model to prime the TypeScript worker
151+
// This ensures types are loaded before any editor is mounted
152+
const uri = monaco.Uri.parse("file:///automations/_init.ts")
153+
// Add code that uses the heavy types to force TS worker to load them
154+
const model = monaco.editor.createModel("", "typescript", uri)
155+
model.dispose()
156+
147157
unsubscribe()
148158
}
149159
})
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
import { useSnapshot } from "valtio"
2-
3-
import { Button, Column, Row, Text, TextInput } from "@code-glue/paradigm"
1+
import { Button, ButtonRow, Row, Text, TextInput } from "@code-glue/paradigm"
2+
import { Header } from "@/components/Header"
43
import { useCurrentAutomation } from "@/hooks/useAutomation"
5-
import { store } from "@/store"
4+
import { useRouter } from "@/hooks/useRouter"
65

7-
export const Header = () => {
6+
export const AutomationHeader = () => {
87
const { automation, automationSnapshot, saveCurrentAutomation } =
98
useCurrentAutomation()
10-
const { isBodyEdited, newAutomationTitle } = useSnapshot(store.state)
9+
const [, navigateTo] = useRouter()
1110

1211
return (
13-
<Column
14-
borderBottomColor="$borderColor"
15-
borderBottomWidth="$size.stroke"
16-
noShrink
17-
>
12+
<Header>
1813
<Row mx={12}>
1914
<Text>Name:</Text>
2015
<TextInput
2116
onChangeText={(title) => {
2217
if (automation) {
2318
automation.update({ title })
24-
} else {
25-
store.state.newAutomationTitle = title
2619
}
2720
}}
28-
value={automation ? automationSnapshot.title : newAutomationTitle}
21+
value={automation ? automationSnapshot.title : ""}
2922
/>
3023
</Row>
3124
<Row>
3225
<Text>Status:</Text>
33-
<Text>{isBodyEdited ? "Edited" : "Unedited"}</Text>
34-
<Button label="Save" onPress={saveCurrentAutomation} />
26+
<Text>{automation?._isEdited ? "Edited" : "Unedited"}</Text>
27+
<ButtonRow>
28+
<Button label="Save" isRaised onPress={saveCurrentAutomation} />
29+
<Button
30+
label="Delete"
31+
isRaised
32+
isNegative
33+
onPress={() => {
34+
automation?.delete()
35+
navigateTo("home")
36+
}}
37+
/>
38+
</ButtonRow>
3539
</Row>
36-
</Column>
40+
</Header>
3741
)
3842
}

apps/client/src/pages/AutomationDetail/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Column, Layout } from "@code-glue/paradigm"
44
import { Editor } from "@/components/Editor"
55
import { useCurrentAutomation } from "@/hooks/useAutomation"
66
import { Footer } from "./Footer"
7-
import { Header } from "./Header"
7+
import { AutomationHeader } from "./Header"
88

99
export const AutomationDetail = () => {
1010
const { saveCurrentAutomation } = useCurrentAutomation()
@@ -23,7 +23,7 @@ export const AutomationDetail = () => {
2323
<Layout.VerticalSplit
2424
top={
2525
<Column grow>
26-
<Header />
26+
<AutomationHeader />
2727
<Editor />
2828
</Column>
2929
}

apps/client/src/store/automation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ const automationFactory = createFactory<AutomationType, Record<string, never>>(
136136
console.error("client -> server push error", error)
137137
})
138138
},
139+
async delete() {
140+
await fetch(`${baseUrl}/api/v1/automation/${this.id}`, {
141+
method: "DELETE",
142+
})
143+
.then((response) => {
144+
if (!response.ok) {
145+
throw new Error(`Failed to delete automation with id ${this.id}`)
146+
}
147+
automationStore.delete(this.id)
148+
})
149+
.catch((error) => {
150+
console.error("client -> server delete error", error)
151+
})
152+
},
139153
})
140154
.actions({
141155
update(updates: AutomationUpdateOptions) {

apps/client/src/store/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
} from "@code-glue/server/utils/index.mts"
1313
import type { Monaco } from "@monaco-editor/react"
1414
import type { editor } from "monaco-editor"
15-
import type { SectionIds } from "@/config"
1615

1716
export const store = proxy({
1817
isReady: false,
@@ -43,12 +42,6 @@ export const store = proxy({
4342
allowedATAPackages: [] as string[],
4443
},
4544
},
46-
/**
47-
* UI State
48-
*/
49-
state: {
50-
currentNavSection: null as SectionIds | null,
51-
},
5245
/**
5346
* API Update/Connection Status
5447
*/

0 commit comments

Comments
 (0)