init
This commit is contained in:
commit
451223816b
338 changed files with 9938 additions and 0 deletions
9
src/lib/core/stores/auth.ts
Normal file
9
src/lib/core/stores/auth.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import type { User } from "firebase/auth";
|
||||
import { writable } from "svelte/store";
|
||||
|
||||
// type User = {
|
||||
// uid: string,
|
||||
// email: string,
|
||||
// };
|
||||
|
||||
export const auth = writable<User | null>(null);
|
||||
3
src/lib/core/stores/departments.ts
Normal file
3
src/lib/core/stores/departments.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { writable } from 'svelte/store';
|
||||
|
||||
export const departmentStore = writable<string | undefined>();
|
||||
1
src/lib/core/stores/machineFiles.ts
Normal file
1
src/lib/core/stores/machineFiles.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
/// save files' content
|
||||
4
src/lib/core/stores/machineInfoStore.ts
Normal file
4
src/lib/core/stores/machineInfoStore.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import type { MachineInfo } from '$lib/models/machineInfo.model';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const machineInfoStore = writable<MachineInfo | undefined>();
|
||||
41
src/lib/core/stores/noti.ts
Normal file
41
src/lib/core/stores/noti.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { toast } from 'svelte-sonner';
|
||||
import { get, writable } from 'svelte/store';
|
||||
|
||||
// save notifications to user
|
||||
export const notiStore = writable<string[]>([]);
|
||||
|
||||
export function addNotification(msg: string) {
|
||||
let current = get(notiStore);
|
||||
current.push(msg);
|
||||
notiStore.set(current);
|
||||
}
|
||||
|
||||
export function getNotification() {
|
||||
let current = get(notiStore);
|
||||
let first = current.shift();
|
||||
if (first) {
|
||||
let msg_p = first.split(':');
|
||||
let msg_level_type = msg_p[0];
|
||||
let msg = msg_p[1];
|
||||
|
||||
switch (msg_level_type) {
|
||||
case 'ERR':
|
||||
toast.error('Error', {
|
||||
description: msg
|
||||
});
|
||||
break;
|
||||
case 'WARN':
|
||||
toast.warning('Warning', {
|
||||
description: msg
|
||||
});
|
||||
default:
|
||||
toast(msg);
|
||||
}
|
||||
}
|
||||
|
||||
notiStore.set(current);
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
getNotification();
|
||||
}, 100);
|
||||
4
src/lib/core/stores/permissions.ts
Normal file
4
src/lib/core/stores/permissions.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { writable } from "svelte/store";
|
||||
|
||||
// blocking views by permission of user
|
||||
export const permission = writable<string[]>([]);
|
||||
67
src/lib/core/stores/recipeStore.ts
Normal file
67
src/lib/core/stores/recipeStore.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { writable } from 'svelte/store';
|
||||
import type { RecipeOverview } from '../../../routes/(authed)/recipe/overview/columns';
|
||||
import type { Material } from '$lib/models/material.model';
|
||||
|
||||
export const recipeData = writable<any>(null);
|
||||
export const recipeLoading = writable(false);
|
||||
export const recipeDataError = writable<string | null>(null);
|
||||
export const recipeStreamMeta = writable<{
|
||||
id: string;
|
||||
total_size: number;
|
||||
chunk_size: number;
|
||||
progress: number;
|
||||
} | null>(null);
|
||||
|
||||
// from server
|
||||
export const recipeOverviewData = writable<RecipeOverview[] | null>(null);
|
||||
export const materialData = writable<Material | undefined>();
|
||||
|
||||
// machine recipe
|
||||
export const recipeFromMachine = writable<any>(null);
|
||||
export const recipeFromMachineLoading = writable(false);
|
||||
export const recipeFromMachineError = writable<string | null>(null);
|
||||
|
||||
// NOTE: must not have any nested structures
|
||||
// { recipe: {}, materials: {}, toppings: { groups: {}, lists: {} } }
|
||||
export const recipeFromMachineQuery = writable<any>({});
|
||||
export const materialFromMachineQuery = writable<any>({});
|
||||
|
||||
export const referenceFromPage = writable<string>('');
|
||||
|
||||
let worker: Worker | null = null;
|
||||
let initialized = false;
|
||||
|
||||
export function loadRecipe(url: string) {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
recipeLoading.set(true);
|
||||
|
||||
worker = new Worker(new URL('../../workers/data.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
|
||||
worker.onmessage = (e) => {
|
||||
const { type, payload } = e.data;
|
||||
if (type === 'data') {
|
||||
recipeData.set(payload);
|
||||
recipeLoading.set(false);
|
||||
}
|
||||
|
||||
if (type === 'error') {
|
||||
recipeDataError.set(payload);
|
||||
recipeLoading.set(false);
|
||||
}
|
||||
};
|
||||
|
||||
worker.postMessage({ url });
|
||||
}
|
||||
|
||||
export function getWorker() {
|
||||
if (!worker) {
|
||||
worker = new Worker(new URL('../../workers/data.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
return worker;
|
||||
}
|
||||
3
src/lib/core/stores/sidebar.ts
Normal file
3
src/lib/core/stores/sidebar.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { writable } from 'svelte/store';
|
||||
|
||||
export const sidebarStore = writable<boolean>(true);
|
||||
46
src/lib/core/stores/websocketStore.ts
Normal file
46
src/lib/core/stores/websocketStore.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { browser } from '$app/environment';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { handleIncomingMessages } from '../handlers/messageHandler';
|
||||
import { queue as msgQueue } from '../handlers/ws_messageSender';
|
||||
|
||||
export const socketStore = writable<WebSocket | null>(null, (set) => {
|
||||
if (browser) {
|
||||
console.log('connecting to ', env.PUBLIC_WSS);
|
||||
const socket = new WebSocket(`${env.PUBLIC_WSS}`);
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
set(socket);
|
||||
|
||||
// recover messages on connect, flushing
|
||||
while (get(msgQueue).length) {
|
||||
let queue = get(msgQueue);
|
||||
let current = queue.shift();
|
||||
if (current) {
|
||||
socket.send(current);
|
||||
// set next
|
||||
msgQueue.set(queue);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.addEventListener('message', (event) => {
|
||||
handleIncomingMessages(event.data);
|
||||
});
|
||||
|
||||
socket.addEventListener('close', () => {
|
||||
set(null);
|
||||
});
|
||||
|
||||
socket.addEventListener('error', (e) => {
|
||||
console.log('WebSocket error: ', e);
|
||||
set(null);
|
||||
});
|
||||
|
||||
return () => {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue