Skip to content

Commit

Permalink
feat(perf): create app-loading component + refactor view resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Dec 23, 2021
1 parent 2392d8e commit 558e1c1
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 132 deletions.
6 changes: 3 additions & 3 deletions src/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</template>

<script>
import { contexts, useLoadingContext } from "@/composables/loading";
import { contexts, useLoadingContext } from "@/composables/loading.js";
// Components
import AppHeader from "@/components/specific/app/app-header/AppHeader";
import NotificationCard from "@/components/generic/notification-card/NotificationCard";
import AppHeader from "@/components/specific/app/app-header/AppHeader.vue";
import NotificationCard from "@/components/generic/notification-card/NotificationCard.vue";
export default {
components: {
Expand Down
20 changes: 20 additions & 0 deletions src/components/generic/app-loading/AppLoader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template>
<div class="app-loader">
<BIMDataSpinner />
</div>
</template>

<style scoped lang="scss">
.app-loader {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
.bimdata-spinner {
transform: scale(2);
}
}
</style>
34 changes: 34 additions & 0 deletions src/components/generic/app-loading/AppLoading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<transition name="fade" mode="out-in">
<template v-if="loading">
<AppLoader />
</template>
<template v-else>
<slot></slot>
</template>
</transition>
</template>

<script>
import { useAppLoading } from "./app-loading.js";
import AppLoader from "./AppLoader.vue";
export default {
components: {
AppLoader
},
props: {
name: {
type: String,
required: true
}
},
setup(props) {
const loading = useAppLoading(props.name);
return {
loading
};
}
};
</script>
14 changes: 14 additions & 0 deletions src/components/generic/app-loading/app-loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ref } from "vue";

const state = {};

export function useAppLoading(name) {
return state[name] ?? (state[name] = ref(false));
}

export async function load(name, promises) {
const loading = useAppLoading(name);
loading.value = true;
await Promise.all(promises);
loading.value = false;
}
2 changes: 1 addition & 1 deletion src/components/generic/app-slot/AppSlot.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { h } from "vue";
import { useAppSlot } from "./app-slot";
import { useAppSlot } from "./app-slot.js";
export default {
props: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/generic/app-slot/AppSlotContent.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { onActivated, onBeforeUnmount, onDeactivated, onMounted } from "vue";
import { useAppSlot } from "./app-slot";
import { useAppSlot } from "./app-slot.js";
export default {
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<script>
import { useRouter } from "vue-router";
import routeNames from "@/router/route-names.js";
import { useGroups } from "@/state/groups";
import { useProjects } from "@/state/projects";
import { useGroups } from "@/state/groups.js";
import { useProjects } from "@/state/projects.js";
// Components
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector";
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector.vue";
export default {
components: {
Expand Down Expand Up @@ -51,8 +51,8 @@ export default {
return {
// References
selectedGroup: currentGroup,
groups: projectGroups,
selectedGroup: currentGroup,
// Methods
goToGroupBoard,
goToProjectGroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<BreadcrumbSelector
:list="spaces"
labelProp="name"
:header="selectedSpace.name"
:header="selectedSpace?.name"
@item-selected="selectSpace"
@header-clicked="goToSpace"
/>
Expand All @@ -11,7 +11,7 @@
v-if="projects.length > 0"
:list="projects"
labelProp="name"
:header="selectedProject.name"
:header="selectedProject?.name"
@item-selected="goToProject"
/>
<div v-else>
Expand All @@ -23,10 +23,10 @@
import { ref, watch } from "vue";
import { useRouter } from "vue-router";
import routeNames from "@/router/route-names.js";
import { useProjects } from "@/state/projects";
import { useSpaces } from "@/state/spaces";
import { useProjects } from "@/state/projects.js";
import { useSpaces } from "@/state/spaces.js";
// Components
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector";
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector.vue";
export default {
components: {
Expand All @@ -37,13 +37,24 @@ export default {
const { userSpaces, currentSpace } = useSpaces();
const { userProjects, spaceProjects, currentProject } = useProjects();
const projects = ref(spaceProjects.value);
const selectedSpace = ref(currentSpace.value);
const selectedProject = ref(currentProject.value);
const projects = ref([]);
const selectedSpace = ref(null);
const selectedProject = ref(null);
watch(
() => spaceProjects.value,
() => (projects.value = spaceProjects.value),
{ immediate: true }
);
watch(
() => currentSpace.value,
space => (selectedSpace.value = space),
{ immediate: true }
);
watch(
() => currentProject.value,
() => (selectedProject.value = currentProject.value)
project => (selectedProject.value = project),
{ immediate: true }
);
const goToProject = project => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<script>
import { useRouter } from "vue-router";
import routeNames from "@/router/route-names.js";
import { useSpaces } from "@/state/spaces";
import { useSpaces } from "@/state/spaces.js";
// Components
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector";
import BreadcrumbSelector from "@/components/generic/breadcrumb-selector/BreadcrumbSelector.vue";
export default {
components: {
Expand Down
24 changes: 4 additions & 20 deletions src/composables/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@ const contexts = Object.freeze({
viewContainer: "view-container"
});

const state = {
[contexts.viewContainer]: { loading: ref(false) }
};

const createLoadingContext = context => {
state[context] = { loading: ref(false) };
return state[context].loading;
};
const state = {};

const removeLoadingContext = context => {
delete state[context];
const useLoadingContext = name => {
return state[name] ?? (state[name] = ref(false));
};

const useLoadingContext = context => {
return state[context].loading;
};

export {
contexts,
createLoadingContext,
removeLoadingContext,
useLoadingContext
};
export { contexts, useLoadingContext };
4 changes: 3 additions & 1 deletion src/router/guards/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const { isAuthenticated, authenticate } = useAuth();

export default async function authGuard(route) {
if (isAuthenticated.value) {
// Continue navigation if already authenticated
return true;
} else if (route.matched.some(r => r.meta.requiresAuth)) {
// Trigger authentication process if required
await authenticate(route.path);
// Navigate to target route if authentication succeeds (cancel navigation otherwise)
// Continue navigation if authentication succeeds (cancel navigation otherwise)
return isAuthenticated.value;
}
}
18 changes: 12 additions & 6 deletions src/router/guards/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ let dataLoaded = false;

export default async function dataGuard() {
if (isAuthenticated.value && !dataLoaded) {
// Note: the order in which methods are called is important !
// **NOTE** the order in which methods are called is important !

// 1) Load current user data
await loadUser();
await loadUserOrganizations();
await loadUserSpaces();
await loadUserProjects();

await loadAllOrganizationsSpaces();
await loadAllSpacesSubscriptions();
// 2) Load organizations, spaces and projects for the current user
await Promise.all([
loadUserOrganizations(),
loadUserSpaces(),
loadUserProjects()
]);

// 3) Load lists of orga spaces and space subs
await loadAllOrganizationsSpaces(); // 3.1) load orga spaces
await loadAllSpacesSubscriptions(); // 3.2) load space subs

dataLoaded = true;
}
Expand Down
9 changes: 5 additions & 4 deletions src/router/resolvers/views/group-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const groups = useGroups();

export default async function groupBoardResolver(route) {
spaces.setCurrentSpace(+route.params.spaceID);
await projects.loadSpaceProjects(spaces.currentSpace.value);
const project = projects.setCurrentProject(+route.params.projectID);

projects.setCurrentProject(+route.params.projectID);
await projects.loadProjectUsers(projects.currentProject.value);
await groups.loadProjectGroups(projects.currentProject.value);
await Promise.all([
projects.loadProjectUsers(project),
groups.loadProjectGroups(project)
]);

groups.setCurrentGroup(+route.params.groupID);
}
10 changes: 6 additions & 4 deletions src/router/resolvers/views/model-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ const projects = useProjects();
const models = useModels();

export default async function modelViewerResolver(route) {
spaces.setCurrentSpace(+route.params.spaceID);
await projects.loadSpaceProjects(spaces.currentSpace.value);
const space = spaces.setCurrentSpace(+route.params.spaceID);
const project = projects.setCurrentProject(+route.params.projectID);

projects.setCurrentProject(+route.params.projectID);
await models.loadProjectModels(projects.currentProject.value);
await Promise.all([
projects.loadSpaceProjects(space),
models.loadProjectModels(project)
]);
}
28 changes: 18 additions & 10 deletions src/router/resolvers/views/project-board.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */
import { load } from "@/components/generic/app-loading/app-loading.js";
import { useGroups } from "@/state/groups.js";
import { useModels } from "@/state/models.js";
import { useProjects } from "@/state/projects.js";
Expand All @@ -10,16 +12,22 @@ const models = useModels();
const files = useFiles();
const groups = useGroups();

export default async function projectBoardResolver(route) {
spaces.setCurrentSpace(+route.params.spaceID);
await spaces.loadSpaceInfo(spaces.currentSpace.value);
await projects.loadSpaceProjects(spaces.currentSpace.value);
export default function projectBoardResolver(route) {
const space = spaces.setCurrentSpace(+route.params.spaceID);
const project = projects.setCurrentProject(+route.params.projectID);

projects.setCurrentProject(+route.params.projectID);
await models.loadProjectModels(projects.currentProject.value);
await files.loadProjectFileStructure(projects.currentProject.value);
await groups.loadProjectGroups(projects.currentProject.value);
spaces.loadSpaceInfo(space);
projects.loadSpaceProjects(space);

await projects.loadProjectUsers(projects.currentProject.value);
await projects.loadProjectInvitations(projects.currentProject.value);
load("project-users", [
projects.loadProjectUsers(project),
projects.loadProjectInvitations(project)
]);
load("project-models", [
models.loadProjectModels(project)
]);
load("project-files", [
files.loadProjectFileStructure(project),
groups.loadProjectGroups(project)
]);
}
5 changes: 2 additions & 3 deletions src/router/resolvers/views/project-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const groups = useGroups();

export default async function projectBoardResolver(route) {
spaces.setCurrentSpace(+route.params.spaceID);
await projects.loadSpaceProjects(spaces.currentSpace.value);
const project = projects.setCurrentProject(+route.params.projectID);

projects.setCurrentProject(+route.params.projectID);
await groups.loadProjectGroups(projects.currentProject.value);
await groups.loadProjectGroups(project);
}
17 changes: 12 additions & 5 deletions src/router/resolvers/views/space-board.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/* eslint-disable */
import { load } from "@/components/generic/app-loading/app-loading.js";
import { useProjects } from "@/state/projects.js";
import { useSpaces } from "@/state/spaces.js";

const spaces = useSpaces();
const projects = useProjects();

export default async function spaceBoardResolver(route) {
spaces.setCurrentSpace(+route.params.spaceID);
const space = spaces.setCurrentSpace(+route.params.spaceID);

await projects.loadSpaceProjects(spaces.currentSpace.value);
await spaces.loadSpaceInfo(spaces.currentSpace.value);
await spaces.loadSpaceUsers(spaces.currentSpace.value);
await spaces.loadSpaceInvitations(spaces.currentSpace.value);
spaces.loadSpaceInfo(space);

load("space-users", [
spaces.loadSpaceUsers(space),
spaces.loadSpaceInvitations(space)
]);
load("space-projects", [
projects.loadSpaceProjects(space)
]);
}
6 changes: 6 additions & 0 deletions src/views/project-board/project-files/ProjectFiles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
width: 100%;
min-height: 560px;
max-height: 100%;
background-color: var(--color-white);
}
}

.files-manager {
width: 100%;
height: 100%;
}
}
Loading

0 comments on commit 558e1c1

Please sign in to comment.