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

[WEB-25] Published blog title is name of file in CMS #379

Open
wants to merge 3 commits into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ function FileContainer({ name, id, selectedFile, setSelectedFile }: Props) {
console.log(id);
setSelectedFile(id);
if (selectedFile !== null) {
navigate("/editor/" + selectedFile, {
navigate("/editor/" + selectedFile, {
replace: false,
state: {
filename: name
}
}), [navigate];
filename: name,
},
}),
[navigate];
}
};

Expand Down
90 changes: 57 additions & 33 deletions next/src/pages/blog/[bid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,71 @@ import { BlogHeading } from "../../components/blog/Blog-styled";
import Footer from "../../components/footer/Footer";

const PageContainer = styled.div`
display: flex;
min-height: 100vh;
flex-direction: column;
display: flex;
min-height: 100vh;
flex-direction: column;
`;

const MainContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
min-height: 80vh;
display: flex;
flex-direction: column;
align-items: center;
min-height: 80vh;
`;

const BlogPage: NextPage<{ data: Block[] }> = ({ data }) => {
return (
<PageContainer>
<Navbar
variant={NavbarType.HOMEPAGE}
open={false}
setNavbarOpen={() => {}}
/>{" "}
{/** ignore the styling */}
<MainContainer>
<BlogHeading>Blog Title</BlogHeading>
<Blog blocks={data} />
</MainContainer>
<Footer />
</PageContainer>
);
const BlogPage: NextPage<{ data: Block[]; blogName: string }> = ({
data,
blogName,
}) => {
return (
<PageContainer>
<Navbar
variant={NavbarType.HOMEPAGE}
open={false}
setNavbarOpen={() => {}}
/>{" "}
{/** ignore the styling */}
<MainContainer>
<BlogHeading>{blogName}</BlogHeading>
<Blog blocks={data} />
</MainContainer>
<Footer />
</PageContainer>
);
};

export const getServerSideProps: GetServerSideProps = async ({ params }) => {
const data = await fetch(
`http://backend:8080/api/filesystem/get/published?DocumentID=${
params && params.bid
}`,
{
method: "GET",
}
).then((res) => res.text());

return { props: { data: JSON.parse(data).Contents } };
// get blog data
const data = await fetch(
`http://backend:8080/api/filesystem/get/published?DocumentID=${
params && params.bid
}`,
{
method: "GET",
}
)
.then((res) => res.text())
.then((res) => JSON.parse(res).Contents);

// get blog name
const blogName = await fetch(
`http://backend:8080/api/filesystem/info?EntityID=${
params && params.bid
}`,
{
method: "GET",
}
)
.then((blogInfo) => blogInfo.json())
.then((blogInfo_json) => blogInfo_json.Response.EntityName)
.catch((err) => console.log("ERROR fetching blogInfo: ", err));

return {
props: {
data: data,
blogName: blogName,
},
};
};

export default BlogPage;