Skip to content

Commit

Permalink
feat: add skeleton loading in my deploypage
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalop1 committed Apr 12, 2024
1 parent f2c7e6d commit 88cbdd6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions web/src/DeployPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function DeployPage() {
const [deploy, setDeploy] = useState<DeployDto | null>(null);
const [server, setServer] = useState<ServerDto | null>(null);
const [services, setServices] = useState<Service[]>([]);
const [loadingNewService, setLoadingNewService] = useState(false);

async function fetchDeployById(id: string) {
const res = await getDeployByIdApi(id);
Expand Down Expand Up @@ -79,11 +80,13 @@ export default function DeployPage() {
<TabsContent value="database-service">
<AddService
deployId={deploy.id}
setLoading={setLoadingNewService}
fetchServiceList={fetchServiceList}
/>
<ServiceListDeploy
deployId={deploy.id}
services={services}
loadingNewService={loadingNewService}
fetchServiceList={fetchServiceList}
/>
</TabsContent>
Expand Down
5 changes: 5 additions & 0 deletions web/src/components/AddServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import { createServiceApi } from "@/services/createServiceApi";

type AddServiceProps = {
deployId: string;
setLoading: (loading: boolean) => void;
fetchServiceList: (deployId: string) => Promise<void>;
};

export default function AddService({
deployId,
fetchServiceList,
setLoading,
}: AddServiceProps) {
const [services, setServices] = useState<Array<ServiceDto>>([]);
const [open, setOpen] = useState(false);
Expand All @@ -46,12 +48,14 @@ export default function AddService({

async function createService(serviceName: string) {
try {
setLoading(true);
setOpen(false);
await createServiceApi(serviceName, deployId);
await fetchServiceList(deployId);
} catch (e) {
console.error(e);
}
setLoading(false);
}

return (
Expand Down Expand Up @@ -81,6 +85,7 @@ export default function AddService({
{services.map((s) => (
<DatabaseCard key={s.name} service={s} onSelect={createService} />
))}
{/* TODO: command item to add new service link to github issue template */}
</CommandGroup>
</CommandList>
</CommandDialog>
Expand Down
18 changes: 16 additions & 2 deletions web/src/components/ServiceListDeploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import {
} from "./ui/dialog";
import { deleteServiceApi } from "@/services/deleteServiceApi";
import { DialogTitle } from "@radix-ui/react-dialog";
import { Skeleton } from "@/components/ui/skeleton";

type ServiceListDeployProps = {
deployId: string;
services: Service[];
loadingNewService: boolean;
fetchServiceList: (deployId: string) => Promise<void>;
};

export default function ServiceListDeploy({
deployId,
services,
loadingNewService,
fetchServiceList,
}: ServiceListDeployProps) {
const [serviceToDelete, setServiceToDelete] = useState<Service | null>(null);
Expand All @@ -38,7 +41,7 @@ export default function ServiceListDeploy({

useEffect(() => {
fetchServiceList(deployId);
}, [deployId, fetchServiceList]);
}, [deployId]);

return (
<div className="flex flex-col">
Expand Down Expand Up @@ -73,7 +76,7 @@ export default function ServiceListDeploy({
</DialogContent>
</Dialog>
{services.map((s) => (
<Card className="flex justify-between p-3">
<Card className="flex justify-between p-3 mb-3 h-24">
<div className="flex flex-col gap-3">
<div className="flex items-center gap-5">
<div className="text-xl font-bold">{s.name}</div>
Expand All @@ -88,6 +91,17 @@ export default function ServiceListDeploy({
</div>
</Card>
))}
{loadingNewService && (
<Card className="flex justify-between p-3 h-24">
<div className="flex flex-col gap-3 w-full">
<div className="flex justify-between">
<Skeleton className="w-44 h-6" />
<Skeleton className="w-24 h-10" />
</div>
<Skeleton className="w-20 h-3" />
</div>
</Card>
)}
</div>
);
}
15 changes: 15 additions & 0 deletions web/src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { cn } from "@/lib/utils"

function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
)
}

export { Skeleton }

0 comments on commit 88cbdd6

Please sign in to comment.