Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Use defineComponent, add prop types and emit types (#1480)
Browse files Browse the repository at this point in the history
* Use `defineComponent`, add prop types and emit types
* Add more files to tsconfig
* Remove changes that cannot be added to tsconfig
  • Loading branch information
obulat authored Jun 28, 2022
1 parent 01831a5 commit f929743
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 61 deletions.
13 changes: 10 additions & 3 deletions src/components/VAllResultsGrid/VAudioCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
<VAudioTrack :audio="audio" layout="box" />
</template>

<script>
import { defineComponent } from '@vue/composition-api'
<script lang="ts">
import { defineComponent, PropType } from '@nuxtjs/composition-api'
import type { AudioDetail } from '~/models/media'
import VAudioTrack from '~/components/VAudioTrack/VAudioTrack.vue'
export default defineComponent({
components: { VAudioTrack },
props: ['audio'],
props: {
audio: {
type: Object as PropType<AudioDetail>,
required: true,
},
},
})
</script>
3 changes: 1 addition & 2 deletions src/components/VErrorSection/VErrorImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'
import type { License, LicenseVersion } from '~/constants/license'
import { ErrorCode, errorCodes } from '~/constants/errors'
import type { ErrorCode } from '~/constants/errors'
import { AttributableMedia, getAttribution } from '~/utils/attribution-html'
import { useI18n } from '~/composables/use-i18n'
Expand All @@ -40,7 +40,6 @@ export default defineComponent({
errorCode: {
type: String as PropType<ErrorCode>,
required: true,
validator: (val: ErrorCode) => errorCodes.includes(val),
},
},
setup(props) {
Expand Down
14 changes: 9 additions & 5 deletions src/components/VFilters/VLicenseExplanation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
</div>
</template>

<script>
import { isLicense, getLicenseUrl } from '~/utils/license'
<script lang="ts">
import { defineComponent, PropType } from '@nuxtjs/composition-api'
import { getLicenseUrl, isLicense } from '~/utils/license'
import type { License } from '~/constants/license'
import VLicenseElements from '~/components/VLicense/VLicenseElements.vue'
import VLink from '~/components/VLink.vue'
Expand All @@ -45,7 +49,7 @@ import VLink from '~/components/VLink.vue'
* Renders the explanation of the license passed to it by breaking it down to
* its constituent clauses.
*/
export default {
export default defineComponent({
name: 'VLicenseExplanation',
components: {
VLicenseElements,
Expand All @@ -56,7 +60,7 @@ export default {
* the code of the license whose elements need to be explained
*/
license: {
type: String,
type: String as PropType<License>,
required: true,
},
},
Expand All @@ -66,5 +70,5 @@ export default {
getLicenseUrl,
}
},
}
})
</script>
3 changes: 1 addition & 2 deletions src/components/VLicense/VLicense.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<script lang="ts">
import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'
import { ALL_LICENSES, License, LICENSE_ICONS } from '~/constants/license'
import { License, LICENSE_ICONS } from '~/constants/license'
import { getFullLicenseName, getElements } from '~/utils/license'
import { useI18n } from '~/composables/use-i18n'
Expand All @@ -40,7 +40,6 @@ export default defineComponent({
license: {
type: String as PropType<License>,
required: true,
validator: (val: License) => ALL_LICENSES.includes(val as License),
},
/**
* Whether to display icons filled with a white background or leave them transparent.
Expand Down
4 changes: 1 addition & 3 deletions src/components/VLicense/VLicenseElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'
import type { License } from '~/constants/license'
import { ALL_LICENSES, LICENSE_ICONS } from '~/constants/license'
import { LICENSE_ICONS } from '~/constants/license'
import { getElements } from '~/utils/license'
Expand All @@ -41,15 +41,13 @@ export default defineComponent({
license: {
type: String as PropType<License>,
required: true,
validator: (val: License) => ALL_LICENSES.includes(val),
},
/**
* the size of the icons and text
*/
size: {
type: String as PropType<'big' | 'small'>,
default: 'big',
validator: (val: 'big' | 'small') => ['big', 'small'].includes(val),
},
},
setup(props) {
Expand Down
13 changes: 0 additions & 13 deletions src/components/VLogoLoader/VLogoLoader.types.js

This file was deleted.

17 changes: 12 additions & 5 deletions src/components/VLogoLoader/VLogoLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,23 @@
</svg>
</template>

<script>
import { defineComponent } from '@nuxtjs/composition-api'
<script lang="ts">
import { defineComponent, PropType } from '@nuxtjs/composition-api'
import { useReducedMotion } from '~/composables/use-media-query'
import { propTypes } from './VLogoLoader.types'
export default defineComponent({
name: 'VLogoLoader',
props: propTypes,
props: {
status: {
type: String as PropType<'loading' | 'idle'>,
default: 'idle',
},
autoResize: {
type: Boolean,
default: true,
},
},
setup() {
const prefersReducedMotion = useReducedMotion()
Expand Down
8 changes: 5 additions & 3 deletions src/components/VMediaTag/VMediaTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
</Component>
</template>

<script>
<script lang="ts">
/**
* Displays a tag associated with a media item. If set up as a link, it can be
* used as a link to find other items that are similarly tagged.
*/
export default {
import { defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
name: 'MediaTag',
props: {
/**
Expand All @@ -26,5 +28,5 @@ export default {
default: 'span',
},
},
}
})
</script>
8 changes: 5 additions & 3 deletions src/components/VSkeleton/VAudioTrackSkeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
</article>
</template>

<script>
export default {
<script lang="ts">
import { defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
name: 'VAudioTrackSkeleton',
methods: {
getRandomSize(max = 250, min = 70) {
return Math.floor(Math.random() * (max - min) + min)
},
},
}
})
</script>

<style scoped>
Expand Down
8 changes: 5 additions & 3 deletions src/components/VSkeleton/VBone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<div :class="['bg-dark-charcoal-10', shimmer ? 'shimmering' : '']" />
</template>

<script>
export default {
<script lang="ts">
import { defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
name: 'VBone',
props: { shimmer: { type: Boolean, default: true } },
}
})
</script>

<style scoped>
Expand Down
13 changes: 8 additions & 5 deletions src/components/VSkeleton/VGridSkeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@
</section>
</template>

<script>
<script lang="ts">
/**
* Display placeholder elements while waiting for the actual elements to be
* loaded in the results views.
*/
import { defineComponent, PropType } from '@nuxtjs/composition-api'
import type { SupportedSearchType } from '~/constants/media'
import VAudioTrackSkeleton from '~/components/VSkeleton/VAudioTrackSkeleton.vue'
import VBone from '~/components/VSkeleton/VBone.vue'
export default {
export default defineComponent({
name: 'VGridSkeleton',
components: { VAudioTrackSkeleton, VBone },
props: {
isForTab: {
type: String,
type: String as PropType<SupportedSearchType>,
default: 'image',
validator: (val) => ['all', 'image', 'audio'].includes(val),
},
numElems: {
type: Number,
Expand All @@ -55,7 +58,7 @@ export default {
return { getRandomSize }
},
}
})
</script>

<style scoped>
Expand Down
34 changes: 20 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"test/proxy.js",
"src/components/VButton.vue",
"src/components/VContentPage.vue",
"src/components/VMetaSearch/*.vue",
"src/components/VLicenseElements.vue",
"src/components/VWarningSuppressor.vue",
"src/components/VLink.vue",
Expand All @@ -50,23 +49,30 @@
"src/components/VBackToSearchResultsLink.vue",
"src/components/VSourcesTable.vue",
"src/components/TableSortIcon.vue",
"src/components/VIcon/VIcon.vue",
"src/components/VCheckbox/VCheckbox.vue",
"src/components/VIconButton/VIconButton.vue",
"src/components/VLicense/VLicense.vue",
"src/components/VContentLink/VContentLink.vue",
"src/components/VCopyButton.vue",
"src/components/VSketchFabViewer.vue",
"src/components/VAudioThumbnail/**.vue",
"src/components/VAudioTrack/**/*.vue",
"src/components/VCheckbox/**.vue",
"src/components/VGlobalAudioSection/**.vue",
"src/components/VIcon/**.vue",
"src/components/VIconButton/**.vue",
"src/components/VLicense/**.vue",
"src/components/VLogoLoader/**.vue",
"src/components/VMediaInfo/**.vue",
"src/components/VMediaTag/**.vue",
"src/components/VMetaSearch/*.vue",
"src/components/VSkeleton/**.vue",
"src/components/VTabs/**.vue",
"src/components/VAllResultsGrid/VAudioCell.vue",
"src/components/VContentLink/**.vue",
"src/components/VContentReport/VReportDescForm.vue",
"src/components/VErrorSection/VErrorImage.vue",
"src/components/VAudioTrack/**/*.vue",
"src/components/VAudioThumbnail/VAudioThumbnail.vue",
"src/components/VGlobalAudioSection/VGlobalAudioSection.vue",
"src/components/VInputField/VInputField.vue",
"src/components/VHeader/VFilterButton.vue",
"src/components/VHeader/VSearchBar/VSearchBar.vue",
"src/components/VTabs/**.vue",
"src/components/VCopyButton.vue",
"src/components/VMediaInfo/**.vue",
"src/components/VSketchFabViewer.vue",
"src/components/VInputField/VInputField.vue",
"src/components/VErrorSection/VErrorImage.vue",
"src/components/VFilters/VLicenseExplanation.vue",
"src/pages/feedback.vue",
"src/pages/search-help.vue",
"src/pages/extension.vue",
Expand Down

0 comments on commit f929743

Please sign in to comment.