Break apart the planning columns
This commit is contained in:
parent
0b8bea393e
commit
b152cf9c36
11 changed files with 821 additions and 585 deletions
52
ts/store/signal.ts
Normal file
52
ts/store/signal.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { Signal } from "../types";
|
||||
import { SSEManager } from "../SSEManager";
|
||||
import { useUserStore } from "./user";
|
||||
|
||||
export const useSignalStore = defineStore("signal", () => {
|
||||
// State
|
||||
const all = ref<Signal[] | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
|
||||
// Subscription
|
||||
SSEManager.subscribe("*", (e) => {
|
||||
if (e.resource.startsWith("signal")) {
|
||||
fetchAll();
|
||||
}
|
||||
});
|
||||
// Actions
|
||||
async function fetchAll() {
|
||||
const userStore = useUserStore();
|
||||
if (userStore.urls == null) {
|
||||
throw new Error("can't fetch without user URL data");
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append("sort", "-created");
|
||||
//if (typeFilter.value) params.append("type", typeFilter.value);
|
||||
|
||||
const response = await fetch(`${userStore.urls.api.signal}?${params}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
all.value = data.signals;
|
||||
} catch (err) {
|
||||
console.error("Error loading signals:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
all,
|
||||
// Actions
|
||||
fetchAll,
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue