Skip to content

Commit

Permalink
Merge pull request #37 from beclab/fix/i18n
Browse files Browse the repository at this point in the history
fix: first load page
  • Loading branch information
icebergtsn authored Sep 25, 2024
2 parents 45da3ff + b4876a7 commit 776e6f1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 67 deletions.
93 changes: 45 additions & 48 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<router-view />
<router-view v-if="appStore.pageData" />
</template>

<script lang="ts">
<script lang="ts" setup>
import { useAppStore } from 'src/stores/app';
import { onBeforeMount, onBeforeUnmount } from 'vue';
import { useSocketStore } from 'src/stores/websocketStore';
Expand All @@ -14,53 +14,50 @@ import { supportLanguages } from 'src/i18n';
import { useMenuStore } from 'src/stores/menu';
// import { testSatisfies } from 'src/utils/version';
export default {
setup() {
const appStore = useAppStore();
const websocketStore = useSocketStore();
const userStore = useUserStore();
const menuStore = useMenuStore();
let terminusLanguage = '';
let terminusLanguageInfo: any = document.querySelector(
'meta[name="terminus-language"]'
);
if (terminusLanguageInfo && terminusLanguageInfo.content) {
terminusLanguage = terminusLanguageInfo.content;
} else {
terminusLanguage = navigator.language;
}
console.log(navigator.language);
if (terminusLanguage) {
if (supportLanguages.find((e) => e.value == terminusLanguage)) {
i18n.global.locale.value = terminusLanguage as any;
}
}
onBeforeMount(async () => {
await menuStore.init();
if (!appStore.isPublic) {
// testSatisfies();
websocketStore.start();
userStore.init();
appStore.init();
}
bus.on(BUS_EVENT.APP_BACKEND_ERROR, onErrorMessage);
});
const appStore = useAppStore();
const websocketStore = useSocketStore();
const userStore = useUserStore();
const menuStore = useMenuStore();
let terminusLanguage = '';
let terminusLanguageInfo: any = document.querySelector(
'meta[name="terminus-language"]'
);
if (terminusLanguageInfo && terminusLanguageInfo.content) {
terminusLanguage = terminusLanguageInfo.content;
} else {
terminusLanguage = navigator.language;
}
console.log(navigator.language);
if (terminusLanguage) {
if (supportLanguages.find((e) => e.value == terminusLanguage)) {
i18n.global.locale.value = terminusLanguage as any;
}
}
onBeforeMount(async () => {
await appStore.prefetch();
await menuStore.init();
if (!appStore.isPublic) {
// testSatisfies();
websocketStore.start();
userStore.init();
appStore.init();
}
const onErrorMessage = (failureMessage: string) => {
BtNotify.show({
type: NotifyDefinedType.FAILED,
message: failureMessage
});
};
bus.on(BUS_EVENT.APP_BACKEND_ERROR, onErrorMessage);
});
onBeforeUnmount(() => {
bus.off(BUS_EVENT.APP_BACKEND_ERROR, onErrorMessage);
});
}
const onErrorMessage = (failureMessage: string) => {
BtNotify.show({
type: NotifyDefinedType.FAILED,
message: failureMessage
});
};
onBeforeUnmount(() => {
bus.off(BUS_EVENT.APP_BACKEND_ERROR, onErrorMessage);
});
</script>
19 changes: 15 additions & 4 deletions frontend/src/pages/application/AppListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</page-container>
</template>
<script lang="ts" setup>
import { ref, onBeforeUnmount, onMounted } from 'vue';
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { AppStoreInfo, CATEGORIES_TYPE } from 'src/constants/constants';
import EmptyView from 'components/base/EmptyView.vue';
Expand Down Expand Up @@ -63,9 +63,6 @@ const updateApp = (app: AppStoreInfo) => {
onMounted(async () => {
bus.on(BUS_EVENT.UPDATE_APP_STORE_INFO, updateApp);
if (route.params.categories || route.params.type) {
await fetchData();
}
});
onBeforeUnmount(() => {
Expand Down Expand Up @@ -108,6 +105,20 @@ const fetchData = async () => {
isEmpty.value = applications.value.length === 0;
loading.value = false;
};
watch(
() => appStore.pageData,
async (newValue) => {
if (newValue.length > 0) {
if (route.params.categories || route.params.type) {
await fetchData();
}
}
},
{
immediate: true
}
);
</script>
<style lang="scss" scoped>
.list-page {
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/pages/application/CategoryPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {
AppStoreInfo,
Expand Down Expand Up @@ -195,7 +195,6 @@ const { t } = useI18n();
onMounted(() => {
topTitle.value = `Top App in ${categoryRef.value}`;
latestTitle.value = `Latest App in ${categoryRef.value}`;
fetchData(true);
});
function fetchData(showLoading = false) {
Expand Down Expand Up @@ -241,6 +240,18 @@ function fetchData(showLoading = false) {
});
}
watch(
() => appStore.pageData,
(newValue) => {
if (newValue.length > 0) {
fetchData(true);
}
},
{
immediate: true
}
);
const clickList = (type: string) => {
router.push({
name: TRANSACTION_PAGE.List,
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/pages/application/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { ref, onMounted, watch } from 'vue';
import { useRouter } from 'vue-router';
import {
AppStoreInfo,
Expand Down Expand Up @@ -206,10 +206,6 @@ const pageData = ref();
const appStore = useAppStore();
const { t } = useI18n();
onMounted(() => {
fetchData(true);
});
function fetchData(showLoading = false) {
if (showLoading) {
pageLoading.value = true;
Expand Down Expand Up @@ -254,6 +250,18 @@ function fetchData(showLoading = false) {
});
}
watch(
() => appStore.pageData,
(newValue) => {
if (newValue.length > 0) {
fetchData(true);
}
},
{
immediate: true
}
);
const clickList = (type: string) => {
router.push({
name: TRANSACTION_PAGE.List,
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/pages/recommend/RecommendPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { ref, watch } from 'vue';
import AppStoreBody from 'src/components/base/AppStoreBody.vue';
import MyAppCard from 'src/components/appcard/MyAppCard.vue';
import { AppStoreInfo, CATEGORIES_TYPE } from 'src/constants/constants';
Expand All @@ -87,10 +87,6 @@ const latestLoading = ref(true);
const pageData = ref();
const appStore = useAppStore();
onMounted(() => {
fetchData(true);
});
async function fetchData(showLoading = false) {
if (showLoading) {
pageLoading.value = true;
Expand Down Expand Up @@ -122,6 +118,18 @@ async function fetchData(showLoading = false) {
pageLoading.value = false;
});
}
watch(
() => appStore.pageData,
(newValue) => {
if (newValue.length > 0) {
fetchData(true);
}
},
{
immediate: true
}
);
</script>

<style lang="scss">
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ export const useAppStore = defineStore('app', {
},

async getPageData(category: string): Promise<any> {
if (!this.pageData || this.pageData.length == 0) {
await this.prefetch();
}
switch (category) {
case CATEGORIES_TYPE.LOCAL.ALL:
case CATEGORIES_TYPE.SERVER.Productivity:
Expand Down

0 comments on commit 776e6f1

Please sign in to comment.