directly import react & react-native

This commit is contained in:
amsyarasyiq 2023-04-05 14:37:50 +08:00
parent 5938714c73
commit 9a98225dd7
4 changed files with 149 additions and 146 deletions

View file

@ -73,10 +73,7 @@ async function buildPlugin(plugin) {
},
plugins: [
nodeResolve({
resolveOnly: (id) => ![
"react",
"react-native"
].includes(id)
resolveOnly: (id) => !["react", "react-native"].includes(id)
}),
commonjs(),
{

View file

@ -1,4 +1,4 @@
import { NavigationNative, React, ReactNative } from "@vendetta/metro/common";
import { NavigationNative, React } from "@vendetta/metro/common";
import { storage } from "@vendetta/plugin";
import { useProxy } from "@vendetta/storage";
import { getAssetIDByName } from "@vendetta/ui/assets";
@ -9,7 +9,9 @@ import { currentSettings } from ".";
import Constants from "./constants";
import { initialize } from "./utils";
const { ScrollView, TouchableOpacity, Text } = ReactNative;
import { useEffect } from "react";
import { ScrollView, Text, TouchableOpacity } from "react-native";
const { FormInput, FormDivider, FormSwitchRow, FormText, FormIcon } = Forms;
function UpdateButton() {
@ -35,7 +37,7 @@ export default function Settings() {
const settings = useProxy(storage) as PluginSettings;
const navigation = NavigationNative.useNavigation();
React.useEffect(() => {
useEffect(() => {
navigation.setOptions({
title: "Last.fm Configuration",
headerRight: UpdateButton

View file

@ -1,13 +1,14 @@
import { findByStoreName } from "@vendetta/metro";
import { NavigationNative, React, ReactNative, stylesheet } from "@vendetta/metro/common";
import { NavigationNative, React, stylesheet } from "@vendetta/metro/common";
import { useProxy } from "@vendetta/storage";
import { getAssetIDByName } from "@vendetta/ui/assets";
import { Forms } from "@vendetta/ui/components";
import { settings, SettingsSchema } from ".";
import { useEffect, useState } from "react";
import { FlatList, Image, ScrollView, TouchableOpacity } from "react-native";
import { SettingsSchema, settings } from ".";
const UserStore = findByStoreName("UserStore");
const { ScrollView, TouchableOpacity, Image, FlatList } = ReactNative;
const { FormInput, FormDivider, FormText, FormIcon, FormRow, FormSection, FormSwitchRow } = Forms;
const styles = stylesheet.createThemedStyleSheet({
@ -28,7 +29,7 @@ function AddButton({ callback }: { callback: () => void }) {
}
function AddRow({ onFinish }: { onFinish: () => void }) {
const [value, setValue] = React.useState("");
const [value, setValue] = useState("");
const onPressCallback = () => {
if (!isNaN(parseInt(value)) && UserStore.getUser(value) && !settings.exempted.includes(value)) {
@ -61,10 +62,10 @@ function AddRow({ onFinish }: { onFinish: () => void }) {
export default function Settings() {
useProxy(settings) as SettingsSchema;
const [shouldShowAdd, setShouldShowAdd] = React.useState(false);
const [shouldShowAdd, setShouldShowAdd] = useState(false);
const navigation = NavigationNative.useNavigation();
React.useEffect(() => {
useEffect(() => {
navigation.setOptions({
headerRight: () => <AddButton callback={() => setShouldShowAdd(true)} />
});

View file

@ -1,11 +1,12 @@
import { React, ReactNative, stylesheet } from "@vendetta/metro/common";
import { React, stylesheet } from "@vendetta/metro/common";
import { storage } from "@vendetta/plugin";
import { useProxy } from "@vendetta/storage";
import { semanticColors } from "@vendetta/ui";
import { Forms } from "@vendetta/ui/components";
import { ScrollView } from "react-native";
const { FormSection, FormInput, FormRow, FormSwitch, FormText } = Forms;
const { ScrollView } = ReactNative;
const styles = stylesheet.createThemedStyleSheet({
subText: {
@ -22,135 +23,137 @@ const styles = stylesheet.createThemedStyleSheet({
export default function Settings() {
const settings = useProxy(storage) as { [key: string]: any };
return (<ScrollView>
<FormSection title="Basic">
<FormInput
title="Application Name"
value={settings.app_name}
placeholder="Vendetta"
onChange={v => settings.app_name = v}
/>
<FormInput
title="Application ID"
value={settings.application_id}
placeholder="1054951789318909972"
onChange={v => settings.application_id = v}
keyboardType="numeric"
/>
<FormInput
title="Type"
value={settings.type}
placeholder="0"
onChange={v => settings.type = v}
keyboardType="numeric"
/>
<FormInput
title="Details"
value={settings.details}
placeholder="Competitive"
onChange={v => settings.details = v}
/>
<FormInput
title="State"
value={settings.state}
placeholder="Playing Solo"
onChange={v => settings.state = v}
/>
</FormSection>
<FormSection title="Images">
<FormInput
title="Large Image Asset Key or URL"
value={settings.large_image}
placeholder="large_image_here"
onChange={v => settings.large_image = v}
/>
<FormInput
title="Large Image Text"
value={settings.large_image_text}
placeholder="Playing on Joe's lobby"
disabled={!settings.large_image}
onChange={v => settings.large_image_text = v}
/>
<FormInput
title="Small Image Asset Key or URL"
value={settings.small_image}
placeholder="small_image_here"
onChange={v => settings.small_image = v}
/>
<FormInput
title="Small Image Text"
value={settings.small_image_text}
placeholder="Solo"
disabled={!settings.small_image}
onChange={v => settings.small_image_text = v}
/>
<FormText style={styles.subText}>
{"Image assets key can be either a Discord app asset's name or a URL to an image."}
</FormText>
</FormSection>
<FormSection title="Timestamps">
<FormRow
label="Enable timestamps"
subLabel="Set whether to show timestamps or not"
trailing={<FormSwitch
value={settings.enable_timestamps}
onValueChange={v => settings.enable_timestamps = v}
/>}
/>
<FormInput
title="Start Timestamp (seconds)"
value={settings.start_timestamp}
placeholder="1234567890"
disabled={!settings.enable_timestamps}
onChange={v => settings.start_timestamp = v}
keyboardType="numeric"
/>
<FormInput
title="End Timestamp (seconds)"
value={settings.end_timestamp}
placeholder="1234567890"
disabled={!settings.enable_timestamps}
onChange={v => settings.end_timestamp = v}
keyboardType="numeric"
/>
<FormRow
label="Use current time as start timestamp"
subLabel="This will override the start timestamp you set above"
disabled={!settings.enable_timestamps}
onPress={() => settings.start_timestamp = String(Date.now())}
trailing={FormRow.Arrow}
/>
<FormText style={styles.subText}>
Leaving start timestamp blank will use the time the Discord started.
</FormText>
</FormSection>
<FormSection title="Buttons">
<FormInput
title="First Button Text"
value={settings.button1_text}
placeholder="random link #1"
onChange={v => settings.button1_text = v}
/>
<FormInput
title="First Button URL"
value={settings.button1_URL}
placeholder="https://discord.com/vanityurl/dotcom/steakpants/flour/flower/index11.html"
disabled={!settings.button1_text}
onChange={v => settings.button1_URL = v}
/>
<FormInput
title="Second Button Text"
value={settings.button2_text}
placeholder="random link #2"
onChange={v => settings.button2_text = v}
/>
<FormInput
title="Second Button URL"
value={settings.button2_URL}
placeholder="https://youtu.be/w0AOGeqOnFY"
disabled={!settings.button2_text}
onChange={v => settings.button2_URL = v}
/>
</FormSection>
</ScrollView>);
return (
<ScrollView>
<FormSection title="Basic">
<FormInput
title="Application Name"
value={settings.app_name}
placeholder="Vendetta"
onChange={v => settings.app_name = v}
/>
<FormInput
title="Application ID"
value={settings.application_id}
placeholder="1054951789318909972"
onChange={v => settings.application_id = v}
keyboardType="numeric"
/>
<FormInput
title="Type"
value={settings.type}
placeholder="0"
onChange={v => settings.type = v}
keyboardType="numeric"
/>
<FormInput
title="Details"
value={settings.details}
placeholder="Competitive"
onChange={v => settings.details = v}
/>
<FormInput
title="State"
value={settings.state}
placeholder="Playing Solo"
onChange={v => settings.state = v}
/>
</FormSection>
<FormSection title="Images">
<FormInput
title="Large Image Asset Key or URL"
value={settings.large_image}
placeholder="large_image_here"
onChange={v => settings.large_image = v}
/>
<FormInput
title="Large Image Text"
value={settings.large_image_text}
placeholder="Playing on Joe's lobby"
disabled={!settings.large_image}
onChange={v => settings.large_image_text = v}
/>
<FormInput
title="Small Image Asset Key or URL"
value={settings.small_image}
placeholder="small_image_here"
onChange={v => settings.small_image = v}
/>
<FormInput
title="Small Image Text"
value={settings.small_image_text}
placeholder="Solo"
disabled={!settings.small_image}
onChange={v => settings.small_image_text = v}
/>
<FormText style={styles.subText}>
{"Image assets key can be either a Discord app asset's name or a URL to an image."}
</FormText>
</FormSection>
<FormSection title="Timestamps">
<FormRow
label="Enable timestamps"
subLabel="Set whether to show timestamps or not"
trailing={<FormSwitch
value={settings.enable_timestamps}
onValueChange={v => settings.enable_timestamps = v}
/>}
/>
<FormInput
title="Start Timestamp (seconds)"
value={settings.start_timestamp}
placeholder="1234567890"
disabled={!settings.enable_timestamps}
onChange={v => settings.start_timestamp = v}
keyboardType="numeric"
/>
<FormInput
title="End Timestamp (seconds)"
value={settings.end_timestamp}
placeholder="1234567890"
disabled={!settings.enable_timestamps}
onChange={v => settings.end_timestamp = v}
keyboardType="numeric"
/>
<FormRow
label="Use current time as start timestamp"
subLabel="This will override the start timestamp you set above"
disabled={!settings.enable_timestamps}
onPress={() => settings.start_timestamp = String(Date.now())}
trailing={FormRow.Arrow}
/>
<FormText style={styles.subText}>
Leaving start timestamp blank will use the time the Discord started.
</FormText>
</FormSection>
<FormSection title="Buttons">
<FormInput
title="First Button Text"
value={settings.button1_text}
placeholder="random link #1"
onChange={v => settings.button1_text = v}
/>
<FormInput
title="First Button URL"
value={settings.button1_URL}
placeholder="https://discord.com/vanityurl/dotcom/steakpants/flour/flower/index11.html"
disabled={!settings.button1_text}
onChange={v => settings.button1_URL = v}
/>
<FormInput
title="Second Button Text"
value={settings.button2_text}
placeholder="random link #2"
onChange={v => settings.button2_text = v}
/>
<FormInput
title="Second Button URL"
value={settings.button2_URL}
placeholder="https://youtu.be/w0AOGeqOnFY"
disabled={!settings.button2_text}
onChange={v => settings.button2_URL = v}
/>
</FormSection>
</ScrollView>
);
}