generated from Fierdetta/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom action sheet to choose the server to add a emoji to
- Loading branch information
1 parent
cef2897
commit 9311f5b
Showing
3 changed files
with
90 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { findByDisplayName, findByProps } from "@vendetta/metro"; | ||
import { getAssetIDByName } from "@vendetta/ui/assets"; | ||
import { FormRow } from "@vendetta/ui/components/Forms"; | ||
import { showToast } from "@vendetta/ui/toasts"; | ||
import fetchImageAsDataURL from "../functions/fetchImageAsDataURL"; | ||
|
||
// Components | ||
const { default: GuildIcon, GuildIconSizes } = findByProps("GuildIconSizes"); | ||
const Icon = findByDisplayName("Icon"); | ||
|
||
// Misc | ||
const Emojis = findByProps("uploadEmoji"); | ||
const LazyActionSheet = findByProps("openLazy", "hideActionSheet"); | ||
|
||
const Add = getAssetIDByName("ic_add_24px"); | ||
const Checkmark = getAssetIDByName("Check"); | ||
|
||
export default function AddToServerRow({ guild, emojiNode }) { | ||
const addToServerCallback = () => { | ||
// Fetch image | ||
fetchImageAsDataURL(emojiNode.src, (dataUrl) => { | ||
// Upload it to Discord | ||
Emojis.uploadEmoji({ | ||
guildId: guild.id, | ||
image: dataUrl, | ||
name: emojiNode.alt, | ||
roles: undefined | ||
}).then(() => { | ||
// Let user know it was added | ||
showToast(`Added ${emojiNode.alt} to ${guild.name}`, Checkmark); | ||
// Close the sheet | ||
LazyActionSheet.hideActionSheet(); | ||
}); | ||
}); | ||
}; | ||
|
||
return (<FormRow | ||
leading={ | ||
<GuildIcon | ||
guild={guild} | ||
size={GuildIconSizes.LARGE} | ||
animate={false} | ||
/> | ||
} | ||
label={guild.name} | ||
trailing={<Icon source={Add} />} | ||
onPress={addToServerCallback} | ||
/>) | ||
} |
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,36 @@ | ||
import { find, findByProps } from "@vendetta/metro"; | ||
import { Permissions } from "@vendetta/metro/common/constants"; | ||
import { FormDivider } from "@vendetta/ui/components/Forms"; | ||
import AddToServerRow from "../components/AddToServerRow"; | ||
|
||
const LazyActionSheet = findByProps("openLazy", "hideActionSheet"); | ||
|
||
// Components | ||
const ActionSheet = find((m) => m.default && m.default.render && m.default.render.name == "ActionSheet").default.render; | ||
const { BottomSheetScrollView } = findByProps("BottomSheetScrollView"); | ||
|
||
// Stores | ||
const GuildStore = findByProps("getGuilds"); | ||
const PermissionsStore = findByProps("can", "_dispatcher"); | ||
|
||
// function to easily show the sheet | ||
export function showAddToServerActionSheet(emojiNode) { | ||
LazyActionSheet.openLazy(() => Promise.resolve(AddToServerActionSheet), "AddToServerActionSheet", { emojiNode: emojiNode }); | ||
}; | ||
|
||
// The sheet itself | ||
export default function AddToServerActionSheet({ emojiNode }) { | ||
// Get guilds as a Array of ID and value pairs, and filter out guilds the user can't edit emojis in | ||
const guilds = Object.entries(GuildStore.getGuilds()).filter(([_, guild]) => PermissionsStore.can(Permissions.MANAGE_GUILD_EXPRESSIONS, guild)); | ||
|
||
return (<ActionSheet> | ||
<BottomSheetScrollView contentContainerStyle={{ paddingBottom: 16 }}> | ||
{guilds.map(([_, guild], num) => | ||
<> | ||
<AddToServerRow guild={guild} emojiNode={emojiNode} /> | ||
{num !== guilds.length - 1 && <FormDivider />} | ||
</> | ||
)} | ||
</BottomSheetScrollView> | ||
</ActionSheet>) | ||
}; |