-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added state for instances (add, edit and delete)
- Loading branch information
Showing
6 changed files
with
254 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
import { atom } from "recoil"; | ||
import { atom, atomFamily, selectorFamily } from "recoil"; | ||
import { Profile } from "./profiles"; | ||
import { recoilPersist } from "recoil-persist"; | ||
|
||
export const instances = atom({ | ||
key: "instancesList", | ||
const { persistAtom } = recoilPersist(); | ||
|
||
export type Instance = { | ||
id: number | undefined; | ||
name: string; | ||
host: string; | ||
description: string; | ||
profile: Profile | undefined; | ||
}; | ||
|
||
export const instanceIds = atom<number[]>({ | ||
key: "instanceIds", | ||
default: [], | ||
effects_UNSTABLE: [persistAtom], | ||
}); | ||
|
||
export const DefaultInstance = { | ||
id: undefined, | ||
name: "", | ||
host: "", | ||
description: "", | ||
profile: undefined, | ||
}; | ||
|
||
export const instances = atomFamily<Instance, number>({ | ||
key: "instance", | ||
default: DefaultInstance, | ||
effects_UNSTABLE: [persistAtom], | ||
}); | ||
|
||
export const intanceFormErrors = atom({ | ||
key: "intanceFormErrors", | ||
default: {} as { [key: string]: string }, | ||
}); | ||
|
||
export const intanceFormFieldErrors = selectorFamily({ | ||
key: "profileFormFieldErrors", | ||
get: | ||
(field: string) => | ||
({ get }) => | ||
get(intanceFormErrors)[field], | ||
}); | ||
|
||
export const instanceFormFields = atom({ | ||
key: "instanceFormFields", | ||
default: DefaultInstance as { [key: string]: any }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.