Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 494f145

Browse files
committed
Improve translated content
1 parent 1c7a5f3 commit 494f145

File tree

5 files changed

+74
-21
lines changed

5 files changed

+74
-21
lines changed

components/layout/Donations.vue

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="fixed right-3 bottom-5 z-50">
2+
<div v-if="info && info.text" class="fixed right-3 bottom-5 z-50">
33
<button
44
@click="onClickButton"
55
class="text-white px-4 w-auto h-10 bg-blue-700 rounded-full hover:bg-blue-800 active:shadow-lg mouse shadow transition ease-in duration-200 focus:outline-none"
@@ -23,7 +23,7 @@
2323
icon="info"
2424
:showCloseButton="true"
2525
:okButtonText="info.confirm"
26-
>{{ settings.bank && info.text }}</t-dialog
26+
>{{ info.text }}</t-dialog
2727
>
2828
</div>
2929
</template>
@@ -36,24 +36,11 @@ export default {
3636
return this.$store.state.settings.donations;
3737
}
3838
},
39-
data() {
39+
data(context) {
4040
return {
41-
info: {}
41+
info: context.$store.state.donations.info,
4242
};
4343
},
44-
async fetch() {
45-
context.app.$storyapi
46-
.get(`cdn/stories/`, {
47-
starts_with: context.localePath('donations'),
48-
version: 'published'
49-
})
50-
.then((donationsRefResponse) => {
51-
const stories = donationsRefResponse.data.stories;
52-
const info = stories[0].content;
53-
54-
this.info = info;
55-
});
56-
},
5744
setup() {
5845
const showDialog = ref();
5946
@@ -63,6 +50,7 @@ export default {
6350
6451
return {
6552
showDialog,
53+
6654
onClickButton
6755
};
6856
}

helpers/common-page.helper.js

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export function loadPageContentFromApi(context, route, starts_with) {
4646
}
4747

4848
export function loadMenuFromApi(context) {
49-
if (context.store.state.menu.items.length !== 0) {
49+
if (
50+
context.store.state.menu.locale === context.i18n.locale &&
51+
context.store.state.menu.items.length !== 0
52+
) {
5053
return Promise.resolve(context.store.state.menu.items);
5154
}
5255

@@ -55,11 +58,12 @@ export function loadMenuFromApi(context) {
5558
starts_with: context.localePath('menu'),
5659
version: 'published'
5760
})
58-
.then((menuRefResponse) => {
59-
const stories = menuRefResponse.data.stories;
61+
.then((response) => {
62+
const stories = response.data.stories;
6063
const logo = stories && stories[0].content.logo;
6164
const items = stories && stories[0].content.items;
6265

66+
context.store.commit('menu/setLocale', context.i18n.locale);
6367
context.store.commit('menu/setMenu', items);
6468
context.store.commit('menu/setLogo', logo.filename);
6569

@@ -82,8 +86,50 @@ export function loadMenuFromApi(context) {
8286
});
8387
}
8488

89+
export function loadDonationsFromApi(context) {
90+
if (
91+
context.store.state.donations.locale === context.i18n.locale &&
92+
context.store.state.donations.info.cta
93+
) {
94+
return Promise.resolve(context.store.state.donations.info);
95+
}
96+
97+
return context.app.$storyapi
98+
.get(`cdn/stories/`, {
99+
starts_with: context.localePath('donations'),
100+
version: 'published'
101+
})
102+
.then((response) => {
103+
const stories = response.data.stories;
104+
const content = stories && stories[0].content;
105+
106+
context.store.commit('donations/setLocale', context.i18n.locale);
107+
context.store.commit('donations/setInfo', content);
108+
109+
return content;
110+
})
111+
.catch((res) => {
112+
if (!res.response) {
113+
console.error(res);
114+
context.error({
115+
statusCode: 404,
116+
message: 'Failed to receive content form api'
117+
});
118+
} else {
119+
console.error(res.response.data);
120+
context.error({
121+
statusCode: res.response.status,
122+
message: res.response.data
123+
});
124+
}
125+
});
126+
}
127+
85128
export function loadPageContent(context, path) {
86-
return loadMenuFromApi(context).then((menu) => {
129+
return Promise.all([
130+
loadMenuFromApi(context),
131+
loadDonationsFromApi(context)
132+
]).then(([menu]) => {
87133
const item = menu.find(
88134
({ link }) => link.url === `${path}/` || link.cached_url === `${path}/`
89135
);

plugins/common-stores.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as donationsStore from '../store/donations';
12
import * as menuStore from '../store/menu';
23

34
export function registerStore(name, store, storeModule) {
@@ -15,4 +16,5 @@ export default async (context) => {
1516
const { store } = context;
1617

1718
registerStore('menu', store, menuStore);
19+
registerStore('donations', store, donationsStore);
1820
};

store/donations.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const state = () => ({
2+
locale: null,
3+
info: {}
4+
});
5+
6+
export const mutations = {
7+
setLocale(state, locale) {
8+
state.locale = locale;
9+
},
10+
setInfo(state, info) {
11+
state.info = info;
12+
}
13+
};

store/menu.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
export const state = () => ({
2+
locale: null,
23
items: [],
34
logo: null
45
});
56

67
export const mutations = {
8+
setLocale(state, locale) {
9+
state.locale = locale;
10+
},
711
setMenu(state, items) {
812
state.items = items;
913
},

0 commit comments

Comments
 (0)