Skip to content

Commit

Permalink
Merge branch 'main' into N21-1369-locales-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorCapCoder authored Oct 12, 2023
2 parents 7538701 + 75c8798 commit 484ac43
Show file tree
Hide file tree
Showing 61 changed files with 1,216 additions and 989 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
{
group: ["@components/page-*", "*/../page-*", "../**/page-*/*"],
message:
"page-Modules have to be imported using the pattern '@page-<name>'",
"Page-Modules have to be imported using the pattern '@page-<name>'",
},
{
group: ["@components/ui-*", "*/../ui-*", "../**/ui-*/*"],
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"generate-client:h5p-editor": "node generate-client.js -u 'http://localhost:4448/api/v3/docs-json/' -p 'src/h5pEditorApi/v3' -c 'openapitools-for-h5p-editor.json'"
},
"dependencies": {
"@braintree/sanitize-url": "^6.0.4",
"@ckeditor/ckeditor5-vue2": "^3.0.1",
"@hpi-schul-cloud/ckeditor": "0.4.0",
"@mdi/js": "^7.2.96",
Expand Down
10 changes: 9 additions & 1 deletion src/components/data-board/BoardApi.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CreateContentElementBodyParams,
ExternalToolElementContent,
FileElementContent,
LinkElementContent,
RichTextElementContent,
RoomsApiFactory,
SubmissionContainerElementContent,
Expand Down Expand Up @@ -73,7 +74,7 @@ export const useBoardApi = () => {
if (element.type === ContentElementType.RichText) {
return {
content: element.content as RichTextElementContent,
type: ContentElementType.RichText,
type: element.type,
};
}

Expand All @@ -98,6 +99,13 @@ export const useBoardApi = () => {
};
}

if (element.type === ContentElementType.Link) {
return {
content: element.content as LinkElementContent,
type: ContentElementType.Link,
};
}

throw new Error("element.type mapping is undefined for updateElementCall");
};

Expand Down
42 changes: 32 additions & 10 deletions src/components/data-board/ContentElementState.composable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { watchDebounced } from "@vueuse/core";
import { ref, toRef, unref } from "vue";
import { computed, ComputedRef, Ref, ref, toRef, unref } from "vue";
import { useBoardApi } from "./BoardApi.composable";
import { AnyContentElement } from "@/types/board/ContentElement";
import { useErrorHandler } from "@/components/error-handling/ErrorHandler.composable";
Expand All @@ -11,28 +11,45 @@ export const useContentElementState = <T extends AnyContentElement>(
},
options: { autoSaveDebounce?: number } = { autoSaveDebounce: 300 }
) => {
const { handleError, notifyWithTemplate } = useErrorHandler();
const elementRef = toRef(props, "element");
const modelValue = ref<T["content"]>(unref<T>(elementRef).content);
const _elementRef: Ref<T> = toRef(props, "element");
const _responseValue = ref<T>(unref<T>(_elementRef));

const { handleError, notifyWithTemplate } = useErrorHandler();
const { updateElementCall } = useBoardApi();

watchDebounced(
elementRef.value,
async (elementRef) => {
await updateElement(unref(elementRef));
const modelValue = ref<T["content"]>(unref<T>(_elementRef).content);

const computedElement: ComputedRef<T> = computed(() => ({
..._elementRef.value,
..._responseValue.value,
}));

const isLoading = ref<boolean>(false);

watchDebounced<T["content"]>(
modelValue.value,
async (modelValue) => {
await updateElement(modelValue);
},
{ debounce: options.autoSaveDebounce, maxWait: 2500 }
);

// TODO: refactor this to be properly typed
const updateElement = async (element: T) => {
const updateElement = async (content: T["content"]) => {
isLoading.value = true;
const payload = {
...computedElement.value,
content: { ...content },
};
try {
await updateElementCall(element);
const response = await updateElementCall(payload);
_responseValue.value = response.data;
} catch (error) {
handleError(error, {
404: notifyWithTemplate("notUpdated", "boardElement"),
});
} finally {
isLoading.value = false;
}
};

Expand All @@ -42,5 +59,10 @@ export const useContentElementState = <T extends AnyContentElement>(
* Will be saved automatically after a debounce
*/
modelValue,
/**
* Contains the whole element as it is currently known in the backend
*/
computedElement,
isLoading,
};
};
2 changes: 1 addition & 1 deletion src/components/error-handling/ErrorHandler.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useErrorHandler = () => {
if (handlerFunction) {
handlerFunction(responseError);
} else {
console.error(responseError);
console.error(error);
}
};

Expand Down
Loading

0 comments on commit 484ac43

Please sign in to comment.