-
Notifications
You must be signed in to change notification settings - Fork 2
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
cb7299c
commit d37f98c
Showing
19 changed files
with
731 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
64 changes: 64 additions & 0 deletions
64
demo/src/components/MessageReactions/MessageReactionsMany.tsx
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,64 @@ | ||
import React from 'react'; | ||
import { Message, ReactionRefType } from '@ably/chat'; | ||
|
||
interface MessageReactionsManyProps { | ||
message: Message; | ||
onReactionAdd: (message: Message, refType: ReactionRefType, emoji: string, score?: number) => void; | ||
onReactionRemove: (message: Message, refType: ReactionRefType, emoji: string) => void; | ||
} | ||
|
||
const emojis = ['👍', '❤️', '🔥', '🚀']; | ||
|
||
export const MessageReactionsMany: React.FC<MessageReactionsManyProps> = ({ | ||
message, | ||
onReactionAdd, | ||
onReactionRemove, | ||
}) => { | ||
const handleReactionClick = (emoji: string) => { | ||
onReactionAdd(message, ReactionRefType.Many, emoji); | ||
}; | ||
|
||
const handleReactionRemoveClick = (emoji: string) => { | ||
onReactionRemove(message, ReactionRefType.Many, emoji); | ||
}; | ||
|
||
const currentEmojis = emojis.slice(); | ||
if (message.reactions.many) { | ||
for (const emoji in message.reactions.many) { | ||
if (!currentEmojis.includes(emoji)) { | ||
currentEmojis.push(emoji); | ||
} | ||
} | ||
} | ||
|
||
const many = message.reactions.many ?? {}; | ||
|
||
|
||
console.log("current emojis", currentEmojis) | ||
return ( | ||
<> | ||
hello | ||
{currentEmojis.map((emoji) => ( | ||
<button | ||
key={emoji} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
if (e.type === 'contextmenu') { | ||
console.log("about to remove via onClick") | ||
handleReactionRemoveClick(emoji); | ||
} else { | ||
handleReactionClick(emoji); | ||
} | ||
}} | ||
onContextMenu={(e) => { | ||
e.preventDefault(); | ||
console.log("about to remove via right click onmenu") | ||
handleReactionRemoveClick(emoji); | ||
}} | ||
> | ||
{emoji} ({many[emoji]?.total || 0}) | ||
</button> | ||
))} | ||
</> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
demo/src/components/MessageReactions/MessageReactionsSingle.tsx
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,53 @@ | ||
import React from 'react'; | ||
import { Message, ReactionRefType } from '@ably/chat'; | ||
|
||
interface MessageReactionsSingleProps { | ||
message: Message; | ||
clientId: string; | ||
onReactionAdd: (message: Message, refType: ReactionRefType, emoji: string, score?: number) => void; | ||
onReactionRemove: (message: Message, refType: ReactionRefType, emoji: string) => void; | ||
} | ||
|
||
const emojis = ['👍', '❤️', '🔥', '🚀']; | ||
|
||
export const MessageReactionsSingle: React.FC<MessageReactionsSingleProps> = ({ | ||
message, | ||
clientId, | ||
onReactionAdd, | ||
onReactionRemove, | ||
}) => { | ||
const single = message.reactions.single ?? {}; | ||
|
||
const handleReactionClick = (emoji: string) => { | ||
if (single[emoji]?.clientIds.includes(clientId)) { | ||
onReactionRemove(message, ReactionRefType.Single, emoji); | ||
} else { | ||
onReactionAdd(message, ReactionRefType.Single, emoji); | ||
} | ||
}; | ||
|
||
const currentEmojis = emojis.slice(); | ||
if (message.reactions.single) { | ||
for (const emoji in message.reactions.single) { | ||
if (!currentEmojis.includes(emoji)) { | ||
currentEmojis.push(emoji); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{currentEmojis.map((emoji) => ( | ||
<button | ||
key={emoji} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
handleReactionClick(emoji); | ||
}} | ||
> | ||
{emoji} ({single[emoji]?.total || 0}) | ||
</button> | ||
))} | ||
</> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
demo/src/components/MessageReactions/MessageReactionsUnique.tsx
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,53 @@ | ||
import React from 'react'; | ||
import { Message, ReactionRefType } from '@ably/chat'; | ||
|
||
interface MessageReactionsUniqueProps { | ||
message: Message; | ||
clientId: string; | ||
onReactionAdd: (message: Message, refType: ReactionRefType, emoji: string, score?: number) => void; | ||
onReactionRemove: (message: Message, refType: ReactionRefType, emoji: string) => void; | ||
} | ||
|
||
const emojis = ['👍', '❤️', '🔥', '🚀']; | ||
|
||
export const MessageReactionsUnique: React.FC<MessageReactionsUniqueProps> = ({ | ||
message, | ||
clientId, | ||
onReactionAdd, | ||
onReactionRemove, | ||
}) => { | ||
const unique = message.reactions.unique ?? {}; | ||
|
||
const handleReactionClick = (emoji: string) => { | ||
if (unique[emoji]?.clientIds.includes(clientId)) { | ||
onReactionRemove(message, ReactionRefType.Unique, emoji); | ||
} else { | ||
onReactionAdd(message, ReactionRefType.Unique, emoji); | ||
} | ||
}; | ||
|
||
const currentEmojis = emojis.slice(); | ||
if (unique) { | ||
for (const emoji in unique) { | ||
if (!currentEmojis.includes(emoji)) { | ||
currentEmojis.push(emoji); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{currentEmojis.map((emoji) => ( | ||
<button | ||
key={emoji} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
handleReactionClick(emoji); | ||
}} | ||
> | ||
{emoji} ({unique[emoji]?.total || 0}) | ||
</button> | ||
))} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.