Refactor component

This commit is contained in:
Ramon Wenger 2023-02-16 16:50:09 +01:00
parent 8368050683
commit 3c0f5944cc
2 changed files with 63 additions and 67 deletions

View File

@ -42,79 +42,75 @@
:shared-msg="sharedMsg" :shared-msg="sharedMsg"
:show-reopen="!readOnly" :show-reopen="!readOnly"
v-if="isFinalOrReadOnly" v-if="isFinalOrReadOnly"
@reopen="$emit('reopen')" @reopen="reopenSubmission"
/> />
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import { defineAsyncComponent } from 'vue'; import { defineAsyncComponent, computed } from 'vue';
const SubmissionInput = defineAsyncComponent(() => import('@/components/content-blocks/assignment/SubmissionInput')); export interface Props {
const FinalSubmission = defineAsyncComponent(() => import('@/components/content-blocks/assignment/FinalSubmission')); userInput: {
const FileUpload = defineAsyncComponent(() => import('@/components/ui/file-upload/FileUpload')); final: boolean;
document: string;
text: string;
};
saved: boolean;
placeholder: string;
action: string;
reopen: Function;
document: string;
readOnly: boolean;
spellcheck: boolean;
spellcheckLoading: boolean;
sharedMsg: string;
}
export default { const SubmissionInput = defineAsyncComponent(
props: { () => import('@/components/content-blocks/assignment/SubmissionInput.vue')
userInput: Object, );
saved: Boolean, const FinalSubmission = defineAsyncComponent(
placeholder: String, () => import('@/components/content-blocks/assignment/FinalSubmission.vue')
action: String, );
reopen: Function, const FileUpload = defineAsyncComponent(() => import('@/components/ui/file-upload/FileUpload.vue'));
document: String,
readOnly: {
type: Boolean,
default: false,
},
spellcheck: {
type: Boolean,
default: false,
},
spellcheckLoading: {
type: Boolean,
default: false,
},
sharedMsg: String,
},
components: { const props = withDefaults(defineProps<Props>(), {
FileUpload, readOnly: false,
SubmissionInput, speelcheck: false,
FinalSubmission, spellcheckLoading: false,
}, });
computed: { const final = computed(() => {
final() { return !!props.userInput && props.userInput.final;
return !!this.userInput && this.userInput.final; });
}, const isFinalOrReadOnly = computed(() => {
isFinalOrReadOnly() { return final.value || props.readOnly;
return this.final || this.readOnly; });
}, const allowsDocuments = computed(() => {
allowsDocuments() { return false;
return 'document' in this.userInput; //return 'document' in props.userInput;
}, });
showSpellcheckButton() { const showSpellcheckButton = computed(() => {
return this.spellcheck && process.env.VUE_APP_ENABLE_SPELLCHECK; return props.spellcheck && process.env.VUE_APP_ENABLE_SPELLCHECK;
}, });
spellcheckText() { const spellcheckText = computed(() => {
if (!this.spellcheckLoading) { if (!props.spellcheckLoading) {
return 'Rechtschreibung prüfen'; return 'Rechtschreibung prüfen';
} else { } else {
return 'Wird geprüft...'; return 'Wird geprüft...';
} }
}, });
},
methods: { const emit = defineEmits(['reopen', 'saveInput', 'changeDocumentUrl']);
reopenSubmission() {
this.$emit('reopen'); const reopenSubmission = () => {
}, emit('reopen');
saveInput(input) { };
this.$emit('saveInput', input); const saveInput = (input: any) => {
}, emit('saveInput', input);
changeDocumentUrl(documentUrl) { };
this.$emit('changeDocumentUrl', documentUrl); const changeDocumentUrl = (documentUrl: string) => {
}, emit('changeDocumentUrl', documentUrl);
},
}; };
</script> </script>

View File

@ -6,12 +6,12 @@
>{{ label }}</label >{{ label }}</label
> >
<component <component
:model-value="value" :value="value"
:class="classes" :class="classes"
:data-cy="cyId" :data-cy="cyId"
:is="type" :is="type"
:id="id" :id="id"
@update:modelValue="$emit('input', $event.target.value)" @input="$emit('input', $event.target.value)"
/> />
</div> </div>
</template> </template>