Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: first load page #37

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading