Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 8, 2023
1 parent dec555f commit 8ef936d
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/classes/forums/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,37 @@ class Post {
time: Date;
};

constructor(session: Session, id: number, data?: {
content: string;
parsableContent: HTMLElement;
author: string;
time: Date;
}) {
constructor(
session: Session,
id: number,
data?: {
content: string;
parsableContent: HTMLElement;
author: string;
time: Date;
}
) {
this.id = id;
this.session = session;
if (data) this.data = data;
}

async setData() {
const request = await fetch(`https://scratch.mit.edu/discuss/m/post/${this.id}`);
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
const request = await fetch(
`https://scratch.mit.edu/discuss/m/post/${this.id}`
);
if (!request.ok)
throw Error(`Request failed with status ${request.status}`);
const dom = parse(await request.text());
const postEl = dom.getElementById(`post-${this.id}`);
this.data = {
parsableContent: postEl.querySelector(".post-content")!,
content: postEl.querySelector(".post-content")!.text,
author: postEl
.getElementsByTagName("header")[0]
.getElementsByTagName("h1")[0].text,
time: new Date(
postEl.querySelector("time")!.getAttribute("datetime")!
),
}
.getElementsByTagName("header")[0]
.getElementsByTagName("h1")[0].text,
time: new Date(postEl.querySelector("time")!.getAttribute("datetime")!)
};
}

/**
Expand Down

0 comments on commit 8ef936d

Please sign in to comment.