Skip to content

Commit

Permalink
refactor(sanity): use speakingurl instead of toSlug
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Jul 1, 2024
1 parent 3006467 commit a09593d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
TextInput,
} from '@sanity/ui'
import {useCallback, useState} from 'react'
import speakingurl from 'speakingurl'

import {type Bundle} from '../../types'
import {RANDOM_TONES} from '../../util/const'
import {isDraftOrPublished, toSlug} from '../../util/dummyGetters'
import {isDraftOrPublished} from '../../util/dummyGetters'

export function BundleForm(props: {
onChange: (params: Bundle) => void
Expand All @@ -36,7 +37,7 @@ export function BundleForm(props: {
setShowTitleValidation(false)
}

onChange({...value, title: title, name: toSlug(title)})
onChange({...value, title: title, name: speakingurl(title)})
},
[onChange, value],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function DocumentVersionMenu(props: {

/*// search
const [addVersionTitle, setAddVersionTitle] = useState('')
const addVersionName = toSlug(addVersionTitle)
const addVersionName = speakingurl(addVersionTitle)
// use to prevent adding a version when you're already in that version
const addVersionExists = BUNDLES.some((r) => r.name.toLocaleLowerCase() === addVersionName)
Expand Down Expand Up @@ -76,7 +76,7 @@ export function DocumentVersionMenu(props: {
const handleAddVersion = useCallback(
(versionName: string) => () => {
const nameSlugged = toSlug(versionName)
const nameSlugged = speakingurl(versionName)
// only add to version if there isn't already a version in that bundle of this doc
if (versionDocumentExists(documentVersions, versionName)) {
Expand Down
10 changes: 3 additions & 7 deletions packages/sanity/src/core/versions/util/dummyGetters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {camelCase} from 'lodash'
import {type SanityClient, type SanityDocument} from 'sanity'
import speakingurl from 'speakingurl'

import {type Version} from '../types'
import {BUNDLES} from './const'
Expand Down Expand Up @@ -27,7 +27,7 @@ export async function getAllVersionsOfDocument(
const sluggedName = getVersionName(doc._id)
const bundle = BUNDLES.find((b) => b.name === sluggedName)
return {
name: toSlug(sluggedName),
name: speakingurl(sluggedName),
title: bundle?.title || sluggedName,
tone: bundle?.tone || 'default',
icon: bundle?.icon || 'cube',
Expand All @@ -46,10 +46,6 @@ export function versionDocumentExists(documentVersions: Version[], name: string)
return documentVersions.some((version) => version.name === name)
}

export function toSlug(value: string): string {
return camelCase(value)
}

export function isDraftOrPublished(versionName: string): boolean {
return toSlug(versionName) === 'drafts' || toSlug(versionName) === 'published'
return speakingurl(versionName) === 'drafts' || speakingurl(versionName) === 'published'
}

0 comments on commit a09593d

Please sign in to comment.