From d47456b9a5410fc326777a49f5b7c27a1fcbe3fd Mon Sep 17 00:00:00 2001 From: Ruthenic Date: Thu, 2 Feb 2023 13:56:18 -0500 Subject: [PATCH] show user stories on their page --- css/index.scss | 2 +- routes/user.tsx | 84 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/css/index.scss b/css/index.scss index 02528b1..14b2f9a 100644 --- a/css/index.scss +++ b/css/index.scss @@ -202,7 +202,7 @@ h3 { div { display: flex; flex-direction: row; - align-items: start; + align-items: center; margin-left: 0.5em; div { flex-direction: column; diff --git a/routes/user.tsx b/routes/user.tsx index d086c5d..6bee7ed 100644 --- a/routes/user.tsx +++ b/routes/user.tsx @@ -1,6 +1,6 @@ import { h } from "../jsx.ts"; -import watt, { watt as originalWatt } from "../wattpad.ts"; -import { User } from "../wattpad.ts"; +import watt, { Story, watt as originalWatt } from "../wattpad.ts"; +import wattpad, { User } from "../wattpad.ts"; import { Context } from "../oak.ts"; import Base from "../templates/Base.tsx"; @@ -9,6 +9,7 @@ import FourOhFour from "./404.tsx"; export default async (params: URLSearchParams, ctx: Context) => { const name = params.get("name"); + const chapterNumber = Number(params.get("page")) ?? 0; if (!name) { throw "deez"; } @@ -16,10 +17,26 @@ export default async (params: URLSearchParams, ctx: Context) => { const user = new User(originalWatt.session, name); try { await user.init(); + await user.updateStories(chapterNumber); } catch { return FourOhFour(undefined, ctx); } + const res: Story[] = []; + + for (let i = 0; i < user.stories.length; i++) { + const rizz = await watt.getStory(user.stories[i].id, false); + res.push( + + +
+

{rizz.name}

+

{rizz.storyJSON.description}

+
+
+ ); + } + return ( { {user.displayName === "" ? undefined : user.username} +
+ Followers: {user.userJSON.numFollowers ?? 0} +
+ Following: {user.userJSON.numFollowing ?? 0} +
+ +

@@ -48,6 +81,53 @@ export default async (params: URLSearchParams, ctx: Context) => {

+ +
+ {res.join("")} + +
); };