Skip to content

Commit

Permalink
blog: use bus + PageTransition[Start|End] to indicate page loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nkonev committed Dec 27, 2024
1 parent 7d5d51e commit 333b94e
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 64 deletions.
2 changes: 2 additions & 0 deletions public/common/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export default emitter
export const SEARCH_STRING_CHANGED = "searchStringChanged";

export const PLAYER_MODAL = "playerModal";

export const SET_LOADING = 'setLoading';
1 change: 0 additions & 1 deletion public/pages/blog/+data.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ async function data(pageContext) {
searchStringFacade: searchString,
title: "Blog",
description: "Various tech blog",
loading: false,
}
}
20 changes: 1 addition & 19 deletions public/pages/blog/BlogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
>
<v-container class="post-title ma-0 pa-0">
<v-card-title>
<a class="post-title-text" v-html="item.title" :href="getLink(item)" @click="onPostClick()"></a>
<a class="post-title-text" v-html="item.title" :href="getLink(item)"></a>
</v-card-title>
</v-container>
</v-img>
Expand Down Expand Up @@ -120,7 +120,6 @@ export default {
return blogIdPrefix + id
},
onClickPage(e) {
this.loading = true; // false will be set with the new data from server
let actualPage = e--;
Expand All @@ -130,7 +129,6 @@ export default {
navigate(url.pathname + url.search);
},
onSearchStringChanged(searchString) {
this.loading = true; // false will be set with the new data from server
const url = new URL(window.location.href);
Expand Down Expand Up @@ -226,22 +224,6 @@ export default {
this.removeTopBlogPosition();
}
},
onPostClick() {
this.setLoadingAnimation()
},
setLoadingAnimation() {
this.loading = true
},
},
computed: {
loading: {
get() {
return this.pageContext.data.loading
},
set(v) {
this.pageContext.data.loading = v;
}
}
},
watch: {
'pageContext.data.items': function(newUserValue, oldUserValue) {
Expand Down
1 change: 0 additions & 1 deletion public/pages/blog/post/@id/+data.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ async function data(pageContext) {
count,
blogDto: blogResponse.data,
items: commentResponse.data.items,
commentsLoading: false,
// see getPageTitle.js
title: unescapeHtml(blogResponse.data.title),
description: blogResponse.data.preview,
Expand Down
21 changes: 1 addition & 20 deletions public/pages/blog/post/@id/BlogPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<template v-if="pageContext.data.blogDto.messageId">
<v-container class="ma-0 pa-0" fluid>
<MessageItem v-for="(item, index) in pageContext.data.items" v-if="!commentsLoading"
<MessageItem v-for="(item, index) in pageContext.data.items"
:id="getItemId(item.id)"
:key="item.id"
:item="item"
Expand All @@ -49,13 +49,6 @@
@click="onClickTrap"
></MessageItem>

<v-progress-linear
class="my-2"
v-else
color="primary"
indeterminate
></v-progress-linear>

<v-btn class="my-2 mx-2" variant="flat" color="primary" :href="getChatLink()">Write a comment</v-btn>

<v-pagination
Expand Down Expand Up @@ -132,8 +125,6 @@ export default {
},
onClickPage(e) {
this.commentsLoading = true; // false will be set with the new data from server
const url = new URL(window.location.href);
url.searchParams.set(PAGE_PARAM, e);
navigate(url.pathname + url.search);
Expand All @@ -149,16 +140,6 @@ export default {
components: {
MessageItem,
},
computed: {
commentsLoading: {
get() {
return this.pageContext.data.commentsLoading
},
set(v) {
this.pageContext.data.commentsLoading = v;
}
}
},
mounted() {
},
beforeUnmount() {
Expand Down
2 changes: 0 additions & 2 deletions public/pages/chat/@id/message/@messageId/+data.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async function data(pageContext) {
},
title: "Page not found",
chatMessageHref: null,
loading: false,
}
}

Expand All @@ -38,7 +37,6 @@ async function data(pageContext) {
description: publishedMessageResponse.data.preview,
showSearchButton: true,
chatMessageHref,
loading: false,
}

}
15 changes: 15 additions & 0 deletions public/renderer/+onPageTransitionEnd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import bus, {SET_LOADING} from "../common/bus.js";

export { onPageTransitionEnd }

function onPageTransitionEnd(pageContext) {
if (typeof window == "undefined") {
//console.log("onPageTransitionEnd Application is on server side", pageContext);
return undefined
} else {
//console.log("onPageTransitionEnd Application is on client side", pageContext);
bus.emit(SET_LOADING, false)
return undefined
}

}
15 changes: 15 additions & 0 deletions public/renderer/+onPageTransitionStart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import bus, {SET_LOADING} from "../common/bus.js";

export { onPageTransitionStart }

function onPageTransitionStart(pageContext) {
if (typeof window == "undefined") {
//console.log("+onPageTransitionStart Application is on server side", pageContext);
return undefined
} else {
//console.log("+onPageTransitionStart Application is on client side", pageContext);
bus.emit(SET_LOADING, true)
return undefined
}

}
38 changes: 17 additions & 21 deletions public/renderer/PageShell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<v-app-bar color='indigo' dark :density="getDensity()">
<template v-if="getShowSearchButton()">
<v-breadcrumbs
@click="onBreadcrumbsLinkClick"
:items="getBreadcrumbs()"
/>
<v-spacer/>
Expand Down Expand Up @@ -35,12 +34,13 @@
</template>

<script>
import {hasLength, getUrlPrefix} from "#root/common/utils";
import {hasLength} from "#root/common/utils";
import {blog, path_prefix, blog_post, videochat} from "#root/common/router/routes.js";
import bus, {SEARCH_STRING_CHANGED} from "#root/common/bus.js";
import {usePageContext} from "./usePageContext.js";
import CollapsedSearch from "#root/common/components/CollapsedSearch.vue";
import PlayerModal from "#root/common/components/PlayerModal.vue";
import {SET_LOADING} from "../common/bus.js";
export default {
components: {PlayerModal, CollapsedSearch},
Expand All @@ -54,7 +54,12 @@
}
},
data() {
return this.pageContext.data;
return {
chatMessageHref: this.pageContext.data.chatMessageHref,
chatTitle: this.pageContext.data.chatTitle,
showSearchButton: this.pageContext.data.showSearchButton,
pageLoading: false,
}
},
methods: {
getDensity() {
Expand All @@ -63,16 +68,6 @@
isMobile() {
return this.pageContext.isMobile
},
onBreadcrumbsLinkClick(e) {
const relUrl = e?.target?.href?.slice(getUrlPrefix().length);
console.log("onBreadcrumbsLinkClick", relUrl);
if (hasLength(relUrl)) {
this.setLoadingAnimation();
}
},
setLoadingAnimation(){
this.pageLoading = true
},
getBreadcrumbs() {
const ret = [
{
Expand Down Expand Up @@ -149,6 +144,9 @@
shouldShowTitle() {
return hasLength(this.$data.chatTitle)
},
setLoading(v) {
this.$data.pageLoading = v
},
},
computed: {
chatId() {
Expand All @@ -157,15 +155,13 @@
messageId() {
return this.pageContext.routeParams?.messageId
},
pageLoading: {
get() {
return this.pageContext.data.loading
},
set(v) {
this.pageContext.data.loading = v;
}
},
},
mounted() {
bus.on(SET_LOADING, this.setLoading)
},
beforeUnmount() {
bus.off(SET_LOADING, this.setLoading)
}
}
</script>
Expand Down

0 comments on commit 333b94e

Please sign in to comment.