fix buggy logic
All checks were successful
/ test (push) Successful in 13s

This commit is contained in:
Soph :3 2024-07-23 12:30:49 +03:00
parent 2df4cc3e3a
commit 199c85a262
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
2 changed files with 20 additions and 10 deletions

View file

@ -34,7 +34,7 @@ class Main extends Component {
list(metadatas: Metadata[]) { list(metadatas: Metadata[]) {
const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen"); const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen");
console.log("abcd")
return <ul> return <ul>
{metadatas.map((n) => { {metadatas.map((n) => {
return <li> return <li>
@ -48,15 +48,19 @@ class Main extends Component {
})} })}
</ul> </ul>
} }
render(blogPosts: Metadata[]) {
async handleSelfUpdate() {
const blogPosts = await fetchBlogPosts()
this.update(blogPosts)
}
render(blogPosts: Metadata[]) {
const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen"); const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen");
const md = new URLSearchParams(location.search).get("md"); const md = new URLSearchParams(location.search).get("md");
if (blogPosts) { if (blogPosts) {
const found = blogPosts.find(z => z.filename == md); const found = blogPosts.find(z => z.filename == md);
if (found) { if (found) {
console.log(found);
pageOpen[1](found); pageOpen[1](found);
//@ts-expect-error //@ts-expect-error
pageOpen[0] = found; pageOpen[0] = found;
@ -64,20 +68,21 @@ class Main extends Component {
} }
if (pageOpen[0]) { if (pageOpen[0]) {
return <BlogPage metadata={pageOpen[0]}></BlogPage> return <div><BlogPage metadata={pageOpen[0]} updateParent={this.handleSelfUpdate.bind(this)}
></BlogPage></div>
} }
return <> return <div>
<h1> sophie's blog </h1> <h1> sophie's blog </h1>
<div>Scroll to bottom for comments </div>
<a style="font-size:xx-large;" href="/">back to main page?</a>
{() => { {() => {
if (blogPosts) return this.list(blogPosts) if (blogPosts) return this.list(blogPosts)
else return <h3>Loading...</h3> else return <h3>Loading...</h3>
}} }}
<Giscus searchTerm="main"></Giscus> <Giscus searchTerm="main"></Giscus>
</> </div>
} }
} }

View file

@ -9,10 +9,12 @@ const fetchBlogPost = async (metadata: Metadata) => {
export class BlogPage extends Component { export class BlogPage extends Component {
metadata: Metadata; metadata: Metadata;
updateParent: () => void;
constructor(props: { metadata: Metadata }) { constructor(props: { metadata: Metadata, updateParent: () => void }) {
super(props); super(props);
this.metadata = props.metadata; this.metadata = props.metadata;
this.updateParent = props.updateParent;
} }
async didMount() { async didMount() {
@ -26,10 +28,13 @@ export class BlogPage extends Component {
return <> return <>
<h1> sophie's blog </h1> <h1> sophie's blog </h1>
<a href="/blog.html" style="font-size:xx-large;" onClick={() => { <a style="font-size:xx-large;" onClick={() => {
pageOpen[1](undefined); pageOpen[1](undefined);
this.update(); history.replaceState({}, "", location.pathname+"?md=");
this.updateParent();
}}>return back?</a> }}>return back?</a>
<div>Scroll to bottom for comments </div>
{ {
() => { () => {