Reload the page content in the panel

In my translations plugin I added a revert button to reset the entire translation of a page back to the content of the default language.

Reverting the content in the corresponding .txt file works, but the panel still shows the old content, because the panel page is not reloaded.

I found this code snippet in Kirby core …

this.$store.dispatch("form/revert", this.id);

… which is used by the default revert button after changes have been made by an author. But I’m pretty sure that this.$store is the wrong place for me, because my changes have been made in the textfile and not in the panel (without saving).

This is where I save the data to the textfile and this is the post request from within the panel.

Any ideas how to update the fields and read all the stored data from the textfile again?

Not sure, but does this event reload the form also?

this.$events.$emit("model.update");

Thanks for the reply.

Unfortunately not. I already tried that – but forgot to mention it, sorry.

Sorry for the ping @sylvainjule @bnomei @timoetting @distantnative but I know that you are some of the most experienced panel devs :wink:

Any ideas?

Hey @flokosiol,

I do not think that this.$store is the wrong place for you. I didn’t use it inside a Kirby plugin yet, but this is generally the way to got if you want to manipulate the global state in a vuex (vue + global state handling) context. If it works, it looks fine to me.

https://vuex.vuejs.org/guide/actions.html#dispatching-actions-in-components says " You can dispatch actions in components with this.$store.dispatch('xxx'), or use the mapActions helper which maps component methods to store.dispatch calls (requires root store injection)".

The mapActions approach makes the code a bit cleaner but also adds another layer of abstraction to it, which isn’t everybody’s taste.

You might have a look at the PageView.vue component, whenever the language is changed the page calls a fetch() method. That’s probably the one you want to trigger. But I’m not sure if there’s a non-hacky way (that’d be, for example, mimicking a language change) to reach it.

Thanks for your replies and ideas – much appreciated!

I don’t think there is a good way at the moment. We should introduce a new event that can be emitted via this.$event.$emit() and then triggers the page to be reloaded. Could you please open an issue? Maybe we can get it into 3.1 still.

2 Likes

Thanks @distantnative for the info. Issue is opened: https://github.com/getkirby/kirby/issues/1534

1 Like