Skip to content

Commit

Permalink
Solved linting error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil2000 committed Sep 17, 2024
1 parent 8068fda commit de6a9f8
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions apps/platform/src/lib/workspace-storage.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,60 @@
import type { Workspace } from '@/types'
import { atom, useAtom } from 'jotai'
import type { Workspace } from '@/types'

const defaultWorkspaceAtom = atom<Workspace | null>(null)
const currentWorkspaceAtom = atom<Workspace | null>(null)

export function setWorkspace(workspaceData: Workspace[]): void {
export const useDefaultWorkspace = (): {
defaultWorkspace: Workspace | null
setDefaultWorkspace: (workspace: Workspace | null) => void
} => {
const [defaultWorkspace, setDefaultWorkspace] = useAtom(defaultWorkspaceAtom)
return { defaultWorkspace, setDefaultWorkspace }
}

export const useCurrentWorkspace = (): {
currentWorkspace: Workspace | null
setCurrentWorkspace: (workspace: Workspace | null) => void
} => {
const [currentWorkspace, setCurrentWorkspace] = useAtom(currentWorkspaceAtom)
return { currentWorkspace, setCurrentWorkspace }
}

export const SetWorkspace = (workspaceData: Workspace[]): void => {
const { setDefaultWorkspace } = useDefaultWorkspace()
const { currentWorkspace, setCurrentWorkspace } = useCurrentWorkspace()

const defaultWorkspace =
workspaceData.find((workspace) => workspace.isDefault) || null

setDefaultWorkspaceAtom(defaultWorkspace)
setDefaultWorkspace(defaultWorkspace)

if (getCurrentWorkspace() === null) {
setCurrentWorkspace(defaultWorkspace!)
if (currentWorkspace === null && defaultWorkspace) {
setCurrentWorkspace(defaultWorkspace)
}
}

export function getCurrentWorkspace(): Workspace | null {
const [currentWorkspace] = useAtom(currentWorkspaceAtom)
export const GetCurrentWorkspace = (): Workspace | null => {
const { currentWorkspace } = useCurrentWorkspace()
return currentWorkspace
}

export function setCurrentWorkspace(workspace: Workspace): void {
setCurrentWorkspaceAtom(workspace)
export const SetCurrentWorkspace = (workspace: Workspace): void => {
const { setCurrentWorkspace } = useCurrentWorkspace()
setCurrentWorkspace(workspace)
}

//Utility functions
export function setDefaultWorkspaceAtom(workspace: Workspace | null): void {
const [, setDefaultWorkspace] = useAtom(defaultWorkspaceAtom)
export const UpdateDefaultWorkspaceAtom = (
workspace: Workspace | null
): void => {
const { setDefaultWorkspace } = useDefaultWorkspace()
setDefaultWorkspace(workspace)
}

export function setCurrentWorkspaceAtom(workspace: Workspace | null): void {
const [, setCurrentWorkspace] = useAtom(currentWorkspaceAtom)
export const UpdateCurrentWorkspaceAtom = (
workspace: Workspace | null
): void => {
const { setCurrentWorkspace } = useCurrentWorkspace()
setCurrentWorkspace(workspace)
}

0 comments on commit de6a9f8

Please sign in to comment.