Makes campaigns load all types of docs and then link to the docs

This commit is contained in:
2025-08-03 12:50:52 -07:00
parent 3310be9e9b
commit 2fbc2c853f
13 changed files with 170 additions and 75 deletions

View File

@@ -29,7 +29,9 @@ const AuthContext = createContext<AuthContextValue | undefined>(undefined);
*/
export function AuthProvider({ children }: { children: ReactNode }) {
const [isLoading, setIsLoading] = useState(false);
const [user, setUser] = useState<AuthRecord | null>(pb.authStore.record);
const [user, setUser] = useState<AuthRecord | null>(
pb.authStore.isValid ? pb.authStore.record : null,
);
const navigate = useNavigate();

View File

@@ -1,6 +1,7 @@
import type {
AnyDocument,
DocumentId,
DocumentType,
Relationship,
RelationshipType,
} from "@/lib/types";
@@ -30,3 +31,13 @@ export const initialState = (): DocumentState =>
({
documents: {},
}) as DocumentState;
export const getAllDocumentsOfType = <T extends DocumentType>(
docType: T,
state: DocumentState,
): (AnyDocument & { type: T })[] =>
Object.values(state.documents).flatMap((docRecord) =>
docRecord.type === "ready" && docRecord.value.doc.type === docType
? [docRecord.value.doc as AnyDocument & { type: T }]
: [],
);