Adds new campaign form. Adds fronts and thread types
This commit is contained in:
@@ -15,6 +15,8 @@ const CampaignTabs = {
|
||||
secrets: { label: "Secrets", docType: "secret" },
|
||||
npcs: { label: "NPCs", docType: "npc" },
|
||||
locations: { label: "Locations", docType: "location" },
|
||||
threads: { label: "Threads", docType: "thread" },
|
||||
fronts: { label: "Fronts", docType: "front" },
|
||||
} as const;
|
||||
|
||||
const campaignSearchSchema = z.object({
|
||||
@@ -38,7 +40,6 @@ function RouteComponent() {
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [campaign, setCampaign] = useState<Campaign | null>(null);
|
||||
const [sessions, setSessions] = useState<Session[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
@@ -46,54 +47,11 @@ function RouteComponent() {
|
||||
const campaign = await pb
|
||||
.collection("campaigns")
|
||||
.getOne(params.campaignId);
|
||||
// Fetch all documents for this campaign
|
||||
// const sessions = await pb.collection("documents").getFullList({
|
||||
// filter: `campaign = "${params.campaignId}" && type = 'session'`,
|
||||
// sort: "-created",
|
||||
// });
|
||||
// setSessions(sessions as Session[]);
|
||||
setCampaign(campaign as Campaign);
|
||||
setLoading(false);
|
||||
}
|
||||
fetchData();
|
||||
}, [setCampaign, setSessions, setLoading]);
|
||||
|
||||
const createNewSession = useCallback(async () => {
|
||||
if (campaign === null) {
|
||||
return;
|
||||
}
|
||||
// Check for a previous session
|
||||
const prevSession = await pb
|
||||
.collection("documents")
|
||||
.getFirstListItem(`campaign = "${campaign.id}" && type = 'session'`, {
|
||||
sort: "-created",
|
||||
});
|
||||
|
||||
const newSession = await pb.collection("documents").create({
|
||||
campaign: campaign.id,
|
||||
type: "session",
|
||||
data: {
|
||||
strongStart: "",
|
||||
},
|
||||
});
|
||||
|
||||
// If any relations, then copy things over
|
||||
if (prevSession) {
|
||||
const prevRelations = await pb
|
||||
.collection<Relationship>("relationships")
|
||||
.getFullList({
|
||||
filter: `primary = "${prevSession.id}"`,
|
||||
});
|
||||
|
||||
for (const relation of prevRelations) {
|
||||
await pb.collection("relationships").create({
|
||||
primary: newSession.id,
|
||||
type: relation.type,
|
||||
secondary: relation.secondary,
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [campaign]);
|
||||
}, [setCampaign, setLoading]);
|
||||
|
||||
if (loading || campaign === null) {
|
||||
return <Loader />;
|
||||
|
||||
Reference in New Issue
Block a user