mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
style(onboarding): replace button opacity flash with specific spinner animation on db select
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useOnboarding } from "@onboardjs/react";
|
import { useOnboarding } from "@onboardjs/react";
|
||||||
import { Check, Database } from "lucide-react";
|
import { Check, Database, Loader2 } from "lucide-react";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
@@ -29,15 +29,20 @@ export const StepProjectCreate = () => {
|
|||||||
const [databaseIds, setDatabaseIds] = useState<string[]>(
|
const [databaseIds, setDatabaseIds] = useState<string[]>(
|
||||||
existingProject?.databaseIds ?? [],
|
existingProject?.databaseIds ?? [],
|
||||||
);
|
);
|
||||||
|
const [loadingDbId, setLoadingDbId] = useState<string | null>(null);
|
||||||
|
|
||||||
const mutation = useCreateProject();
|
const mutation = useCreateProject();
|
||||||
|
|
||||||
const toggleDb = (id: string) => {
|
const toggleDb = (id: string) => {
|
||||||
|
setLoadingDbId(id);
|
||||||
const newDbIds = databaseIds.includes(id)
|
const newDbIds = databaseIds.includes(id)
|
||||||
? databaseIds.filter((v) => v !== id)
|
? databaseIds.filter((v) => v !== id)
|
||||||
: [...databaseIds, id];
|
: [...databaseIds, id];
|
||||||
setDatabaseIds(newDbIds);
|
setDatabaseIds(newDbIds);
|
||||||
mutation.mutate({ name: name || "My project", description, databaseIds: newDbIds });
|
mutation.mutate(
|
||||||
|
{ name: name || "My project", description, databaseIds: newDbIds },
|
||||||
|
{ onSettled: () => setLoadingDbId(null) }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -74,17 +79,19 @@ export const StepProjectCreate = () => {
|
|||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
{databases.map((db) => {
|
{databases.map((db) => {
|
||||||
const isSelected = databaseIds.includes(db.id);
|
const isSelected = databaseIds.includes(db.id);
|
||||||
|
const isCurrentLoading = loadingDbId === db.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={db.id}
|
key={db.id}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={mutation.isPending}
|
disabled={mutation.isPending}
|
||||||
onClick={() => toggleDb(db.id)}
|
onClick={() => toggleDb(db.id)}
|
||||||
className={`flex items-center gap-3 rounded-lg border p-3 text-sm transition-colors text-left ${
|
className={`flex items-center gap-3 rounded-lg border p-3 text-sm transition-all text-left ${
|
||||||
isSelected
|
isSelected
|
||||||
? "border-primary/20 bg-primary/10 text-primary"
|
? "border-primary/20 bg-primary/10 text-primary"
|
||||||
: "border-border hover:bg-accent/50 hover:border-primary/20"
|
: "border-border hover:bg-accent/50 hover:border-primary/20"
|
||||||
} ${mutation.isPending ? "opacity-50 cursor-not-allowed" : ""}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="size-9 rounded-md border bg-muted/50 shadow-sm flex items-center justify-center shrink-0">
|
<div className="size-9 rounded-md border bg-muted/50 shadow-sm flex items-center justify-center shrink-0">
|
||||||
<Database className="size-4 text-muted-foreground" />
|
<Database className="size-4 text-muted-foreground" />
|
||||||
@@ -95,14 +102,18 @@ export const StepProjectCreate = () => {
|
|||||||
{db.engine}
|
{db.engine}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{isSelected && (
|
{isCurrentLoading ? (
|
||||||
|
<div className="size-5 rounded-full flex items-center justify-center ml-auto">
|
||||||
|
<Loader2 className="size-4 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
) : isSelected ? (
|
||||||
<div className="size-5 rounded-full bg-primary flex items-center justify-center ml-auto">
|
<div className="size-5 rounded-full bg-primary flex items-center justify-center ml-auto">
|
||||||
<Check
|
<Check
|
||||||
className="size-3 text-primary-foreground"
|
className="size-3 text-primary-foreground"
|
||||||
strokeWidth={3}
|
strokeWidth={3}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user