Refactor some code

This commit is contained in:
Ramon Wenger 2024-04-26 13:39:27 +02:00
parent db628eec24
commit e1c53b99da
2 changed files with 14 additions and 71 deletions

View File

@ -3,82 +3,25 @@
class="document-form"
ref="documentform"
>
<div
v-if="!value.url"
ref="uploadcare-panel"
<document-input
:url="value.url"
@update="updateUrl"
/>
<div
class="document-form__spinner"
v-if="loading"
>
<loading-icon class="document-form__loading-icon" />
</div>
<div
class="document-form__uploaded"
v-if="value.url"
>
<document-icon class="document-form__icon" />
<a
:href="previewUrl"
class="document-form__link"
target="_blank"
>{{ previewLink }}</a
>
</div>
</div>
</template>
<script>
import { uploadcare } from '@/helpers/uploadcare';
import LoadingIcon from '@/components/icons/LoadingIcon.vue';
import { defineAsyncComponent } from 'vue';
<script setup lang="ts">
import DocumentInput from '@/components/content-forms/DocumentInput.vue';
export interface Props {
value: any;
index: number;
}
const DocumentIcon = defineAsyncComponent(() =>
import('@/components/icons/DocumentIcon.vue')
);
const props = defineProps<Props>();
const emit = defineEmits(['change-url']);
export default {
props: ['value', 'index'],
components: {
LoadingIcon,
DocumentIcon,
},
data() {
return {
loading: false,
};
},
computed: {
previewUrl() {
if (this.value && this.value.url) {
return this.value.url;
}
return null;
},
previewLink() {
if (this.value && this.value.url) {
const parts = this.value.url.split('/');
return parts[parts.length - 1];
}
return '';
},
},
mounted() {
uploadcare(
this,
(url) => {
this.$emit('change-url', url, this.index);
this.loading = false;
},
() => {
this.loading = true;
}
);
},
const updateUrl = (url: string) => {
emit('change-url', url, props.index);
};
</script>

View File

@ -28,7 +28,7 @@ export default {
.link-form {
display: grid;
grid-auto-rows: auto;
grid-row-gap: 11px;
grid-row-gap: $small-spacing;
&__text,
&__url {