Path: blob/master/src/packages/next/components/project/link.tsx
1449 views
/*1Given a project_id, creates a link to that project showing the title.23This does a database call (with caching) to get the title from the4project_id, so won't be rendered instantly.5*/67import { useEffect, useState } from "react";8import A from "components/misc/A";9import editURL from "lib/share/edit-url";10import Loading from "components/share/loading";11import apiPost from "lib/api/post";1213export default function ProjectLink({ project_id }) {14const [title, setTitle] = useState<string>("");15useEffect(() => {16(async () => {17const query = {18projects: { project_id, title: null },19};20try {21const title = (await apiPost("/user-query", { query }))?.query?.projects22?.title;23setTitle(title ? title : project_id);24} catch (_err) {25setTitle(project_id);26}27})();28}, []);29let body;30if (!title) {31body = <Loading style={{ display: "inline-block" }} />;32} else {33body = title;34}35return (36<A href={editURL({ project_id, type: "collaborator" })} external>37{body}38</A>39);40}414243