Skip to content

Commit

Permalink
Add Comments and Patreon Campaign OAuth buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
luminamystere committed Sep 6, 2024
1 parent acc7cc3 commit 0f423b9
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 18 deletions.
83 changes: 65 additions & 18 deletions src/Fluff4me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,7 @@ export default class Fluff4me {
await BUTTON_REGISTRY.createChapter.execute("big story 5", "aaaaaaaaaaaaaaaaaaa", "bigstory", "Public");
await BUTTON_REGISTRY.viewWork.execute("big story five chapters", "bigstory");
// await BUTTON_REGISTRY.follow.execute("work", "debut");
await BUTTON_REGISTRY.createWork.execute("tried a new story", "test thing", "anotherstory", "Hiatus", "Public");
await BUTTON_REGISTRY.viewWork.execute("on creation 0 chapters", "anotherstory");
await BUTTON_REGISTRY.createChapter.execute("chapter one", "some chapter data", "anotherstory", "Public");
await BUTTON_REGISTRY.createChapter.execute("chapter two", "some chapter data", "anotherstory", "Private");
await BUTTON_REGISTRY.viewWork.execute("one public one private", "anotherstory");
await BUTTON_REGISTRY.updateChapter.execute("anotherstory", 2, undefined, undefined, "Patreon");
await BUTTON_REGISTRY.viewWork.execute("one public one patreon", "anotherstory");
await BUTTON_REGISTRY.deleteChapter.execute("anotherstory", 2);
await BUTTON_REGISTRY.viewWork.execute("delete second chapter", "anotherstory");
await BUTTON_REGISTRY.deleteChapter.execute("anotherstory", 1);
await BUTTON_REGISTRY.viewWork.execute("delete first chapter", "anotherstory");
await BUTTON_REGISTRY.deleteWork.execute("anotherstory");

},
}));

Expand All @@ -170,12 +159,13 @@ export default class Fluff4me {
name: "Create Profile 3",
async execute () {
await BUTTON_REGISTRY.createAuthor.execute("prolific follower", "ifollowpeople");
await BUTTON_REGISTRY.follow.execute("author", "somanystories");
await BUTTON_REGISTRY.follow.execute("author", "justonestory");
await BUTTON_REGISTRY.follow.execute("work", "debut");
await BUTTON_REGISTRY.follow.execute("work", "sequel");
await BUTTON_REGISTRY.follow.execute("work", "wip");
await BUTTON_REGISTRY.follow.execute("work", "bigstory");
await BUTTON_REGISTRY.createWork.execute("invalid status", "a test", "uwu", "ShouldNotValidate", "ShouldNotBeValidated");
// await BUTTON_REGISTRY.follow.execute("author", "somanystories");
// await BUTTON_REGISTRY.follow.execute("author", "justonestory");
// await BUTTON_REGISTRY.follow.execute("work", "debut");
// await BUTTON_REGISTRY.follow.execute("work", "sequel");
// await BUTTON_REGISTRY.follow.execute("work", "wip");
// await BUTTON_REGISTRY.follow.execute("work", "bigstory");
},
}));

Expand Down Expand Up @@ -379,6 +369,63 @@ export default class Fluff4me {
await BUTTON_REGISTRY.deleteAuthor.execute();
},
}));

const commentsButton = document.createElement("div");
document.body.append(commentsButton);

commentsButton.append(createButton({
name: "Author 2 lots of comments",
async execute () {
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "base comments 1");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "2", "base comments 2");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "3", "base comments 3");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "4", "base comments 4");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "5", "base comments 5");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment", "6");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment 2", "6");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment 3", "11");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment 4", "12");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "base comment index 1");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment 6", "13");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "child comment 7", "11");
await BUTTON_REGISTRY.createCommentChapter.execute("bigstory", "1", "base comment index 1 again");
},
}));

commentsButton.append(createButton({
name: "Author 1 single comment ping",
async execute () {
await BUTTON_REGISTRY.createCommentChapter.execute("debut", "1", "wow you write so many stories @somanystories how do you do it");
await BUTTON_REGISTRY.createCommentChapter.execute("debut", "1", "@somanystories you're so @somanystories amazing");
await BUTTON_REGISTRY.getComment.execute("4");
await BUTTON_REGISTRY.getComment.execute("5");
await BUTTON_REGISTRY.updateCommentChapter.execute("4", "okay done fawning over @somanystories now");
await BUTTON_REGISTRY.getComment.execute("4");
await BUTTON_REGISTRY.deleteCommentChapter.execute("5");
await BUTTON_REGISTRY.getComment.execute("5");
},
}));

commentsButton.append(createButton({
name: "try to delete author 1's comment",
async execute () {
await BUTTON_REGISTRY.deleteCommentChapter.execute("4");
await BUTTON_REGISTRY.getComment.execute("4");
},
}));

const patreonButtons = document.createElement("div");
document.body.append(patreonButtons);

const campaignButtonTest = document.createElement("button");
campaignButtonTest.textContent = "Campaign Test";
patreonButtons.append(campaignButtonTest);
patreonButtons.addEventListener("click", async () => {
await popup(`${Env.API_ORIGIN}auth/patreon/campaign/begin`, 600, 900)
.then(() => true).catch(err => { console.warn(err); return false; });
await Session.refresh();
});

}
}

Expand Down
79 changes: 79 additions & 0 deletions src/dev/ButtonRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Env from "utility/Env";
import popup from "utility/Popup";
import Session from "utility/Session";

export interface IButtonImplementation<ARGS extends any[]> {
Expand Down Expand Up @@ -506,4 +507,82 @@ export const BUTTON_REGISTRY = {
},
},

createCommentChapter: {
name: "Create Comment Chapter",
async execute (vanity: string, index: string, body: string, parent_id?: string) {
await fetch(`${Env.API_ORIGIN}work/${vanity}/chapter/${index}/comment/add`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
body,
parent_id,
}),
});
},
},

updateCommentChapter: {
name: "Update Comment Chapter",
async execute (id: string, comment_body: string) {
await fetch(`${Env.API_ORIGIN}comment/update/chapter`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
comment_id: id,
body: comment_body,
}),
});
},
},

deleteCommentChapter: {
name: "Delete Comment Chapter",
async execute (id: string) {
await fetch(`${Env.API_ORIGIN}comment/remove/chapter`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
comment_id: id,
}),
});
},
},

getComment: {
name: "Get Comment",
async execute (id: string, label?: string) {
const response = await fetch(`${Env.API_ORIGIN}comment/get`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
comment_id: id,
}),
}).then(response => response.json());
console.log(label, response);
},
},

campaignOauth: {
name: "Patreon Campaign OAuth",
async execute (button: HTMLButtonElement) {
await button.addEventListener("click", () => {
popup(`${Env.API_ORIGIN}patreon/campaign/begin`, 600, 900)
.then(() => true).catch(err => { console.warn(err); return false; });
Session.refresh();
});
},
},

} satisfies Record<string, IButtonImplementation<any[]>>;

0 comments on commit 0f423b9

Please sign in to comment.