Skip to content

Commit

Permalink
Extract button frames in function
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin committed Mar 21, 2024
1 parent 52a6237 commit 898eb0e
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions packages/frames/src/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,41 @@ export class Frame {
tags.push({ name: 'fc:frame:post_url', content: this.postUrl });
}

if (this.buttons) {
this.buttons.forEach((button, index) => {
tags.push({
name: `fc:frame:button:${index + 1}`,
content: button.label,
});

if (button.action) {
tags.push({
name: `fc:frame:button:${index + 1}:action`,
content: button.action,
});
}

if (button.target) {
tags.push({
name: `fc:frame:button:${index + 1}:target`,
content: button.target,
});
}
if (!this.buttons) {
return tags;
}

tags.push(
...this.buttons.flatMap((button, index) =>
Frame.buttonToMetaTag(button, index + 1),
),
);

return tags;
}

private static buttonToMetaTag(
button: FrameButton,
index: number,
): MetaTag[] {
const tags = [
{
name: `fc:frame:button:${index}`,
content: button.label,
},
];

if (button.action) {
tags.push({
name: `fc:frame:button:${index}:action`,
content: button.action,
});
}

if (button.target) {
tags.push({
name: `fc:frame:button:${index}:target`,
content: button.target,
});
}

Expand Down

0 comments on commit 898eb0e

Please sign in to comment.