Skip to content

Commit e2773e7

Browse files
committed
App: Fix navigating when a widget gets created.
1 parent a87b5c0 commit e2773e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

app/core/src/main/java/co/casterlabs/caffeinated/app/plugins/PluginIntegration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,14 @@ public void unload(@NonNull String ctxId) {
218218

219219
@SneakyThrows
220220
@JavascriptFunction
221-
public void createNewWidget(@NonNull String namespace, @NonNull String name) {
221+
public String createNewWidget(@NonNull String namespace, @NonNull String name) {
222222
WidgetHandle handle = this.plugins.createWidget(namespace, UUID.randomUUID().toString(), name, null);
223223

224224
handle.onSettingsUpdate(new JsonObject());
225225

226226
this.save(handle);
227227

228-
Thread.sleep(10); // Wait a tiny bit before navigating.
229-
CaffeinatedApp.getInstance().getUI().navigate("/widgets/edit?id=" + handle.id);
228+
return handle.id;
230229
}
231230

232231
@SneakyThrows

app/ui/src/routes/(sidebar)/widgets/+page.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
name: creatable.friendlyName,
8686
requiredFeatures: creatable.requiredFeatures,
8787
create: async () => {
88-
Caffeinated.pluginIntegration.createNewWidget(
88+
return await Caffeinated.pluginIntegration.createNewWidget(
8989
creatable.namespace,
9090
`${await t(creatable.friendlyName)} ${await t(
9191
'co.casterlabs.caffeinated.app.page.widgets.create.new'
@@ -225,8 +225,8 @@
225225
icon: 'icon/trash',
226226
text: 'co.casterlabs.caffeinated.app.page.widgets.delete',
227227
color: 'error',
228-
onclick() {
229-
window.Caffeinated.pluginIntegration.deleteWidget(widget.id);
228+
async onclick() {
229+
await window.Caffeinated.pluginIntegration.deleteWidget(widget.id);
230230
refreshWidgetsList();
231231
}
232232
}
@@ -316,9 +316,10 @@
316316
.filter((f) => !supportedFeatures.includes(f)).length == 0}
317317
<button
318318
class="block w-full h-10"
319-
on:click={() => {
319+
on:click={async () => {
320320
if (isSupported) {
321-
widget.create();
321+
let id = await widget.create();
322+
goto(`/$caffeinated-sdk-root$/widgets/edit?id=${id}`);
322323
} else {
323324
showCreationWarningFeaturesModalFor = widget;
324325
}

0 commit comments

Comments
 (0)