-
Notifications
You must be signed in to change notification settings - Fork 15
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
184cc06
commit fb9e564
Showing
9 changed files
with
106 additions
and
122 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
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,32 @@ | ||
import useSWR from 'swr'; | ||
import { useSelector } from './useRedux'; | ||
import defaultEmoji from '../utils/emojiShortcodes'; | ||
import { useMemo } from 'react'; | ||
|
||
type ServerEmote = { | ||
name: string, | ||
url: string, | ||
}; | ||
|
||
function useEmotes() { | ||
const { data: serverEmotes } = useSWR<ServerEmote[]>('/emotes', async (url: string) => { | ||
const response = await fetch(url); | ||
const { data } = await response.json(); | ||
return data; | ||
}, { | ||
revalidateOnFocus: false, | ||
fallbackData: [], | ||
}); | ||
|
||
const configEmoji = useSelector((state) => state.config.emoji); | ||
|
||
const emotes: Record<string, string> = useMemo(() => ({ | ||
...defaultEmoji, | ||
...configEmoji, | ||
...Object.fromEntries(serverEmotes.map(({ name, url }) => [name, url])), | ||
}), [configEmoji, serverEmotes]); | ||
|
||
return emotes; | ||
} | ||
|
||
export default useEmotes; |
Oops, something went wrong.