Skip to content

Commit d8c0e35

Browse files
authored
Merge pull request #7200 from LibreSign/backport/7198/stable32
[stable32] refactor(vue3): migrate FilesList to script setup ts
2 parents 7c6ac41 + 9d3ef6d commit d8c0e35

42 files changed

Lines changed: 5177 additions & 2935 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/components/PreviewSignature/PreviewSignature.vue

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,87 +18,103 @@
1818
</div>
1919
</template>
2020

21-
<script>
21+
<script setup lang="ts">
2222
import { t } from '@nextcloud/l10n'
2323
2424
import axios from '@nextcloud/axios'
2525
import { getCapabilities } from '@nextcloud/capabilities'
26+
import { onMounted, ref, watch } from 'vue'
2627
2728
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
2829
29-
export default {
30+
type AxiosImageResponse = {
31+
data: ArrayBuffer | string
32+
headers: {
33+
'content-type': string
34+
}
35+
}
36+
37+
type AxiosConfig = {
38+
url: string
39+
method: 'get'
40+
responseType: 'arraybuffer'
41+
headers?: Record<string, string>
42+
}
43+
44+
defineOptions({
3045
name: 'PreviewSignature',
31-
emits: ['loaded'],
32-
components: {
33-
NcLoadingIcon,
34-
},
35-
props: {
36-
src: {
37-
type: String,
38-
default: () => '',
39-
required: true,
40-
},
41-
signRequestUuid: {
42-
type: String,
43-
required: false,
44-
default: '',
45-
},
46-
alt: {
47-
type: String,
48-
required: false,
49-
// TRANSLATORS Alt text for an image showing the user's handwritten, typed, or uploaded signature. Used as fallback when the parent component does not pass a more specific description, for example "Current signature" or "Confirm your initials".
50-
default: () => t('libresign', 'Signature preview'),
51-
},
52-
},
53-
data() {
54-
return {
55-
loading: true,
56-
isLoaded: false,
57-
imageData: '',
58-
width: getCapabilities().libresign.config['sign-elements'].width,
59-
height: getCapabilities().libresign.config['sign-elements'].height,
46+
})
47+
48+
const props = withDefaults(defineProps<{
49+
src: string
50+
signRequestUuid?: string
51+
alt?: string
52+
}>(), {
53+
signRequestUuid: '',
54+
alt: () => t('libresign', 'Signature preview'),
55+
})
56+
57+
const emit = defineEmits<{
58+
(e: 'loaded', status: boolean | Event): void
59+
}>()
60+
61+
const loading = ref(true)
62+
const isLoaded = ref(false)
63+
const imageData = ref('')
64+
const width = ref(getCapabilities().libresign.config['sign-elements'].width)
65+
const height = ref(getCapabilities().libresign.config['sign-elements'].height)
66+
67+
async function loadImage() {
68+
if (props.src.startsWith('data:')) {
69+
imageData.value = props.src
70+
return
71+
}
72+
73+
const config: AxiosConfig = {
74+
url: props.src,
75+
method: 'get',
76+
responseType: 'arraybuffer',
77+
}
78+
if (props.signRequestUuid !== '') {
79+
config.headers = {
80+
'libresign-sign-request-uuid': props.signRequestUuid,
6081
}
61-
},
62-
watch: {
63-
src() {
64-
this.loadImage()
65-
},
66-
},
67-
mounted() {
68-
this.loadImage()
69-
},
70-
methods: {
71-
t,
72-
async loadImage() {
73-
if (this.src.startsWith('data:')) {
74-
this.imageData = this.src
75-
return
76-
}
77-
const config = {
78-
url: this.src,
79-
method: 'get',
80-
responseType: 'arraybuffer',
81-
}
82-
if (this.signRequestUuid !== '') {
83-
config.headers = {
84-
'libresign-sign-request-uuid': this.signRequestUuid,
85-
}
86-
}
87-
await axios(config)
88-
.then(response => {
89-
const buffer = Buffer.from(response.data, 'binary').toString('base64')
90-
this.imageData = 'data:' + response.headers['content-type'] + ';base64,' + buffer
91-
this.onImageLoad(true)
92-
})
93-
.catch(() => this.onImageLoad(false))
94-
},
95-
onImageLoad(status) {
96-
this.loading = false
97-
this.isLoaded = true
98-
this.$emit('loaded', status)
99-
},
100-
},
82+
}
83+
84+
try {
85+
const response = await axios(config) as AxiosImageResponse
86+
const buffer = Buffer.from(response.data, 'binary').toString('base64')
87+
imageData.value = `data:${response.headers['content-type']};base64,${buffer}`
88+
onImageLoad(true)
89+
} catch {
90+
onImageLoad(false)
91+
}
10192
}
93+
94+
function onImageLoad(status: boolean | Event) {
95+
loading.value = false
96+
isLoaded.value = true
97+
emit('loaded', status)
98+
}
99+
100+
watch(() => props.src, () => {
101+
void loadImage()
102+
})
103+
104+
onMounted(() => {
105+
void loadImage()
106+
})
107+
108+
defineExpose({
109+
t,
110+
loading,
111+
isLoaded,
112+
imageData,
113+
width,
114+
height,
115+
loadImage,
116+
onImageLoad,
117+
})
102118
</script>
103119

104120
<style lang="scss" scoped>

0 commit comments

Comments
 (0)