-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56def19
commit a9002d7
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/components/Attachment/hooks/useLiveLocationSharingManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { LiveLocationManager } from 'stream-chat'; | ||
import type { LiveLocationManagerConstructorParameters } from 'stream-chat'; | ||
import { useEffect, useMemo } from 'react'; | ||
|
||
type PartialKeys<T, K extends keyof T> = { | ||
[L in keyof T]: L extends K ? T[L] | undefined : T[L]; | ||
}; | ||
|
||
export const useLiveLocationSharingManager = ({ | ||
client, | ||
retrieveAndDeserialize, | ||
serializeAndStore, | ||
watchLocation, | ||
}: PartialKeys<LiveLocationManagerConstructorParameters, 'client'>) => { | ||
const manager = useMemo(() => { | ||
if (!client) return null; | ||
|
||
return new LiveLocationManager({ | ||
client, | ||
retrieveAndDeserialize, | ||
serializeAndStore, | ||
watchLocation, | ||
}); | ||
}, [client, retrieveAndDeserialize, serializeAndStore, watchLocation]); | ||
|
||
useEffect(() => { | ||
if (!manager) return; | ||
|
||
manager.registerSubscriptions(); | ||
|
||
return () => manager.unregisterSubscriptions(); | ||
}, [manager]); | ||
|
||
return manager; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters