Skip to content

Commit

Permalink
Show toast messages for errors #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Lev Z Király authored and Lev Z Király committed Nov 22, 2023
1 parent cbe454a commit 7dac138
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stores/use-windows-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from "zod";

import type { QueryDescription } from "@/lib/api-client";
import * as arrange from "@/utils/window-arrangement";
import { useToastsStore } from "./use-toasts-store";

interface WindowItemBase {
id: string;
Expand Down Expand Up @@ -108,6 +109,8 @@ export const useWindowsStore = defineStore("windows", () => {
const router = useRouter();
const route = useRoute();

const toasts = useToastsStore();

async function initializeScreen() {
await navigateTo({
path: "/",
Expand All @@ -125,11 +128,16 @@ export const useWindowsStore = defineStore("windows", () => {
try {
windowStates = JSON.parse(route.query.w as string) as Array<WindowState>;
} catch (e) {
toasts.addToast({ title: "Error: JSON parse failed", description: e.message });
await initializeScreen();
return;
}

if (!Array.isArray(windowStates)) {
toasts.addToast({
title: "Error: Window list is not array",
description: "Window list parameter must be an array",
});
await initializeScreen();
return;
}
Expand All @@ -149,6 +157,7 @@ export const useWindowsStore = defineStore("windows", () => {
width: w.width,
});
} catch (e) {
toasts.addToast({ title: "Error: WindowState parse failed", description: e.message });
console.error(e);
}
});
Expand Down

0 comments on commit 7dac138

Please sign in to comment.