feat: update ui

This commit is contained in:
2024-11-08 18:53:30 +00:00
parent 887cb64878
commit 334d90e691
32 changed files with 829 additions and 262 deletions
+26
View File
@@ -0,0 +1,26 @@
import { createStore, useStore } from "zustand";
import { persist, createJSONStorage } from "zustand/middleware";
import AsyncStorage from "@react-native-async-storage/async-storage";
type AuthStore = {
token?: string | null;
};
const authStore = createStore(
persist<AuthStore>(
() => ({
token: null,
}),
{
name: "auth",
storage: createJSONStorage(() => AsyncStorage),
}
)
);
export const useAuthStore = () => {
const state = useStore(authStore);
return { ...state, isLoggedIn: state.token != null };
};
export default authStore;
+43
View File
@@ -0,0 +1,43 @@
import { InteractiveSessionProps } from "@/components/containers/interactive-session";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
export type Session = InteractiveSessionProps & { id: string };
type TerminalSessionsStore = {
sessions: Session[];
curSession: number;
push: (session: Session) => void;
remove: (idx: number) => void;
setSession: (idx: number) => void;
};
export const useTermSession = create(
persist<TerminalSessionsStore>(
(set) => ({
sessions: [],
curSession: 0,
push: (session: Session) => {
set((state) => ({
sessions: [
...state.sessions,
{ ...session, id: session.id + "." + Date.now() },
],
curSession: state.sessions.length,
}));
},
remove: (idx: number) => {
set((state) => {
const sessions = [...state.sessions];
sessions.splice(idx, 1);
return { sessions, curSession: Math.min(idx, sessions.length - 1) };
});
},
setSession: (idx: number) => {
set({ curSession: idx });
},
}),
{ name: "term-sessions", storage: createJSONStorage(() => AsyncStorage) }
)
);
+1 -1
View File
@@ -11,7 +11,7 @@ type Store = {
const useThemeStore = create(
persist<Store>(
(set) => ({
theme: "light",
theme: "dark",
setTheme: (theme: "light" | "dark") => {
set({ theme });
},