Forum Discussion

jaread83's avatar
jaread83
Champion
9 years ago

User menu ajax request

So I have added a couple of custom components to the user menu that slides out when someone clicks their username at the top of the community. The two new components are simply a 'my notifications' and 'private messages' and look like normal links in the menu. For each of these I use the API to get a number for each and if they exist I add those numbers to the menu item.

 

The menu updates the notification and private message counters on the standard items at the top of the menu (the bell and envelope icons) BUT what I really want to do is apply that same logic to my custom components so they also get the numbers updated. Currently, they update when the page loads and gets the information from the API.

 

Is there a way I can update my custom components so that they get the numbers via the ajax request?

8 Replies

  • jaread83 - Yes, you can. Try doing an update on the click, i.e. when the user clicks the link, you send an AJAX and before the slider opens, it gets the updated data.

    Let me know if you need more information. I hope this helps.
  • jaread83's avatar
    jaread83
    Champion
    9 years ago

    Thank VarunGrazitti, thats good to know that there is the ability to do this! Can you provide any kind of sample js code to call the ajax? I am not too sure how to do this in the Lithium platform to be honest. I can add the click function but not sure how to get the data back for the ajax.

    Any help would be greatly appreciated.

  • jaread83's avatar
    jaread83
    Champion
    9 years ago

    Hi KathleenJo,

     

    It's not available to edit via navigating studio but you can get to it via this:

     

    /t5/bizapps/page/tab/community%3Astudio%3Apage-editor?page=UserSlideOutMenu

     

    From here you can rearrange the menu to whatever you want it to be.

     

    I have added two new custom components to it for notifications and private messages with counters but they only appear on page load rather than via AJAX which I have been trying to figure out but can't seem to get it to work.

  • jaread83 - Create an endpoint and use Rest API to get notification count and messages count and create your both links html there(same you have done in custom component).

     

    jQuery get request -

    $("user-menu-class-name").click(function(){
        $.get("endpoint-url", function(data, status){
           $('links-container-class').html(data);
        });
    })

    Replace the html of your links with $.get call response(data).

  • HeyScottyJ's avatar
    HeyScottyJ
    Director
    9 years ago

    jaread83 Hm, using that URL construct to edit the menu redirects me right back to my community's homepage. Is that a version thing? We're running 16.9 here.

     

    Thanks!

     

    ScottyJ

  • jaread83's avatar
    jaread83
    Champion
    9 years ago

    Hi HeyScottyJ, I am also running 16.9 and can access that page in studio just fine from my staging instance:

    /t5/bizapps/page/tab/community%3Astudio%3Apage-editor?page=UserSlideOutMenu

     

  • HeyScottyJ's avatar
    HeyScottyJ
    Director
    9 years ago

    Ermagerd, user error. Was appending to my prod instance URL because I don't drink enough coffee. Sorry, jaread83, and thanks for the awesome pointer! Definitely want to add some things here.

     

    Cheers,

     

    ScottyJ