@sanity/sdk-react 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +60 -9
- package/dist/index.js +145 -77
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/_exports/sdk-react.ts +2 -0
- package/src/components/auth/AuthBoundary.test.tsx +30 -19
- package/src/components/auth/AuthBoundary.tsx +6 -3
- package/src/components/auth/LoginError.tsx +13 -5
- package/src/context/ComlinkTokenRefresh.test.tsx +221 -0
- package/src/context/ComlinkTokenRefresh.tsx +125 -0
- package/src/hooks/dashboard/useDashboardNavigate.test.ts +44 -0
- package/src/hooks/dashboard/useDashboardNavigate.ts +60 -0
- package/src/hooks/dashboard/useManageFavorite.ts +1 -3
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +1 -3
- package/src/hooks/dashboard/useRecordDocumentHistoryEvent.ts +1 -3
|
@@ -44,20 +44,18 @@ interface UseManageFavoriteProps extends DocumentHandle {
|
|
|
44
44
|
* - `favorite` - Function to add document to favorites
|
|
45
45
|
* - `unfavorite` - Function to remove document from favorites
|
|
46
46
|
* - `isFavorited` - Boolean indicating if document is currently favorited
|
|
47
|
-
* - `isConnected` - Boolean indicating if connection to Dashboard UI is established
|
|
48
47
|
*
|
|
49
48
|
* @example
|
|
50
49
|
* ```tsx
|
|
51
50
|
* function FavoriteButton(props: DocumentActionProps) {
|
|
52
51
|
* const {documentId, documentType} = props
|
|
53
|
-
* const {favorite, unfavorite, isFavorited
|
|
52
|
+
* const {favorite, unfavorite, isFavorited} = useManageFavorite({
|
|
54
53
|
* documentId,
|
|
55
54
|
* documentType
|
|
56
55
|
* })
|
|
57
56
|
*
|
|
58
57
|
* return (
|
|
59
58
|
* <Button
|
|
60
|
-
* disabled={!isConnected}
|
|
61
59
|
* onClick={() => isFavorited ? unfavorite() : favorite()}
|
|
62
60
|
* text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
|
|
63
61
|
* />
|
|
@@ -33,7 +33,6 @@ export interface NavigateToStudioResult {
|
|
|
33
33
|
* studios with the same projectId and dataset
|
|
34
34
|
* @returns An object containing:
|
|
35
35
|
* - `navigateToStudioDocument` - Function that when called will navigate to the studio document
|
|
36
|
-
* - `isConnected` - Boolean indicating if connection to Dashboard is established
|
|
37
36
|
*
|
|
38
37
|
* @example
|
|
39
38
|
* ```tsx
|
|
@@ -42,10 +41,9 @@ export interface NavigateToStudioResult {
|
|
|
42
41
|
* import {Suspense} from 'react'
|
|
43
42
|
*
|
|
44
43
|
* function NavigateButton({documentHandle}: {documentHandle: DocumentHandle}) {
|
|
45
|
-
* const {navigateToStudioDocument
|
|
44
|
+
* const {navigateToStudioDocument} = useNavigateToStudioDocument(documentHandle)
|
|
46
45
|
* return (
|
|
47
46
|
* <Button
|
|
48
|
-
* disabled={!isConnected}
|
|
49
47
|
* onClick={navigateToStudioDocument}
|
|
50
48
|
* text="Navigate to Studio Document"
|
|
51
49
|
* />
|
|
@@ -36,7 +36,6 @@ interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
|
|
|
36
36
|
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
37
37
|
* @returns An object containing:
|
|
38
38
|
* - `recordEvent` - Function to record document interactions
|
|
39
|
-
* - `isConnected` - Boolean indicating if connection to Studio is established
|
|
40
39
|
*
|
|
41
40
|
* @example
|
|
42
41
|
* ```tsx
|
|
@@ -46,7 +45,7 @@ interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
|
|
|
46
45
|
*
|
|
47
46
|
* function RecordEventButton(props: DocumentActionProps) {
|
|
48
47
|
* const {documentId, documentType, resourceType, resourceId} = props
|
|
49
|
-
* const {recordEvent
|
|
48
|
+
* const {recordEvent} = useRecordDocumentHistoryEvent({
|
|
50
49
|
* documentId,
|
|
51
50
|
* documentType,
|
|
52
51
|
* resourceType,
|
|
@@ -54,7 +53,6 @@ interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
|
|
|
54
53
|
* })
|
|
55
54
|
* return (
|
|
56
55
|
* <Button
|
|
57
|
-
* disabled={!isConnected}
|
|
58
56
|
* onClick={() => recordEvent('viewed')}
|
|
59
57
|
* text="Viewed"
|
|
60
58
|
* />
|