-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui/plugins): Bunny plugin sheet impl
- Loading branch information
Showing
11 changed files
with
234 additions
and
64 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,23 @@ | ||
import { Author } from "@lib/addons/types"; | ||
import { ImageSourcePropType } from "react-native"; | ||
|
||
interface Badge { | ||
source: ImageSourcePropType; | ||
color?: string; | ||
onPress?: () => void; | ||
} | ||
|
||
export interface UnifiedPluginModel { | ||
id: string; | ||
name: string; | ||
description?: string; | ||
authors?: Author[]; | ||
icon?: string; | ||
getBadges(): Badge[]; | ||
isEnabled(): boolean; | ||
usePluginState(): void; | ||
isInstalled(): boolean; | ||
toggle(start: boolean): void; | ||
resolveSheetComponent(): Promise<{ default: React.ComponentType<any>; }>; | ||
getPluginSettingsComponent(): React.ComponentType<any> | null | undefined; | ||
} |
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
117 changes: 89 additions & 28 deletions
117
src/core/ui/settings/pages/Plugins/sheets/PluginInfoActionSheet.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 |
---|---|---|
@@ -1,45 +1,106 @@ | ||
import { startPlugin } from "@lib/addons/plugins"; | ||
import { findAssetId } from "@lib/api/assets"; | ||
import { hideSheet } from "@lib/ui/sheets"; | ||
import { ActionSheet, Button, Text } from "@metro/common/components"; | ||
import { ActionSheet, Card, ContextMenu, IconButton, Text } from "@metro/common/components"; | ||
import { ComponentProps } from "react"; | ||
import { ScrollView, View } from "react-native"; | ||
|
||
import { PluginInfoActionSheetProps } from "./common"; | ||
import TitleComponent from "./TitleComponent"; | ||
|
||
function PluginInfoIconButton(props: ComponentProps<typeof IconButton>) { | ||
const { onPress } = props; | ||
props.onPress &&= () => { | ||
hideSheet("PluginInfoActionSheet"); | ||
onPress?.(); | ||
}; | ||
|
||
return <IconButton {...props} />; | ||
} | ||
|
||
export default function PluginInfoActionSheet({ plugin, navigation }: PluginInfoActionSheetProps) { | ||
plugin.usePluginState(); | ||
|
||
return <ActionSheet> | ||
<ScrollView contentContainerStyle={{ gap: 8, marginBottom: 12 }}> | ||
<View style={{ flexDirection: "row", alignItems: "center", paddingVertical: 24 }}> | ||
<View style={{ gap: 4 }}> | ||
<Text variant="heading-xl/semibold"> | ||
{plugin.name} | ||
</Text> | ||
<Text variant="text-md/medium" color="text-muted"> | ||
{plugin.description} | ||
</Text> | ||
</View> | ||
<View style={{ marginLeft: "auto" }}> | ||
{plugin.getPluginSettingsComponent() && <Button | ||
size="md" | ||
text="Configure" | ||
<ScrollView contentContainerStyle={{ gap: 12, marginBottom: 12 }}> | ||
<View style={{ flexDirection: "row", alignItems: "center", gap: 8, paddingVertical: 24, justifyContent: "space-between", width: "100%" }}> | ||
<TitleComponent plugin={plugin} /> | ||
<ContextMenu | ||
items={[ | ||
{ | ||
label: "Details", | ||
iconSource: findAssetId("CircleInformationIcon-primary"), | ||
action: () => { | ||
} | ||
}, | ||
// { | ||
// label: true ? "Disable Updates" : "Enable Updates", | ||
// iconSource: true ? findAssetId("ClockXIcon") : findAssetId("ClockIcon"), | ||
// action: () => { | ||
|
||
// } | ||
// }, | ||
{ | ||
label: "Clear Data", | ||
iconSource: findAssetId("CopyIcon"), | ||
variant: "destructive", | ||
action: () => { | ||
} | ||
}, | ||
{ | ||
label: "Uninstall", | ||
iconSource: findAssetId("TrashIcon"), | ||
variant: "destructive", | ||
action: () => { | ||
} | ||
} | ||
]} | ||
> | ||
{props => <IconButton | ||
{...props} | ||
icon={findAssetId("MoreHorizontalIcon")} | ||
variant="secondary" | ||
icon={findAssetId("WrenchIcon")} | ||
onPress={() => { | ||
hideSheet("PluginInfoActionSheet"); | ||
navigation.push("BUNNY_CUSTOM_PAGE", { | ||
title: plugin.name, | ||
render: plugin.getPluginSettingsComponent(), | ||
}); | ||
}} | ||
size="sm" | ||
/>} | ||
</View> | ||
</ContextMenu> | ||
</View> | ||
<View style={{ flexDirection: "row", justifyContent: "center", alignContent: "center" }}> | ||
{/* <Text variant="text-lg/medium"> | ||
Oops, you shouldn't see this! | ||
</Text> */} | ||
<View style={{ flexDirection: "row", justifyContent: "space-around", alignContent: "center" }}> | ||
<PluginInfoIconButton | ||
label="Configure" | ||
variant="secondary" | ||
disabled={!plugin.getPluginSettingsComponent()} | ||
icon={findAssetId("WrenchIcon")} | ||
onPress={() => { | ||
navigation.push("BUNNY_CUSTOM_PAGE", { | ||
title: plugin.name, | ||
render: plugin.getPluginSettingsComponent(), | ||
}); | ||
}} | ||
/> | ||
<PluginInfoIconButton | ||
label="Refetch" | ||
variant="secondary" | ||
icon={findAssetId("RetryIcon")} | ||
onPress={() => { | ||
startPlugin(plugin.id); | ||
}} | ||
/> | ||
<PluginInfoIconButton | ||
label="Copy URL" | ||
variant="secondary" | ||
icon={findAssetId("LinkIcon")} | ||
onPress={() => { | ||
}} | ||
/> | ||
</View> | ||
<Card> | ||
<Text variant="text-md/semibold" color="text-primary" style={{ marginBottom: 4 }}> | ||
Description | ||
</Text> | ||
<Text variant="text-md/medium"> | ||
{plugin.description} | ||
</Text> | ||
</Card> | ||
</ScrollView> | ||
</ActionSheet>; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/core/ui/settings/pages/Plugins/sheets/TitleComponent.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,57 @@ | ||
import { UnifiedPluginModel } from "@core/ui/settings/pages/Plugins/models"; | ||
import { lazyDestructure } from "@lib/utils/lazy"; | ||
import { findByNameLazy, findByProps } from "@metro"; | ||
import { FluxUtils } from "@metro/common"; | ||
import { Avatar, AvatarPile, Text } from "@metro/common/components"; | ||
import { UserStore } from "@metro/common/stores"; | ||
import { View } from "react-native"; | ||
|
||
const showUserProfileActionSheet = findByNameLazy("showUserProfileActionSheet"); | ||
const { getUser: maybeFetchUser } = lazyDestructure(() => findByProps("getUser", "fetchProfile")); | ||
|
||
export default function TitleComponent({ plugin }: { plugin: UnifiedPluginModel; }) { | ||
const users: any[] = FluxUtils.useStateFromStoresArray([UserStore], () => { | ||
plugin.authors?.forEach(a => a.id && maybeFetchUser(a.id)); | ||
return plugin.authors?.map(a => UserStore.getUser(a.id)); | ||
}); | ||
|
||
const { authors } = plugin; | ||
const authorTextNode = []; | ||
|
||
if (authors) { | ||
for (const author of authors) { | ||
authorTextNode.push(<Text | ||
onPress={() => showUserProfileActionSheet({ userId: author.id })} | ||
variant="text-md/medium" | ||
> | ||
{author.name} | ||
</Text>); | ||
|
||
authorTextNode.push(", "); | ||
} | ||
|
||
authorTextNode.pop(); | ||
} | ||
|
||
return <View style={{ gap: 4 }}> | ||
<View> | ||
<Text variant="heading-xl/semibold"> | ||
{plugin.name} | ||
</Text> | ||
</View> | ||
<View style={{ flexDirection: "row", flexShrink: 1 }}> | ||
{authors?.length && <View style={{ flexDirection: "row", gap: 8, alignItems: "center", paddingVertical: 4, paddingHorizontal: 8, backgroundColor: "#00000016", borderRadius: 32 }}> | ||
{users.length && <AvatarPile | ||
size="xxsmall" | ||
names={plugin.authors?.map(a => a.name)} | ||
totalCount={plugin.authors?.length} | ||
> | ||
{users.map(a => <Avatar size="xxsmall" user={a} />)} | ||
</AvatarPile>} | ||
<Text variant="text-md/medium"> | ||
{authorTextNode} | ||
</Text> | ||
</View>} | ||
</View> | ||
</View>; | ||
} |
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
Oops, something went wrong.