const { createEmbed, page } = require("#utils/embed"); const { acknowledge } = require("#utils/interactions"); const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack"); module.exports = { label: "text", name: "test", metadata: { description: 'test.', description_short: 'test', examples: ['test'], category: 'dev', usage: 'test' }, onBefore: context => context.user.isClientOwner, onCancel: ()=>{}, run: async (context, args) => { await acknowledge(context); try{ // This will create a new dynamic card stack new DynamicCardStack(context, { cards: [ createEmbed("default", context, { description: "page 1"}), createEmbed("default", context, { description: "page 2. this has a conditional button."}) ].map((p, index)=>page(p, {}, { key: `t_${index}` })), interactive: { always_active_button: { label: "single sub page", inline: true, visible: true, disableCache: true, resolvePage: ()=>{ return [ createEmbed("success", context, "smiley") ].map((p)=>page(p)) } }, conditional_button: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: (page) => { return (page.getState("key") === "t_1") }, resolvePage: (pg) => { return [ createEmbed("default", context, { description: "this is a conditional sub page"}), createEmbed("default", context, { description: "this is a conditional sub page two"}) ].map((p)=>page(p)); } }, dynamic_button: { // Button Label label: (page) => { return page.getState("key"); }, // Next to pagination or new row inline: false, visible: true, // Renders the loading state card renderLoadingState: (page) => { return createEmbed("default", context, { description: "-# Subpage Loading :)", }) }, resolvePage: async (pg) => { console.log("resolving page") return [ createEmbed("default", context, { description: "this is a dynamic sub page " + Math.random()}), createEmbed("default", context, { description: "this is a dynamic sub page " + Math.random()}), createEmbed("default", context, { description: "this is a dynamic sub page " + Math.random()}), createEmbed("default", context, { description: "this is a dynamic sub page " + Math.random()}) ].map((p)=>page(p)); } }, conditional_button_2: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, conditional_button_3: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, conditional_button_4: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, conditional_button_5: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, conditional_button_6: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, conditional_button_7: { // Button Label label: "Conditional", // Next to pagination or new row inline: false, visible: true, resolvePage: (pg) => {throw "a"} }, } }) }catch(e){ console.log(e) } } };