@comapeo/core-react 7.1.0 → 7.2.0

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.
@@ -1,4 +1,5 @@
1
1
  import type { BlobApi, IconApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
+ import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with { 'resolution-mode': 'import' };
2
3
  import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
3
4
  import { type SyncState } from '../lib/sync.js';
4
5
  /**
@@ -531,15 +532,31 @@ export declare function useRemoveMember({ projectId }: {
531
532
  * It is necessary to use this if you want the project role-related read hooks to update
532
533
  * based on role change events that are received in the background.
533
534
  *
535
+ * @param opts.listener Optional listener to invoke when role changes
536
+ *
534
537
  * @example
535
538
  * ```tsx
536
539
  * function SomeComponent({ projectId }: { projectId: string }) {
537
540
  * useProjectOwnRoleChangeListener({ projectId })
538
541
  * }
539
542
  * ```
543
+ *
544
+ * @example
545
+ * ```tsx
546
+ * function ComponentWithListener({ projectId }: { projectId: string }) {
547
+ * useProjectOwnRoleChangeListener({
548
+ * projectId,
549
+ * listener: (event) => {
550
+ * // Handle role change, e.g., navigate to default project
551
+ * console.log('New role:', event.role)
552
+ * }
553
+ * })
554
+ * }
555
+ * ```
540
556
  */
541
- export declare function useProjectOwnRoleChangeListener({ projectId, }: {
557
+ export declare function useProjectOwnRoleChangeListener({ projectId, listener, }: {
542
558
  projectId: string;
559
+ listener?: (event: RoleChangeEvent) => void;
543
560
  }): void;
544
561
  /**
545
562
  * Create a blob for a project.
@@ -446,14 +446,29 @@ function useRemoveMember({ projectId }) {
446
446
  * It is necessary to use this if you want the project role-related read hooks to update
447
447
  * based on role change events that are received in the background.
448
448
  *
449
+ * @param opts.listener Optional listener to invoke when role changes
450
+ *
449
451
  * @example
450
452
  * ```tsx
451
453
  * function SomeComponent({ projectId }: { projectId: string }) {
452
454
  * useProjectOwnRoleChangeListener({ projectId })
453
455
  * }
454
456
  * ```
457
+ *
458
+ * @example
459
+ * ```tsx
460
+ * function ComponentWithListener({ projectId }: { projectId: string }) {
461
+ * useProjectOwnRoleChangeListener({
462
+ * projectId,
463
+ * listener: (event) => {
464
+ * // Handle role change, e.g., navigate to default project
465
+ * console.log('New role:', event.role)
466
+ * }
467
+ * })
468
+ * }
469
+ * ```
455
470
  */
456
- function useProjectOwnRoleChangeListener({ projectId, }) {
471
+ function useProjectOwnRoleChangeListener({ projectId, listener, }) {
457
472
  const queryClient = (0, react_query_1.useQueryClient)();
458
473
  const { data: projectApi } = useSingleProject({ projectId });
459
474
  (0, react_1.useEffect)(() => {
@@ -470,6 +485,16 @@ function useProjectOwnRoleChangeListener({ projectId, }) {
470
485
  projectApi.removeListener('own-role-change', invalidateCache);
471
486
  };
472
487
  }, [projectApi, queryClient, projectId]);
488
+ (0, react_1.useEffect)(() => {
489
+ if (listener) {
490
+ projectApi.addListener('own-role-change', listener);
491
+ }
492
+ return () => {
493
+ if (listener) {
494
+ projectApi.removeListener('own-role-change', listener);
495
+ }
496
+ };
497
+ }, [projectApi, listener]);
473
498
  }
474
499
  /**
475
500
  * Create a blob for a project.
@@ -1,4 +1,5 @@
1
1
  import type { BlobApi, IconApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
+ import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with { 'resolution-mode': 'import' };
2
3
  import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
3
4
  import { type SyncState } from '../lib/sync.js';
4
5
  /**
@@ -531,15 +532,31 @@ export declare function useRemoveMember({ projectId }: {
531
532
  * It is necessary to use this if you want the project role-related read hooks to update
532
533
  * based on role change events that are received in the background.
533
534
  *
535
+ * @param opts.listener Optional listener to invoke when role changes
536
+ *
534
537
  * @example
535
538
  * ```tsx
536
539
  * function SomeComponent({ projectId }: { projectId: string }) {
537
540
  * useProjectOwnRoleChangeListener({ projectId })
538
541
  * }
539
542
  * ```
543
+ *
544
+ * @example
545
+ * ```tsx
546
+ * function ComponentWithListener({ projectId }: { projectId: string }) {
547
+ * useProjectOwnRoleChangeListener({
548
+ * projectId,
549
+ * listener: (event) => {
550
+ * // Handle role change, e.g., navigate to default project
551
+ * console.log('New role:', event.role)
552
+ * }
553
+ * })
554
+ * }
555
+ * ```
540
556
  */
541
- export declare function useProjectOwnRoleChangeListener({ projectId, }: {
557
+ export declare function useProjectOwnRoleChangeListener({ projectId, listener, }: {
542
558
  projectId: string;
559
+ listener?: (event: RoleChangeEvent) => void;
543
560
  }): void;
544
561
  /**
545
562
  * Create a blob for a project.
@@ -415,14 +415,29 @@ export function useRemoveMember({ projectId }) {
415
415
  * It is necessary to use this if you want the project role-related read hooks to update
416
416
  * based on role change events that are received in the background.
417
417
  *
418
+ * @param opts.listener Optional listener to invoke when role changes
419
+ *
418
420
  * @example
419
421
  * ```tsx
420
422
  * function SomeComponent({ projectId }: { projectId: string }) {
421
423
  * useProjectOwnRoleChangeListener({ projectId })
422
424
  * }
423
425
  * ```
426
+ *
427
+ * @example
428
+ * ```tsx
429
+ * function ComponentWithListener({ projectId }: { projectId: string }) {
430
+ * useProjectOwnRoleChangeListener({
431
+ * projectId,
432
+ * listener: (event) => {
433
+ * // Handle role change, e.g., navigate to default project
434
+ * console.log('New role:', event.role)
435
+ * }
436
+ * })
437
+ * }
438
+ * ```
424
439
  */
425
- export function useProjectOwnRoleChangeListener({ projectId, }) {
440
+ export function useProjectOwnRoleChangeListener({ projectId, listener, }) {
426
441
  const queryClient = useQueryClient();
427
442
  const { data: projectApi } = useSingleProject({ projectId });
428
443
  useEffect(() => {
@@ -439,6 +454,16 @@ export function useProjectOwnRoleChangeListener({ projectId, }) {
439
454
  projectApi.removeListener('own-role-change', invalidateCache);
440
455
  };
441
456
  }, [projectApi, queryClient, projectId]);
457
+ useEffect(() => {
458
+ if (listener) {
459
+ projectApi.addListener('own-role-change', listener);
460
+ }
461
+ return () => {
462
+ if (listener) {
463
+ projectApi.removeListener('own-role-change', listener);
464
+ }
465
+ };
466
+ }, [projectApi, listener]);
442
467
  }
443
468
  /**
444
469
  * Create a blob for a project.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comapeo/core-react",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "React wrapper for working with @comapeo/core",
5
5
  "repository": {
6
6
  "type": "git",