change paths for cardstack types

This commit is contained in:
bignutty 2025-02-14 21:42:54 +01:00
parent 1afe082d92
commit 17964ce5cb
7 changed files with 81 additions and 38 deletions

View file

@ -1,12 +1,12 @@
module.exports.BUILT_IN_BUTTON_TYPES = Object.freeze({
module.exports.BuiltInButtonTypes = Object.freeze({
NEXT_PAGE: "next",
PREVIOUS_PAGE: "previous"
})
module.exports.DEFAULT_BUTTON_ICON_MAPPINGS = Object.freeze({
[this.BUILT_IN_BUTTON_TYPES.NEXT_PAGE]: "button_chevron_right",
[this.BUILT_IN_BUTTON_TYPES.PREVIOUS_PAGE]: "button_chevron_left"
[this.BuiltInButtonTypes.NEXT_PAGE]: "button_chevron_right",
[this.BuiltInButtonTypes.PREVIOUS_PAGE]: "button_chevron_left"
});
module.exports.STACK_CACHE_KEYS = Object.freeze({
@ -23,7 +23,7 @@ module.exports.STACK_CACHE_KEYS = Object.freeze({
* - `REPLACE_ROOT_STACK` - Replaces the root stack
* - This callback type will also unselect the button
*/
module.exports.RESOLVE_CALLBACK_TYPES = Object.freeze({
module.exports.ResolveCallbackTypes = Object.freeze({
SUBSTACK: 0,
REPLACE_PARENT_CARD: 1,
REPLACE_STACK: 2,

View file

@ -1,8 +1,8 @@
const { DynamicCardStack } = require("./DynamicCardStack");
const { DynamicCardStack } = require("./stack");
module.exports = {
createDynamicCardStack: (context, options)=>{
return new DynamicCardStack(context, options)
},
CARD_STACK_CONSTANTS: require("./Constants"),
CARD_STACK_CONSTANTS: require("./constants"),
}

View file

@ -1,3 +1,5 @@
const {DISCORD_INVITES} = require("#constants");
const { createEmbed, page } = require("#utils/embed");
const { iconAsEmojiObject, icon, link, codeblock } = require("#utils/markdown");
const { editOrReply } = require("#utils/message");
@ -7,8 +9,8 @@ const { Context } = require("detritus-client/lib/command");
const { MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants");
const { Message } = require("detritus-client/lib/structures");
const { ComponentContext, Components, ComponentActionRow} = require("detritus-client/lib/utils");
const {DISCORD_INVITES} = require("#constants");
const {DEFAULT_BUTTON_ICON_MAPPINGS, STACK_CACHE_KEYS, BUILT_IN_BUTTON_TYPES, RESOLVE_CALLBACK_TYPES} = require("./Constants");
const {DEFAULT_BUTTON_ICON_MAPPINGS, STACK_CACHE_KEYS, BuiltInButtonTypes, ResolveCallbackTypes} = require("./constants");
/**
* Stores all active card stacks
@ -442,7 +444,7 @@ class DynamicCardStack {
//this.lastInteraction = Date.now();
// Built-in Buttons
if(Object.values(BUILT_IN_BUTTON_TYPES).includes(ctx.data.customId)){
if(Object.values(BuiltInButtonTypes).includes(ctx.data.customId)){
switch(ctx.data.customId){
case "next":
return ctx.respond({
@ -516,7 +518,7 @@ class DynamicCardStack {
// Compute the active cardstack.
let resolvedNewStack = await this.interactive_components[ctx.data.customId].resolvePage(this);
if(!Object.values(RESOLVE_CALLBACK_TYPES).includes(resolvedNewStack.type))
if(!Object.values(ResolveCallbackTypes).includes(resolvedNewStack.type))
throw new Error(`Invalid Stack Resolve Type (${resolvedNewStack.type})`);
switch(resolvedNewStack.type){
@ -527,7 +529,7 @@ class DynamicCardStack {
* with a new, separate card stack to
* page through.
*/
case RESOLVE_CALLBACK_TYPES.SUBSTACK:
case ResolveCallbackTypes.SUBSTACK:
this.activeCardStack = resolvedNewStack.cards;
this.index = resolvedNewStack.index || 0;
@ -552,7 +554,7 @@ class DynamicCardStack {
* Re-resolves all page state.
* Unselects the button.
*/
case RESOLVE_CALLBACK_TYPES.REPLACE_PARENT_CARD:
case ResolveCallbackTypes.REPLACE_PARENT_CARD:
this.cards[this.rootIndex] = resolvedNewStack.card;
this.activeCardStack = [...this.cards];
this.updatePageState();
@ -568,7 +570,7 @@ class DynamicCardStack {
* Re-resolves all page state.
* Unselects the button.
*/
case RESOLVE_CALLBACK_TYPES.REPLACE_STACK:
case ResolveCallbackTypes.REPLACE_STACK:
this.activeCardStack = resolvedNewStack.cards;
this.updatePageState();
this.index = resolvedNewStack.index || this.rootIndex;