Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to use variables for broadcast selection in actions and feedbacks #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JonFStr
Copy link

@JonFStr JonFStr commented Jul 9, 2024

No description provided.

@cyprient cyprient self-assigned this Jul 9, 2024
@cyprient cyprient self-requested a review July 9, 2024 08:50
@cyprient
Copy link
Collaborator

cyprient commented Jul 9, 2024

Please add unit tests for your feature.

Comment on lines +99 to 120
{
type: 'checkbox',
label: 'Use variables for broadcast selection',
id: 'use_var',
default: false
},
{
type: 'dropdown',
label: 'Broadcast:',
id: 'broadcast_id',
choices: [...broadcastEntries, ...broadcastUnfinishedEntries],
default: defaultBroadcast,
isVisible: (options) => options.use_var == false
},
{
type: 'textinput',
label: 'Broadcast',
id: 'broadcast_vars',
useVariables: true,
tooltip: 'Use unfinished_ followed by a number to dynamically select an unfinished broadcast, or the Video ID for static selection',
isVisible: (options) => options.use_var == true
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is becoming unmanageable. I think you should create a function createBroadcastChoices that takes the varying aspects (like the choices for the broadcast_id), and returns an array with the use_var, broadcast_id and broadcast_vars elements. The function is then called with the correct parameters instead of the three elements:

Suggested change
{
type: 'checkbox',
label: 'Use variables for broadcast selection',
id: 'use_var',
default: false
},
{
type: 'dropdown',
label: 'Broadcast:',
id: 'broadcast_id',
choices: [...broadcastEntries, ...broadcastUnfinishedEntries],
default: defaultBroadcast,
isVisible: (options) => options.use_var == false
},
{
type: 'textinput',
label: 'Broadcast',
id: 'broadcast_vars',
useVariables: true,
tooltip: 'Use unfinished_ followed by a number to dynamically select an unfinished broadcast, or the Video ID for static selection',
isVisible: (options) => options.use_var == true
},
...createBroadcastChoices([...broadcastEntries, ...broadcastUnfinishedEntries]),

Copy link

@astellingwerf astellingwerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be made a lot more DRY. Repeating the same code 15 times is a bad idea.

@@ -16,6 +17,7 @@ export enum FeedbackId {

/**
* Get a list of feedbacks for this module
* @param The companion instance used to

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param The companion instance used to

Comment on lines +252 to +261
if (event.options.use_var) {
if (!event.options.broadcast_vars) return {};
} else {
if (!event.options.broadcast) return {};
}
const id = (
event.options.use_var
? await context.parseVariablesInString(event.options.broadcast_vars as string)
: event.options.broadcast
) as BroadcastID;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, or very similar code, is present in this PR at least three times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants