Skip to content

Commit

Permalink
chore(test-studio): add playlist/playlistTrack schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Aug 15, 2022
1 parent cf1ce0d commit fd11603
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dev/test-studio/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import mux from './externalPlugins/mux'
import author from './author'
import book from './book'
import species from './species'
import playlist from './playlist'
import playlistTrack from './playlistTrack'

// CI documents
import conditionalFieldset from './ci/conditionalFieldset'
Expand Down Expand Up @@ -179,6 +181,8 @@ export const schemaTypes = [
// orderableCategoryDocumentType,
// orderableTagDocumentType,
manyEditors,
playlist,
playlistTrack,
poppers,
presence,
previewImageUrlTest,
Expand Down
31 changes: 31 additions & 0 deletions dev/test-studio/schema/playlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {defineType} from '@sanity/types'

export default defineType({
name: 'playlist',
title: 'Playlist',
type: 'document',
liveEdit: true,
fields: [
{
name: 'name',
title: 'Name',
type: 'string',
},
{
name: 'description',
title: 'Description',
type: 'text',
},
{
name: 'tracks',
title: 'Tracks',
type: 'array',
of: [{type: 'playlistTrack'}],
},
{
name: 'image',
title: 'Image',
type: 'image',
},
],
})
59 changes: 59 additions & 0 deletions dev/test-studio/schema/playlistTrack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {defineType} from 'sanity'

export default defineType({
name: 'playlistTrack',
title: 'Playlist track',
type: 'object',
fields: [
{
name: 'name',
title: 'Name',
type: 'string',
},
{
name: 'album',
title: 'Album',
type: 'string',
},
{
name: 'duration',
title: 'Duration (milliseconds)',
type: 'number',
readOnly: true,
},
{
name: 'albumImage',
title: 'Album image',
type: 'image',
},
],
preview: {
prepare(value) {
const {title, duration, album, media} = value
return {
title: `${title} (${formatDuration(duration)})`,
subtitle: album ? `Album: ${album}` : undefined,
media,
}
},
select: {
title: 'name',
album: 'album',
duration: 'duration',
media: 'albumImage',
},
},
})

export function formatDuration(dur: unknown): string {
if (typeof dur !== 'number') {
return 'unknown'
}

const seconds = (dur / 1000) % 60
const minutes = dur / 1000 / 60

return [minutes, seconds]
.map((num) => (num > 9 ? num.toFixed(0) : `0${num.toFixed(0)}`))
.join(':')
}

0 comments on commit fd11603

Please sign in to comment.