This commit is contained in:
parent
2df4cc3e3a
commit
199c85a262
|
@ -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>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
{
|
{
|
||||||
() => {
|
() => {
|
||||||
|
|
Loading…
Reference in a new issue