mlem icon indicating copy to clipboard operation
mlem copied to clipboard

[2.0] Re-implement `InteractionBarView`

Open Sjmarf opened this issue 10 months ago • 0 comments

This should tie into the Action system I implemented in #999. However, not all interaction bar widgets can be represented with actions - the info stack and upvote/downvote counters, for example. Therefore, we'll need some sort of enum to represent widgets, which InteractionBarView could accept an array of. Something roughly like this:

enum InteractionBarWidget {
    case scoreCount(any Interactable1Providing)
    case upvoteCount(any Interactable1Providing)
    case downvoteCount(any Interactable1Providing)
    case infoStack([InfoStackWidget]) // InfoStackWidget is an unimplemented enum
    case action(any Action)
}

If we didn't want to use any Interactable1Providing as arguments of the enum directly, we could instead accept a Counter struct which would be defined roughly like so:

struct Counter {
    let value: Int
    let leadingAction: (any Action)?
    let trailingAction: (any Action)?
}

With InteractionBarWidget looking something like:

enum InteractionBarWidget {
    case infoStack([InfoStackWidget])
    case counter(Counter)
    case action(any Action)
}

Models could be responsible for creating their own Counter objects in computed properties called scoreCounter etc, in the same way that they instantiate their own Action objects.

Sjmarf avatar Apr 21 '24 20:04 Sjmarf