fix: setting up shared state package
This commit is contained in:
parent
e9372adcf4
commit
4bd6ee5014
11 changed files with 309 additions and 3 deletions
3
packages/shared-state/.eslintignore
Normal file
3
packages/shared-state/.eslintignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
build/*
|
||||
dist/*
|
||||
out/*
|
||||
9
packages/shared-state/.eslintrc.js
Normal file
9
packages/shared-state/.eslintrc.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/** @type {import("eslint").Linter.Config} */
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ["@plane/eslint-config/library.js"],
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
project: true,
|
||||
},
|
||||
};
|
||||
5
packages/shared-state/.prettierrc
Normal file
5
packages/shared-state/.prettierrc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
20
packages/shared-state/package.json
Normal file
20
packages/shared-state/package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "@plane/shared-state",
|
||||
"version": "0.24.1",
|
||||
"description": "Shared state shared across multiple apps internally",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"scripts": {
|
||||
"lint": "eslint src --ext .ts,.tsx",
|
||||
"lint:errors": "eslint src --ext .ts,.tsx --quiet"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "^3.22.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@plane/eslint-config": "*",
|
||||
"@types/node": "^22.5.4",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
0
packages/shared-state/src/index.ts
Normal file
0
packages/shared-state/src/index.ts
Normal file
136
packages/shared-state/src/store/user.store.ts
Normal file
136
packages/shared-state/src/store/user.store.ts
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
import { makeObservable, observable } from "mobx";
|
||||
import { IWorkspaceStore } from "./workspace.store";
|
||||
|
||||
export interface IUserStore {
|
||||
user: any;
|
||||
workspaces: Map<string, IWorkspaceStore>;
|
||||
isLoading: boolean;
|
||||
error: any;
|
||||
}
|
||||
|
||||
export class UserStore implements IUserStore {
|
||||
user: any = null;
|
||||
workspaces: Map<string, IWorkspaceStore> = new Map();
|
||||
isLoading: boolean = false;
|
||||
error: any = null;
|
||||
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
user: observable.ref,
|
||||
workspaces: observable,
|
||||
isLoading: observable.ref,
|
||||
error: observable.ref,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// userStore.ts
|
||||
|
||||
// class UserStore {
|
||||
// user: User | null = null;
|
||||
// workspaces: Workspace[] = [];
|
||||
// isLoading = false;
|
||||
// error: string | null = null;
|
||||
// private indexedDBService: IndexedDBService;
|
||||
|
||||
// constructor() {
|
||||
// makeAutoObservable(this);
|
||||
// this.indexedDBService = new IndexedDBService();
|
||||
// this.init();
|
||||
// }
|
||||
|
||||
// private async init() {
|
||||
// try {
|
||||
// await this.indexedDBService.init();
|
||||
// await this.loadWorkspacesFromIndexedDB();
|
||||
// } catch (error) {
|
||||
// runInAction(() => {
|
||||
// this.error = "Failed to initialize store";
|
||||
// console.error("Store initialization error:", error);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// setUser(user: User | null) {
|
||||
// this.user = user;
|
||||
// }
|
||||
|
||||
// async loadWorkspacesFromIndexedDB() {
|
||||
// try {
|
||||
// const workspaces = await this.indexedDBService.getWorkspaces();
|
||||
// runInAction(() => {
|
||||
// this.workspaces = workspaces;
|
||||
// });
|
||||
// } catch (error) {
|
||||
// runInAction(() => {
|
||||
// this.error = "Failed to load workspaces from IndexedDB";
|
||||
// console.error("Load workspaces error:", error);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// async fetchAndSyncWorkspaces() {
|
||||
// this.isLoading = true;
|
||||
// this.error = null;
|
||||
|
||||
// try {
|
||||
// // Simulate API call to fetch workspaces
|
||||
// const response = await fetch("/api/workspaces");
|
||||
// const workspaces = await response.json();
|
||||
|
||||
// // Save to IndexedDB
|
||||
// await this.indexedDBService.saveWorkspaces(workspaces);
|
||||
|
||||
// // Update MobX store
|
||||
// runInAction(() => {
|
||||
// this.workspaces = workspaces;
|
||||
// this.isLoading = false;
|
||||
// });
|
||||
// } catch (error) {
|
||||
// runInAction(() => {
|
||||
// this.error = "Failed to fetch workspaces";
|
||||
// this.isLoading = false;
|
||||
// console.error("Fetch workspaces error:", error);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Additional methods for workspace management
|
||||
// async addWorkspace(workspace: Omit<Workspace, "id" | "createdAt" | "updatedAt">) {
|
||||
// this.isLoading = true;
|
||||
// this.error = null;
|
||||
|
||||
// try {
|
||||
// // Simulate API call to create workspace
|
||||
// const response = await fetch("/api/workspaces", {
|
||||
// method: "POST",
|
||||
// body: JSON.stringify(workspace),
|
||||
// });
|
||||
// const newWorkspace = await response.json();
|
||||
|
||||
// // Update local storage and state
|
||||
// const updatedWorkspaces = [...this.workspaces, newWorkspace];
|
||||
// await this.indexedDBService.saveWorkspaces(updatedWorkspaces);
|
||||
|
||||
// runInAction(() => {
|
||||
// this.workspaces.push(newWorkspace);
|
||||
// this.isLoading = false;
|
||||
// });
|
||||
// } catch (error) {
|
||||
// runInAction(() => {
|
||||
// this.error = "Failed to add workspace";
|
||||
// this.isLoading = false;
|
||||
// console.error("Add workspace error:", error);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// logout() {
|
||||
// this.user = null;
|
||||
// this.workspaces = [];
|
||||
// // Optionally clear IndexedDB data
|
||||
// this.indexedDBService.init().then(() => {
|
||||
// this.indexedDBService.saveWorkspaces([]);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
28
packages/shared-state/src/store/workspace.store.ts
Normal file
28
packages/shared-state/src/store/workspace.store.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { makeObservable, observable } from "mobx";
|
||||
|
||||
export interface IWorkspaceStore {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export class WorkspaceStore implements IWorkspaceStore {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
|
||||
constructor(data: IWorkspaceStore) {
|
||||
makeObservable(this, {
|
||||
id: observable.ref,
|
||||
name: observable.ref,
|
||||
createdAt: observable.ref,
|
||||
updatedAt: observable.ref,
|
||||
});
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.createdAt = data.createdAt;
|
||||
this.updatedAt = data.updatedAt;
|
||||
}
|
||||
}
|
||||
12
packages/shared-state/tsconfig.json
Normal file
12
packages/shared-state/tsconfig.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "@plane/typescript-config/react-library.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react",
|
||||
"lib": ["esnext", "dom"],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["./src"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue