Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flush out support for displaying project on card #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/Board/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ function BoardCard({ data, classes }) {
size="small"
className={classes.chip}
/> */}
{/* <Chip label={data.field_project.id} size="small" /> */}
{/* performance problem until dupe requests can be queued. */}
{/* <ProjectChip id={data.field_project.id} /> */}
</CardActions>
</Card>
);
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/components/Board/ProjectChip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import useProjectInfo from "../../hooks/projectInfo";
import { Chip } from "@material-ui/core";

const ProjectChip = ({ id }) => {
const project = useProjectInfo(id);
if (project) {
return <Chip label={project.title} size="small" />;
} else {
return null;
}
};
export default ProjectChip;
33 changes: 33 additions & 0 deletions frontend/src/hooks/projectInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState, useEffect } from "react";
import { drupalApiFetch } from "../api";

const useProjectInfo = (id) => {
const [project, setProject] = useState(null);
useEffect(() => {
async function doFetch() {
const res = await drupalApiFetch(`/node/${id}.json`);
if (!res.ok) {
setProject(null);
// there was an error, prevent spamming the API.
} else {
const json = await res.json();
if (json.type === "project_module") {
setProject(json);
} else {
setProject(null);
}
}
}
if (id && id !== "") {
if (parseInt(id) === 3060) {
setProject({
title: "Drupal core",
});
} else {
doFetch();
}
}
}, [id]);
return project;
};
export default useProjectInfo;