Add more typescript checks
This commit is contained in:
parent
c1a7f4551d
commit
626e336db9
|
|
@ -1,9 +1,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ItCheckbox from '@/components/ui/ItCheckbox.vue';
|
import ItCheckbox from '@/components/ui/ItCheckbox.vue';
|
||||||
|
import type {LearningContent, LearningSequence} from '@/services/circle';
|
||||||
|
|
||||||
const props = defineProps(['learningSequence', 'completionData'])
|
const props = defineProps<{
|
||||||
|
learningSequence: LearningSequence
|
||||||
|
completionData: any
|
||||||
|
}>()
|
||||||
|
|
||||||
const contentCompleted = (learningContent) => {
|
const contentCompleted = (learningContent: LearningContent) => {
|
||||||
if (props.completionData?.completed_learning_contents) {
|
if (props.completionData?.completed_learning_contents) {
|
||||||
return props.completionData.completed_learning_contents.findIndex((e) => {
|
return props.completionData.completed_learning_contents.findIndex((e) => {
|
||||||
return e.learning_content_key === learningContent.translation_key && e.completed;
|
return e.learning_content_key === learningContent.translation_key && e.completed;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import { getCookieValue } from '@/router/guards';
|
import {getCookieValue} from '@/router/guards';
|
||||||
|
|
||||||
class FetchError extends Error {
|
class FetchError extends Error {
|
||||||
constructor(response, message = 'HTTP error ' + response.status) {
|
response: Response;
|
||||||
|
|
||||||
|
constructor(response: Response, message = 'HTTP error ' + response.status) {
|
||||||
super(message);
|
super(message);
|
||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const itFetch = (url, options) => {
|
export const itFetch = (url: RequestInfo, options: RequestInit) => {
|
||||||
return fetch(url, options).then(response => {
|
return fetch(url, options).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new FetchError(response);
|
throw new FetchError(response);
|
||||||
|
|
@ -17,7 +19,11 @@ export const itFetch = (url, options) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const itPost = (url, data, options) => {
|
export const itPost = (
|
||||||
|
url: RequestInfo,
|
||||||
|
data: unknown,
|
||||||
|
options: RequestInit = {},
|
||||||
|
) => {
|
||||||
options = Object.assign({}, options);
|
options = Object.assign({}, options);
|
||||||
|
|
||||||
const headers = Object.assign({
|
const headers = Object.assign({
|
||||||
|
|
@ -35,6 +41,8 @@ export const itPost = (url, data, options) => {
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
options.headers['X-CSRFToken'] = getCookieValue('csrftoken');
|
options.headers['X-CSRFToken'] = getCookieValue('csrftoken');
|
||||||
|
|
||||||
if (options.method === 'GET') {
|
if (options.method === 'GET') {
|
||||||
|
|
@ -48,6 +56,6 @@ export const itPost = (url, data, options) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const itGet = (url) => {
|
export const itGet = (url: RequestInfo) => {
|
||||||
return itPost(url, {}, {method: 'GET'});
|
return itPost(url, {}, {method: 'GET'});
|
||||||
};
|
};
|
||||||
|
|
@ -1,24 +1,32 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import * as log from 'loglevel';
|
import * as log from 'loglevel';
|
||||||
|
|
||||||
import MainNavigationBar from '../components/MainNavigationBar.vue';
|
import MainNavigationBar from '../components/MainNavigationBar.vue';
|
||||||
import LearningSequence from '../components/circle/LearningSequence.vue';
|
import LearningSequence from '../components/circle/LearningSequence.vue';
|
||||||
import { itGet, itPost } from '../fetchHelpers';
|
import type {Circle, LearningContent} from '../services/circle';
|
||||||
import { parseLearningSequences } from '../services/circle';
|
import {parseLearningSequences} from '../services/circle';
|
||||||
|
|
||||||
export default {
|
import {defineComponent} from 'vue'
|
||||||
|
import {itGet, itPost} from '@/fetchHelpers';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
components: { LearningSequence, MainNavigationBar },
|
components: { LearningSequence, MainNavigationBar },
|
||||||
props: ['circleSlug',],
|
props: {
|
||||||
|
circleSlug: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
count: 0,
|
count: 0,
|
||||||
circleData: {},
|
circleData: {} as Circle,
|
||||||
learningSequences: [],
|
learningSequences: [] as LearningSequence[],
|
||||||
completionData: {},
|
completionData: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleLearningContentCheckbox(learningContent, completed=true) {
|
toggleLearningContentCheckbox(learningContent: LearningContent, completed=true) {
|
||||||
log.debug('toggleLearningContentCheckbox', learningContent, completed);
|
log.debug('toggleLearningContentCheckbox', learningContent, completed);
|
||||||
console.log(learningContent);
|
console.log(learningContent);
|
||||||
|
|
||||||
|
|
@ -43,8 +51,7 @@ export default {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -80,7 +87,10 @@ export default {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-auto bg-gray-100 px-4 py-8 lg:px-24">
|
<div class="flex-auto bg-gray-100 px-4 py-8 lg:px-24">
|
||||||
<div v-for="learningSequence in learningSequences">
|
<div
|
||||||
|
v-for="learningSequence in learningSequences"
|
||||||
|
:key="learningSequence.translation_key"
|
||||||
|
>
|
||||||
<LearningSequence
|
<LearningSequence
|
||||||
:learning-sequence="learningSequence" @toggleLearningContentCheckbox="toggleLearningContentCheckbox"
|
:learning-sequence="learningSequence" @toggleLearningContentCheckbox="toggleLearningContentCheckbox"
|
||||||
:completion-data="completionData"
|
:completion-data="completionData"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
"exclude": ["src/**/__tests__/*"],
|
"exclude": ["src/**/__tests__/*"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
|
"strict": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue