Hey all. Newbie here. I've tried searching and tried ChatGPT but I can't figure this out.
I've managed to get an extension set up and integrated. On loading my flarum index page, it calls an API and presents a "loading" text on the UI. When the API returns successfully it is not updating the UI. If I browse to a new page, the UI then loads correctly.
I am seeing that m.request(...) and m.redraw() are not redrawing as I expect.
I was extending the DiscussionList.prototype 'view'. I found that the DiscussionList has special redraw logic. As a test, I switched my extension to the IndexPage but it's still not refreshing.
Any help, pointers or thoughts appreciated! Code below:
import { extend } from 'flarum/extend';
import IndexPage from 'flarum/components/IndexPage';
import m from 'mithril';
app.initializers.add('myExtension-extension', () => {
extend(IndexPage.prototype, 'view', function (vdom) {
// Initialize state
let myValue = "-";
let isLoading = true;
// Fetch upvote data from your API
m.request({
method: 'GET',
url: app.forum.attribute('apiUrl') + '/myvalues/data'
}).then(result => {
myValue = result.data.attributes.myValue;
isLoading = false;
m.redraw();
}).catch(err => {
myValue = 0;
isLoading = false;
m.redraw();
});
// Render logic
if (isLoading) {
vdom.children.unshift(m('div', '...Loading...'));
} else {
.....
}