feat: added a twist
This commit is contained in:
78
frontend/src/stores/editorStore.ts
Normal file
78
frontend/src/stores/editorStore.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
export interface PageMeta {
|
||||
name: string;
|
||||
title: string | null;
|
||||
published: boolean;
|
||||
has_source: boolean;
|
||||
last_modified: number | null;
|
||||
size: number | null;
|
||||
}
|
||||
|
||||
interface EditorStore {
|
||||
// Source
|
||||
ufSource: string;
|
||||
isDirty: boolean;
|
||||
currentPage: PageMeta | null;
|
||||
|
||||
// Compiled output
|
||||
compiledAscii: string;
|
||||
compiledMicron: string;
|
||||
compileWarnings: string[];
|
||||
isCompiling: boolean;
|
||||
compileError: string | null;
|
||||
|
||||
// Preview
|
||||
previewMode: "ascii" | "micron" | "raw";
|
||||
|
||||
// Actions
|
||||
setSource: (s: string) => void;
|
||||
setCurrentPage: (p: PageMeta | null) => void;
|
||||
setDirty: (v: boolean) => void;
|
||||
setCompileResult: (ascii: string, micron: string, warnings: string[]) => void;
|
||||
setCompiling: (v: boolean) => void;
|
||||
setCompileError: (e: string | null) => void;
|
||||
setPreviewMode: (mode: "ascii" | "micron" | "raw") => void;
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
export const useEditorStore = create<EditorStore>((set) => ({
|
||||
ufSource: "",
|
||||
isDirty: false,
|
||||
currentPage: null,
|
||||
|
||||
compiledAscii: "",
|
||||
compiledMicron: "",
|
||||
compileWarnings: [],
|
||||
isCompiling: false,
|
||||
compileError: null,
|
||||
|
||||
previewMode: "ascii",
|
||||
|
||||
setSource: (s) => set({ ufSource: s, isDirty: true }),
|
||||
setCurrentPage: (p) => set({ currentPage: p }),
|
||||
setDirty: (v) => set({ isDirty: v }),
|
||||
setCompileResult: (ascii, micron, warnings) =>
|
||||
set({
|
||||
compiledAscii: ascii,
|
||||
compiledMicron: micron,
|
||||
compileWarnings: warnings,
|
||||
isCompiling: false,
|
||||
compileError: null,
|
||||
}),
|
||||
setCompiling: (v) => set({ isCompiling: v }),
|
||||
setCompileError: (e) => set({ compileError: e, isCompiling: false }),
|
||||
setPreviewMode: (mode) => set({ previewMode: mode }),
|
||||
reset: () =>
|
||||
set({
|
||||
ufSource: "",
|
||||
isDirty: false,
|
||||
currentPage: null,
|
||||
compiledAscii: "",
|
||||
compiledMicron: "",
|
||||
compileWarnings: [],
|
||||
isCompiling: false,
|
||||
compileError: null,
|
||||
previewMode: "ascii",
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user