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

[BUG] Multimedia sent to a GoldenLayout pane with 'replace' update method doesn't replace existing content #3314

Open
nyweryl opened this issue Oct 30, 2023 · 1 comment
Labels
bug An actual error or unwanted behavior. web This issue is website or webclient related.

Comments

@nyweryl
Copy link

nyweryl commented Oct 30, 2023

Describe the bug

When sending multimedia elements to a GoldenLayout webclient pane they always get appended to existing content, even if the update method of the pane is defined as "replace".

To Reproduce

Steps to reproduce the behavior:

  1. Define a new GoldenLayout pane, with the updateMethod of the componentState set to replace, for example:
   type: 'component',
   componentName: 'evennia',
   componentId: 'evennia',
   title: 'Minimap',
   isClosable: false,
   componentState: {
       types: 'minimap',
       updateMethod: 'replace',
   },
}
  1. Create a piece of code that sends a message with multimedia content to that pane, for example:
obj.msg(image=("https://avatars.githubusercontent.com/u/23739149", {"type": "minimap"}))
  1. Make sure that piece fires multiple times.
  2. See the result:
    image

Expected behavior

I expect the existing contents of the pane to be completely replaced by the multimedia content.

Environment, Evennia version, OS etc

     Evennia version: 2.2.0 (rev 8593c7eb41)
     OS: posix
     Python: 3.11.1
     Twisted: 22.10.0
     Django: 4.1.3

Additional context

As a work-around I added a few lines to the multimedia plugin:

let multimedia_plugin = (function () {
    //
    var image = function (args, kwargs) {
        let options = window.options;
        if( !("mm_image" in options) || options["mm_image"] === false ) { return; }

        var mwins = window.plugins["goldenlayout"].routeMessage(args, kwargs);
        mwins.forEach( function (mwin) {
            // Lyrewyn
            // Check the defined updatemethod for the appropiate action.
            let updateMethod = mwin.attr("updateMethod");
            if ( updateMethod === "replace" ) {
                mwin.html("<img src='"+ args[0] +"'/>");    
            } else {
                mwin.append("<img src='"+ args[0] +"'/>");
            }
            //
            mwin.scrollTop(mwin[0].scrollHeight);
        });
    }
@nyweryl nyweryl added bug An actual error or unwanted behavior. needs-triage Yet to be looked at and verified as an a real issue/feature that could be worked on labels Oct 30, 2023
@Griatch Griatch added web This issue is website or webclient related. and removed needs-triage Yet to be looked at and verified as an a real issue/feature that could be worked on labels Nov 26, 2023
@Chetral
Copy link

Chetral commented Apr 18, 2024

Another, easier, work-around is to send an empty message of type "text" with the same tag before the new image (or message you want to show)

obj.msg(text=(' ', {"type": "minimap"}), options=None)

The message type "text" actually reset the goldenlayout component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An actual error or unwanted behavior. web This issue is website or webclient related.
Projects
None yet
Development

No branches or pull requests

3 participants