-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Geolocation attachment
1 parent
06b3bd3
commit 3b8f2e1
Showing
5 changed files
with
88 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import type { Attachment, DefaultGenerics, ExtendableGenerics } from 'stream-chat'; | ||
import { useChatContext, useMessageContext } from '../../context'; | ||
|
||
export const Geolocation = <SCG extends ExtendableGenerics = DefaultGenerics>({ | ||
attachment, | ||
}: { | ||
attachment: Attachment<SCG>; | ||
}) => { | ||
const { channel } = useChatContext(); | ||
const { isMyMessage, message } = useMessageContext(); | ||
|
||
const stoppedSharing = !!attachment.stopped_sharing; | ||
const expired: boolean = | ||
typeof attachment.end_time === 'string' && Date.now() > new Date(attachment.end_time).getTime(); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: 10, | ||
paddingBlock: 15, | ||
paddingInline: 10, | ||
width: 'auto', | ||
}} | ||
> | ||
{attachment.type === 'live_location' && !stoppedSharing && !expired && isMyMessage() && ( | ||
<button | ||
onClick={() => | ||
channel?.stopLiveLocationSharing({ | ||
attachments: message.attachments, | ||
id: message.id, | ||
type: message.type, | ||
}) | ||
} | ||
> | ||
Stop sharing | ||
</button> | ||
)} | ||
{/* TODO: {MAP} */} | ||
<span> | ||
lat: {attachment.latitude}, lng: {attachment.longitude} | ||
</span> | ||
{(stoppedSharing || expired) && <span style={{ fontSize: 12 }}>Location sharing ended</span>} | ||
</div> | ||
); | ||
}; |
18 changes: 10 additions & 8 deletions
18
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