-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from cnpem/updated-schemas
Updated schemas
- Loading branch information
Showing
25 changed files
with
1,419 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use client"; | ||
|
||
import { buttonVariants } from "@sophys-web/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "@sophys-web/ui/dropdown-menu"; | ||
import { api } from "../../trpc/react"; | ||
|
||
export function EnvMenu() { | ||
const apiUtils = api.useUtils(); | ||
|
||
const { | ||
data: status, | ||
isError, | ||
isLoading, | ||
} = api.status.get.useQuery(undefined); | ||
|
||
const { mutate: envUpdate } = api.environment.update.useMutation({ | ||
onSuccess: async () => { | ||
await apiUtils.status.get.invalidate(); | ||
}, | ||
}); | ||
|
||
const { mutate: envOpen } = api.environment.open.useMutation({ | ||
onSuccess: async () => { | ||
await apiUtils.status.get.invalidate(); | ||
}, | ||
}); | ||
|
||
const statusMessage = () => { | ||
if (isLoading) { | ||
return "Loading..."; | ||
} | ||
if (isError) { | ||
return "Error"; | ||
} | ||
return status?.reState || "Unknown"; | ||
}; | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger | ||
className={buttonVariants({ variant: "secondary" })} | ||
disabled={isLoading || isError} | ||
onClick={async () => { | ||
await apiUtils.status.get.invalidate(); | ||
}} | ||
> | ||
Status: {statusMessage()} | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuLabel>Env controls</DropdownMenuLabel> | ||
<DropdownMenuItem | ||
onClick={() => { | ||
envUpdate(); | ||
}} | ||
> | ||
Update | ||
</DropdownMenuItem> | ||
|
||
<DropdownMenuItem | ||
onClick={() => { | ||
envOpen(); | ||
}} | ||
> | ||
Open | ||
</DropdownMenuItem> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuLabel>Full status</DropdownMenuLabel> | ||
<div className="mb-2 p-2"> | ||
{status | ||
? Object.entries(status).map(([key, value]) => ( | ||
<p | ||
className="text-ellipsis text-xs text-muted-foreground" | ||
key={key} | ||
> | ||
{key}: {value?.toString()} | ||
</p> | ||
)) | ||
: null} | ||
</div> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
|
||
import { api } from "../../trpc/react"; | ||
|
||
export const useQueue = () => { | ||
const apiUtils = api.useUtils(); | ||
|
||
const get = api.queue.get.useQuery(undefined, { | ||
refetchInterval: 4000, | ||
}); | ||
|
||
const add = api.queue.item.add.useMutation({ | ||
onSuccess: async () => { | ||
await apiUtils.queue.get.invalidate(); | ||
}, | ||
}); | ||
|
||
const remove = api.queue.item.remove.useMutation({ | ||
onSuccess: async () => { | ||
await apiUtils.queue.get.invalidate(); | ||
}, | ||
}); | ||
|
||
const clear = api.queue.clear.useMutation({ | ||
onSuccess: async () => { | ||
await apiUtils.queue.get.invalidate(); | ||
}, | ||
}); | ||
|
||
return { | ||
get, | ||
add, | ||
remove, | ||
clear, | ||
}; | ||
}; |
Oops, something went wrong.