Remove debug logs, refactor some problematic code

This commit is contained in:
Ramon Wenger 2023-07-27 15:40:23 +02:00
parent b664e97b1a
commit e726dcc073
6 changed files with 225 additions and 235 deletions

View File

@ -35,35 +35,19 @@ const EditContentBlockWizard = defineAsyncComponent(() =>
const EditRoomEntryWizard = defineAsyncComponent(() =>
import('@/components/rooms/room-entries/EditRoomEntryWizard.vue')
);
const NewProjectEntryWizard = defineAsyncComponent(() =>
import('@/components/portfolio/NewProjectEntryWizard.vue')
);
const EditProjectEntryWizard = defineAsyncComponent(() =>
import('@/components/portfolio/EditProjectEntryWizard.vue')
);
const NewObjectiveWizard = defineAsyncComponent(() =>
import('@/components/objective-groups/NewObjectiveWizard.vue')
);
const NewNoteWizard = defineAsyncComponent(() =>
import('@/components/notes/NewNoteWizard.vue')
);
const EditNoteWizard = defineAsyncComponent(() =>
import('@/components/notes/EditNoteWizard.vue')
);
const EditClassNameWizard = defineAsyncComponent(() =>
import('@/components/school-class/EditClassNameWizard.vue')
);
const EditTeamNameWizard = defineAsyncComponent(() =>
import('@/components/profile/EditTeamNameWizard.vue')
);
const NewProjectEntryWizard = defineAsyncComponent(() => import('@/components/portfolio/NewProjectEntryWizard.vue'));
const EditProjectEntryWizard = defineAsyncComponent(() => import('@/components/portfolio/EditProjectEntryWizard.vue'));
const NewObjectiveWizard = defineAsyncComponent(() => import('@/components/objective-groups/NewObjectiveWizard.vue'));
const NewNoteWizard = defineAsyncComponent(() => import('@/components/notes/NewNoteWizard.vue'));
const EditNoteWizard = defineAsyncComponent(() => import('@/components/notes/EditNoteWizard.vue'));
const EditClassNameWizard = defineAsyncComponent(() => import('@/components/school-class/EditClassNameWizard.vue'));
const EditTeamNameWizard = defineAsyncComponent(() => import('@/components/profile/EditTeamNameWizard.vue'));
const EditSnapshotTitleWizard = defineAsyncComponent(() =>
import('@/components/snapshots/EditSnapshotTitleWizard.vue')
);
const DefaultLayout = defineAsyncComponent(() => import('@/layouts/DefaultLayout.vue'));
const SimpleLayout = defineAsyncComponent(() => import('@/layouts/SimpleLayout.vue'));
const FullScreenLayout = defineAsyncComponent(() =>
import('@/layouts/FullScreenLayout.vue')
);
const FullScreenLayout = defineAsyncComponent(() => import('@/layouts/FullScreenLayout.vue'));
const PublicLayout = defineAsyncComponent(() => import('@/layouts/PublicLayout.vue'));
const BlankLayout = defineAsyncComponent(() => import('@/layouts/BlankLayout.vue'));
const SplitLayout = defineAsyncComponent(() => import('@/layouts/SplitLayout.vue'));

View File

@ -22,7 +22,7 @@ import { getUniqueId } from '@/helpers/id';
interface Props {
label: string;
type: string;
type?: string;
value: string;
}
const props = withDefaults(defineProps<Props>(), {

View File

@ -16,7 +16,7 @@ const PlusIcon = defineAsyncComponent(() => import('@/components/icons/PlusIcon.
const props = withDefaults(
defineProps<{
module: boolean;
module?: boolean;
}>(),
{
module: false,

View File

@ -19,10 +19,10 @@ export default function(uri, networkErrorCallback) {
});
const consoleLink = new ApolloLink((operation, forward) => {
log.debug('operation', operation.operationName);
// log.debug('operation', operation.operationName);
return forward(operation).map((data) => {
log.debug(`returned from server for ${operation.operationName}`, data);
// log.debug(`returned from server for ${operation.operationName}`, data);
return data;
});
});
@ -43,7 +43,8 @@ export default function(uri, networkErrorCallback) {
const errorLink = onError(({ networkError, graphQLErrors }) => {
if (networkError && networkErrorCallback) {
networkErrorCallback(networkError.statusCode);
if (networkError.statusCode == 402) { // not authenticated, we don't need to continue here
if (networkError.statusCode == 402) {
// not authenticated, we don't need to continue here
return;
}
}

View File

@ -27,7 +27,7 @@ export function matomoTrackPageView(absolutePath: string = '/', title?: string)
if (matomoLastUrl !== url) {
// do not track the same url twice
log.debug('trackMatomoPageView', { url, matomoLastUrl, title });
// log.debug('trackMatomoPageView', { url, matomoLastUrl, title });
window._paq.push(['setCustomUrl', url]);
window._paq.push(['trackPageView', title]);
matomoLastUrl = url;
@ -39,7 +39,7 @@ export function matomoTrackEvent(category: string, action: string, name?: string
const dataJSON = JSON.stringify(data);
if (matomoLastEventData !== dataJSON) {
log.debug('matomoTrackEvent', { category, action, name, value });
// log.debug('matomoTrackEvent', { category, action, name, value });
// @ts-ignore
window._paq.push(['trackEvent', category, action, name, value]);
matomoLastEventData = dataJSON;
@ -79,7 +79,7 @@ export function matomoTrackModuleVisibilityEvent(blockType: string, block: any,
export function matomoTrackUser(userId: string, role: matomoUserRole = 'Student') {
// see https://developer.matomo.org/guides/tracking-javascript-guide#user-id for the process
if (matomoLastUserId !== userId) {
log.debug('matomoTrackUser', { userId, matomoLastUserId, role });
// log.debug('matomoTrackUser', { userId, matomoLastUserId, role });
if (userId) {
// @ts-ignore

View File

@ -1,228 +1,233 @@
<template>
<module :module="module" @editNote="editNote" @addNote="addNote" @bookmark="bookmark" />
<module
:module="module"
@editNote="editNote"
@addNote="addNote"
@bookmark="bookmark"
/>
</template>
<script>
import Module from '@/components/modules/Module.vue';
import log from 'loglevel';
import Module from '@/components/modules/Module.vue';
import log from 'loglevel';
import UPDATE_LAST_MODULE_MUTATION from '@/graphql/gql/mutations/updateLastModule.gql';
import UPDATE_MODULE_BOOKMARK_MUTATION from '@/graphql/gql/mutations/updateModuleBookmark.gql';
// import ME_QUERY from '@/graphql/gql/meQuery.gql';
import MODULE_FRAGMENT from '@/graphql/gql/fragments/moduleParts.gql';
import SCROLL_POSITION from '@/graphql/gql/local/scrollPosition.gql';
import SCROLL_TO_MUTATION from '@/graphql/gql/local/mutations/scrollTo.gql';
import UPDATE_LAST_MODULE_MUTATION from '@/graphql/gql/mutations/updateLastModule.gql';
import UPDATE_MODULE_BOOKMARK_MUTATION from '@/graphql/gql/mutations/updateModuleBookmark.gql';
// import ME_QUERY from '@/graphql/gql/meQuery.gql';
import MODULE_FRAGMENT from '@/graphql/gql/fragments/moduleParts.gql';
import SCROLL_POSITION from '@/graphql/gql/local/scrollPosition.gql';
import SCROLL_TO_MUTATION from '@/graphql/gql/local/mutations/scrollTo.gql';
import meMixin from '@/mixins/me';
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
import {setModuleEditMode} from '@/graphql/cache-operations';
import meMixin from '@/mixins/me';
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
import { setModuleEditMode } from '@/graphql/cache-operations';
export default {
mixins: [meMixin],
export default {
mixins: [meMixin],
components: {
Module,
},
components: {
Module,
},
data() {
data() {
return {
module: {},
updateSent: false,
};
},
beforeRouteLeave(to, _, next) {
// toggle edit mode if leaving the module subtree
if (this.module.inEditMode && to.path.indexOf('/module/') === -1) {
setModuleEditMode(this.module.slug, false);
}
next();
},
apollo: {
module() {
return {
module: {},
updateSent: false,
query: MODULE_DETAILS_QUERY,
variables: {
slug: this.$route.params.slug,
},
result({
data: {
module: { id },
},
}) {
if (!this.updateSent) {
// log.debug(`=== updating result for module ${id} ===`);
this.updateLastVisitedModule(id);
this.updateSent = true;
}
},
fetchPolicy: 'cache-first',
};
},
scrollPosition: {
query: SCROLL_POSITION,
},
},
beforeRouteLeave(to, _, next) {
// toggle edit mode if leaving the module subtree
if (this.module.inEditMode && to.path.indexOf('/module/') === -1) {
setModuleEditMode(this.module.slug, false);
methods: {
updateLastVisitedModule(moduleId) {
// log.debug(`updating last visited module for module ${moduleId}`);
if (!moduleId) {
log.warn('no module id');
return;
}
next();
},
apollo: {
module() {
return {
query: MODULE_DETAILS_QUERY,
variables: {
slug: this.$route.params.slug,
if (this.me.lastModule && this.me.lastModule.id === moduleId) {
log.debug('same module already set as last module');
return;
}
this.$apollo.mutate({
mutation: UPDATE_LAST_MODULE_MUTATION,
variables: {
input: {
id: moduleId,
},
result({
},
update: (
store,
{
data: {
module: {id},
updateLastModule: { lastModule },
},
}) {
if (!this.updateSent) {
log.debug(`=== updating result for module ${id} ===`);
this.updateLastVisitedModule(id);
this.updateSent = true;
}
},
fetchPolicy: 'cache-first',
};
},
scrollPosition: {
query: SCROLL_POSITION,
},
},
}
) => {
const { slug } = lastModule;
// log.debug('updating last module', lastModule.id, slug);
const query = ME_QUERY;
let { me } = store.readQuery({
query,
});
// me.lastModule = {
// id,
// slug,
// __typename: 'ModuleNode',
// };
methods: {
updateLastVisitedModule(moduleId) {
log.debug(`updating last visited module for module ${moduleId}`);
if (!moduleId) {
log.warn('no module id');
return;
}
if (this.me.lastModule && this.me.lastModule.id === moduleId) {
log.debug('same module already set as last module');
return;
}
this.$apollo.mutate({
mutation: UPDATE_LAST_MODULE_MUTATION,
variables: {
input: {
id: moduleId,
},
},
update: (
store,
let edges = [...me.recentModules.edges];
const foundIndex = edges.findIndex((edge) => edge.node.slug === slug);
if (foundIndex > -1) {
edges = [...edges.slice(0, foundIndex), ...edges.slice(foundIndex + 1, edges.length)];
}
edges = [
{
data: {
updateLastModule: {lastModule},
},
}
) => {
const {id, slug} = lastModule;
log.debug('updating last module', id, slug);
const query = ME_QUERY;
let {me} = store.readQuery({
query,
});
// me.lastModule = {
// id,
// slug,
// __typename: 'ModuleNode',
// };
let edges = [...me.recentModules.edges];
const foundIndex = edges.findIndex((edge) => edge.node.slug === slug);
if (foundIndex > -1) {
edges = [...edges.slice(0, foundIndex), ...edges.slice(foundIndex + 1, edges.length)];
}
edges = [
{
node: lastModule,
__typename: 'ModuleNodeEdge',
},
...edges.slice(0, 2),
];
const recentModules = {
__typename: 'ModuleNodeConnection',
edges,
};
const data = {
me: {
...me,
recentModules,
lastModule: {
...lastModule,
// todo: do we really need this? shouldn't the lastModule property already include this?
__typename: 'ModuleNode',
},
},
};
store.writeQuery({
query,
data,
});
},
});
},
bookmark(bookmarked) {
const slug = this.module.slug;
this.$apollo.mutate({
mutation: UPDATE_MODULE_BOOKMARK_MUTATION,
variables: {
input: {
module: slug,
bookmarked,
node: lastModule,
__typename: 'ModuleNodeEdge',
},
},
update: (store) => {
const fragment = MODULE_FRAGMENT;
const id = store.identify({
__typename: 'ModuleNode',
slug: slug,
});
const module = store.readFragment({
fragment,
id,
});
let bookmark;
if (bookmarked) {
bookmark = {
__typename: 'ModuleBookmarkNode',
note: null,
};
} else {
bookmark = null;
}
const data = {
...module,
bookmark,
};
store.writeFragment({
data,
fragment,
id,
});
},
optimisticResponse: {
__typename: 'Mutation',
updateModuleBookmark: {
__typename: 'UpdateModuleBookmarkPayload',
success: true,
},
},
});
},
addNote(id) {
this.$store.dispatch('addNote', {
content: id,
parent: this.module.slug,
type: 'module',
});
},
editNote() {
this.$store.dispatch('editNote', this.module.bookmark.note);
},
scrollTo() {
if (this.scrollPosition && this.scrollPosition.scrollTo) {
let options = {
container: 'body',
easing: 'ease',
offset: -60,
x: false,
y: true,
...edges.slice(0, 2),
];
const recentModules = {
__typename: 'ModuleNodeConnection',
edges,
};
setTimeout(() => {
this.$scrollTo(`[data-scrollto="${this.scrollPosition.scrollTo}"]`, 1000, options);
this.$apollo.mutate({
mutation: SCROLL_TO_MUTATION,
variables: {
scrollTo: '',
const data = {
me: {
...me,
recentModules,
lastModule: {
...lastModule,
// todo: do we really need this? shouldn't the lastModule property already include this?
__typename: 'ModuleNode',
},
});
}, 250); // unfortunately this timeout is needed as it is hard to tell when everything is rendered
}
},
},
};
store.writeQuery({
query,
data,
});
},
});
},
};
bookmark(bookmarked) {
const slug = this.module.slug;
this.$apollo.mutate({
mutation: UPDATE_MODULE_BOOKMARK_MUTATION,
variables: {
input: {
module: slug,
bookmarked,
},
},
update: (store) => {
const fragment = MODULE_FRAGMENT;
const id = store.identify({
__typename: 'ModuleNode',
slug: slug,
});
const module = store.readFragment({
fragment,
id,
});
let bookmark;
if (bookmarked) {
bookmark = {
__typename: 'ModuleBookmarkNode',
note: null,
};
} else {
bookmark = null;
}
const data = {
...module,
bookmark,
};
store.writeFragment({
data,
fragment,
id,
});
},
optimisticResponse: {
__typename: 'Mutation',
updateModuleBookmark: {
__typename: 'UpdateModuleBookmarkPayload',
success: true,
},
},
});
},
addNote(id) {
this.$store.dispatch('addNote', {
content: id,
parent: this.module.slug,
type: 'module',
});
},
editNote() {
this.$store.dispatch('editNote', this.module.bookmark.note);
},
scrollTo() {
if (this.scrollPosition && this.scrollPosition.scrollTo) {
let options = {
container: 'body',
easing: 'ease',
offset: -60,
x: false,
y: true,
};
setTimeout(() => {
this.$scrollTo(`[data-scrollto="${this.scrollPosition.scrollTo}"]`, 1000, options);
this.$apollo.mutate({
mutation: SCROLL_TO_MUTATION,
variables: {
scrollTo: '',
},
});
}, 250); // unfortunately this timeout is needed as it is hard to tell when everything is rendered
}
},
},
};
</script>