Fixes type errors, cleans up code
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { pb } from "@/lib/pocketbase";
|
|
||||||
import { useAuth } from "@/context/auth/AuthContext";
|
import { useAuth } from "@/context/auth/AuthContext";
|
||||||
|
import { pb } from "@/lib/pocketbase";
|
||||||
import type { Campaign } from "@/lib/types";
|
import type { Campaign } from "@/lib/types";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button and form for creating a new campaign. Handles UI state and creation logic.
|
* Button and form for creating a new campaign. Handles UI state and creation logic.
|
||||||
*/
|
*/
|
||||||
export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Campaign) => void }) {
|
export function CreateCampaignButton({
|
||||||
|
onCreated,
|
||||||
|
}: {
|
||||||
|
onCreated?: (campaign: Campaign) => void;
|
||||||
|
}) {
|
||||||
const [creating, setCreating] = useState(false);
|
const [creating, setCreating] = useState(false);
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -29,7 +33,7 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
|
|||||||
});
|
});
|
||||||
setName("");
|
setName("");
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
if (onCreated) onCreated({ id: record.id, name: record.name });
|
if (onCreated) onCreated(record as Campaign);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setError(e?.message || "Failed to create campaign.");
|
setError(e?.message || "Failed to create campaign.");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -55,7 +59,7 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
|
|||||||
className="px-3 py-2 rounded bg-slate-800 text-slate-100 border border-slate-700 focus:outline-none focus:ring-2 focus:ring-violet-500"
|
className="px-3 py-2 rounded bg-slate-800 text-slate-100 border border-slate-700 focus:outline-none focus:ring-2 focus:ring-violet-500"
|
||||||
placeholder="Campaign name"
|
placeholder="Campaign name"
|
||||||
value={name}
|
value={name}
|
||||||
onChange={e => setName(e.target.value)}
|
onChange={(e) => setName(e.target.value)}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
@@ -68,7 +72,11 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="px-2 py-2 rounded text-slate-400 hover:text-red-400"
|
className="px-2 py-2 rounded text-slate-400 hover:text-red-400"
|
||||||
onClick={() => { setCreating(false); setName(""); setError(null); }}
|
onClick={() => {
|
||||||
|
setCreating(false);
|
||||||
|
setName("");
|
||||||
|
setError(null);
|
||||||
|
}}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
aria-label="Cancel"
|
aria-label="Cancel"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -26,16 +26,6 @@ function RootHeader() {
|
|||||||
>
|
>
|
||||||
Campaigns
|
Campaigns
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
|
||||||
to="/sessions"
|
|
||||||
className="no-underline text-slate-200 hover:text-violet-400 transition-colors font-medium border-b-2 border-transparent pb-1"
|
|
||||||
activeProps={{
|
|
||||||
className:
|
|
||||||
"no-underline text-violet-400 border-violet-400 border-b-2 pb-1",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Sessions
|
|
||||||
</Link>
|
|
||||||
<Link
|
<Link
|
||||||
to="/about"
|
to="/about"
|
||||||
className="no-underline text-slate-200 hover:text-violet-400 transition-colors font-medium border-b-2 border-transparent pb-1"
|
className="no-underline text-slate-200 hover:text-violet-400 transition-colors font-medium border-b-2 border-transparent pb-1"
|
||||||
|
|||||||
@@ -89,7 +89,9 @@ function RouteComponent() {
|
|||||||
|
|
||||||
async function handleToggleDiscovered(secret: Secret, checked: boolean) {
|
async function handleToggleDiscovered(secret: Secret, checked: boolean) {
|
||||||
// 1. Update the discovered field in the secret document
|
// 1. Update the discovered field in the secret document
|
||||||
await pb.collection("documents").update(secret.id, {
|
const updatedSecret: Secret = await pb
|
||||||
|
.collection("documents")
|
||||||
|
.update(secret.id, {
|
||||||
data: {
|
data: {
|
||||||
...secret.data,
|
...secret.data,
|
||||||
secret: {
|
secret: {
|
||||||
@@ -115,17 +117,7 @@ function RouteComponent() {
|
|||||||
}
|
}
|
||||||
// 4. Update local state
|
// 4. Update local state
|
||||||
setSecretList(
|
setSecretList(
|
||||||
secretList.map((s: any) =>
|
secretList.map((s: any) => (s.id === secret.id ? updatedSecret : s)),
|
||||||
s.id === secret.id
|
|
||||||
? {
|
|
||||||
...s,
|
|
||||||
data: {
|
|
||||||
...s.data,
|
|
||||||
secret: { ...s.data.secret, discovered: checked },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: s,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user