Skip to content

Commit

Permalink
fix: reduce listener calls with updated useListeningQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonGriggs committed Jun 12, 2023
1 parent 33af7cd commit 0d81952
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@sanity/ui": "^1.2.2",
"@sanity/uuid": "^3.0.1",
"sanity-plugin-internationalized-array": "^1.6.0",
"sanity-plugin-utils": "^1.6.1"
"sanity-plugin-utils": "^1.6.2"
},
"devDependencies": {
"@commitlint/cli": "^17.4.4",
Expand Down
5 changes: 3 additions & 2 deletions src/components/DocumentInternationalizationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useClickOutside,
} from '@sanity/ui'
import {uuid} from '@sanity/uuid'
import {FormEvent, useCallback, useMemo, useState} from 'react'
import {FormEvent, useCallback, useEffect, useMemo, useState} from 'react'
import {useEditState} from 'sanity'

import {useTranslationMetadata} from '../hooks/useLanguageMetadata'
Expand All @@ -24,7 +24,8 @@ import Warning from './Warning'
export function DocumentInternationalizationMenu(
props: DocumentInternationalizationMenuProps
) {
const {schemaType, documentId} = props
const {documentId} = props
const schemaType = props.schemaType.name
const {languageField, supportedLanguages} =
useDocumentInternationalizationContext()

Expand Down
17 changes: 6 additions & 11 deletions src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ export const documentInternationalization = definePlugin<PluginConfig>(

if (schemaTypes.length === 0) {
throw new Error(
'You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in te documentInternationalization() configuration.'
)
}

const renderLanguageFilter = (schemaType: string, documentId: string) => {
return (
<DocumentInternationalizationMenu
schemaType={schemaType}
documentId={documentId}
/>
'You must specify at least one schema type on which to enable document internationalization. Update the `schemaTypes` option in the documentInternationalization() configuration.'
)
}

Expand Down Expand Up @@ -96,7 +87,11 @@ export const documentInternationalization = definePlugin<PluginConfig>(
const {schemaType, documentId} = ctx

return schemaTypes.includes(schemaType) && documentId
? [...prev, () => renderLanguageFilter(schemaType, documentId)]
? [
...prev,
(props) =>
DocumentInternationalizationMenu({...props, documentId}),
]
: prev
},
badges: (prev, {schemaType}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
FieldDefinition,
KeyedObject,
ObjectSchemaType,
Reference,
SanityClient,
} from 'sanity'
Expand Down Expand Up @@ -43,6 +44,6 @@ export type Metadata = {
}

export type DocumentInternationalizationMenuProps = {
schemaType: string
schemaType: ObjectSchemaType
documentId: string
}

0 comments on commit 0d81952

Please sign in to comment.