-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move servers pages one level higher
- Loading branch information
Showing
8 changed files
with
182 additions
and
179 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
114 changes: 93 additions & 21 deletions
114
...routes/_authenticated/_layout/projects/$projectId/environments/$environmentId/servers.tsx
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,34 +1,106 @@ | ||
import { ErrorComponent } from "@/components/error-component"; | ||
import { ServersListPreview } from "@/domains/project/components/servers/servers-list-preview"; | ||
import * as Layout from "@/domains/project/layouts/servers-layout"; | ||
import { projectServersQueryOptions } from "@/domains/project/queries"; | ||
import { | ||
type ErrorComponentProps, | ||
Outlet, | ||
createFileRoute, | ||
} from "@tanstack/react-router"; | ||
Button, | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
Flex, | ||
WithTooltip, | ||
} from "@rivet-gg/components"; | ||
import { Icon, faPlus, faRefresh } from "@rivet-gg/icons"; | ||
import { useSuspenseInfiniteQuery } from "@tanstack/react-query"; | ||
import { Link, createFileRoute } from "@tanstack/react-router"; | ||
import { zodSearchValidator } from "@tanstack/router-zod-adapter"; | ||
import { z } from "zod"; | ||
|
||
function ServersLayoutErrorComponent(props: ErrorComponentProps) { | ||
const { environmentId, projectId } = Route.useParams(); | ||
return ( | ||
<Layout.Root environmentId={environmentId} projectId={projectId}> | ||
<ErrorComponent {...props} /> | ||
</Layout.Root> | ||
function ProjectServersRoute() { | ||
const { projectId, environmentId } = Route.useParams(); | ||
const { data, refetch, isRefetching } = useSuspenseInfiniteQuery( | ||
projectServersQueryOptions({ projectId, environmentId: environmentId }), | ||
); | ||
} | ||
|
||
function ServersLayoutView() { | ||
const { environmentId, projectId } = Route.useParams(); | ||
const { serverId } = Route.useSearch(); | ||
|
||
return ( | ||
<Layout.Root environmentId={environmentId} projectId={projectId}> | ||
<Outlet /> | ||
</Layout.Root> | ||
<Card w="full" h="full" className="flex flex-col"> | ||
<CardHeader className="border-b "> | ||
<CardTitle className="flex flex-row justify-between items-center"> | ||
Servers | ||
<Flex gap="2"> | ||
<WithTooltip | ||
content="Refresh" | ||
trigger={ | ||
<Button | ||
size="icon" | ||
isLoading={isRefetching} | ||
variant="outline" | ||
onClick={() => refetch()} | ||
> | ||
<Icon icon={faRefresh} /> | ||
</Button> | ||
} | ||
/> | ||
<WithTooltip | ||
content="Create a new server" | ||
trigger={ | ||
<Button | ||
asChild | ||
size="icon" | ||
variant="outline" | ||
onClick={() => refetch()} | ||
> | ||
<Link | ||
to="." | ||
search={{ | ||
modal: "create-server", | ||
}} | ||
> | ||
<Icon icon={faPlus} /> | ||
</Link> | ||
</Button> | ||
} | ||
/> | ||
</Flex> | ||
</CardTitle> | ||
<CardDescription> | ||
Servers are created & destroyed automatically as players connect & | ||
disconnect. | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent className="flex-1 min-h-0 w-full p-0"> | ||
{data.length === 0 ? ( | ||
<div className="flex items-center mx-auto flex-col gap-2 my-10"> | ||
<span>No servers created.</span> | ||
<span className="text-xs"> | ||
Run your project client & connect to start a server. | ||
</span> | ||
</div> | ||
) : ( | ||
<ServersListPreview | ||
projectId={projectId} | ||
environmentId={environmentId} | ||
serverId={serverId} | ||
/> | ||
)} | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
const searchSchema = z.object({ | ||
serverId: z.string().optional(), | ||
}); | ||
|
||
export const Route = createFileRoute( | ||
"/_authenticated/_layout/projects/$projectId/environments/$environmentId/servers", | ||
)({ | ||
component: ServersLayoutView, | ||
errorComponent: ServersLayoutErrorComponent, | ||
pendingComponent: Layout.Root.Skeleton, | ||
validateSearch: zodSearchValidator(searchSchema), | ||
staticData: { | ||
layout: "full", | ||
}, | ||
component: ProjectServersRoute, | ||
pendingComponent: Layout.Content.Skeleton, | ||
}); |
14 changes: 14 additions & 0 deletions
14
...utes/_authenticated/_layout/projects/$projectId/environments/$environmentId/servers/$.tsx
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,14 @@ | ||
import { createFileRoute, redirect } from "@tanstack/react-router"; | ||
|
||
export const Route = createFileRoute( | ||
"/_authenticated/_layout/projects/$projectId/environments/$environmentId/servers/$", | ||
)({ | ||
beforeLoad: ({ params, location }) => { | ||
if (location.href.endsWith("/builds")) { | ||
throw redirect({ | ||
to: "/projects/$projectId/environments/$environmentId/builds", | ||
params, | ||
}); | ||
} | ||
}, | ||
}); |
106 changes: 0 additions & 106 deletions
106
.../_authenticated/_layout/projects/$projectId/environments/$environmentId/servers/index.tsx
This file was deleted.
Oops, something went wrong.