factor V2
This commit is contained in:
parent
19a61101ca
commit
6720e86ac8
1 changed files with 64 additions and 48 deletions
|
|
@ -1,13 +1,12 @@
|
||||||
import { plugin } from "@vendetta";
|
import { plugin } from "@vendetta";
|
||||||
import { Forms } from "@vendetta/ui/components";
|
|
||||||
import { useProxy } from "@vendetta/storage";
|
|
||||||
import { getAssetIDByName } from "@vendetta/ui/assets";
|
import { getAssetIDByName } from "@vendetta/ui/assets";
|
||||||
import { showToast } from "@vendetta/ui/toasts";
|
import { showToast } from "@vendetta/ui/toasts";
|
||||||
import { React } from "@vendetta/metro/common";
|
import { React } from "@vendetta/metro/common";
|
||||||
import { ScrollView, View, Linking } from "react-native";
|
import { Linking } from "react-native";
|
||||||
import { changelog, currentVersion } from "../../changelog";
|
import { changelog, currentVersion } from "../../changelog";
|
||||||
import { findByProps } from "@vendetta/metro";
|
import { findByProps } from "@vendetta/metro";
|
||||||
|
|
||||||
|
const { ScrollView } = findByProps("ScrollView");
|
||||||
const { TableRowGroup, TableSwitchRow, Stack, TableRow } = findByProps(
|
const { TableRowGroup, TableSwitchRow, Stack, TableRow } = findByProps(
|
||||||
"TableSwitchRow",
|
"TableSwitchRow",
|
||||||
"TableRowGroup",
|
"TableRowGroup",
|
||||||
|
|
@ -21,18 +20,20 @@ import Constants from "../../constants";
|
||||||
import { initialize } from "../../manager";
|
import { initialize } from "../../manager";
|
||||||
import { lastfmClient } from "../../utils/lastfm";
|
import { lastfmClient } from "../../utils/lastfm";
|
||||||
|
|
||||||
|
const get = (k: string, fallback: any = "") => plugin.storage[k] ?? fallback;
|
||||||
|
const set = (k: string, v: any) => (plugin.storage[k] = v);
|
||||||
|
|
||||||
export default function Settings() {
|
export default function Settings() {
|
||||||
useProxy(currentSettings);
|
const [_, forceUpdate] = React.useReducer((x) => ~x, 0);
|
||||||
|
const update = () => forceUpdate();
|
||||||
|
|
||||||
const [loading, setLoading] = React.useState(false);
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
|
||||||
const saveSettings = (key: string, value: any) => {
|
|
||||||
currentSettings[key] = value;
|
|
||||||
plugin.storage[key] = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
const testConnection = async () => {
|
const testConnection = async () => {
|
||||||
if (!currentSettings.username || !currentSettings.apiKey) {
|
const username = get("username");
|
||||||
|
const apiKey = get("apiKey");
|
||||||
|
|
||||||
|
if (!username || !apiKey) {
|
||||||
showToast(
|
showToast(
|
||||||
"Please enter both username and API key",
|
"Please enter both username and API key",
|
||||||
getAssetIDByName("Small"),
|
getAssetIDByName("Small"),
|
||||||
|
|
@ -62,21 +63,29 @@ export default function Settings() {
|
||||||
<Stack spacing={4}>
|
<Stack spacing={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder="Last.fm Username"
|
placeholder="Last.fm Username"
|
||||||
value={currentSettings.username}
|
value={get("username")}
|
||||||
onChange={(v: string) => saveSettings("username", v)}
|
onChange={(v: string) => {
|
||||||
|
set("username", v);
|
||||||
|
update();
|
||||||
|
}}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder="API Key"
|
placeholder="API Key"
|
||||||
value={currentSettings.apiKey}
|
value={get("apiKey")}
|
||||||
onChange={(v: string) => saveSettings("apiKey", v)}
|
onChange={(v: string) => {
|
||||||
|
set("apiKey", v);
|
||||||
|
update();
|
||||||
|
}}
|
||||||
secureTextEntry={true}
|
secureTextEntry={true}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<TableRow
|
<TableRow
|
||||||
label="Get API Key"
|
label="Get API Key"
|
||||||
subLabel="https://www.last.fm/api/"
|
subLabel="https://www.last.fm/api/account/create"
|
||||||
onPress={() => Linking.openURL("https://www.last.fm/api/")}
|
onPress={() =>
|
||||||
|
Linking.openURL("https://www.last.fm/api/account/create")
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<TableRow
|
<TableRow
|
||||||
|
|
@ -91,17 +100,23 @@ export default function Settings() {
|
||||||
<Stack spacing={4}>
|
<Stack spacing={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={`App Name (Default: ${Constants.DEFAULT_SETTINGS.appName})`}
|
placeholder={`App Name (Default: ${Constants.DEFAULT_SETTINGS.appName})`}
|
||||||
value={currentSettings.appName}
|
value={get("appName", Constants.DEFAULT_SETTINGS.appName)}
|
||||||
onChange={(v: string) => saveSettings("appName", v)}
|
onChange={(v: string) => {
|
||||||
|
set("appName", v);
|
||||||
|
update();
|
||||||
|
}}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={`Update Interval (Default: ${Constants.DEFAULT_SETTINGS.timeInterval}s)`}
|
placeholder={`Update Interval (Default: ${Constants.DEFAULT_SETTINGS.timeInterval}s)`}
|
||||||
value={String(currentSettings.timeInterval)}
|
value={String(
|
||||||
|
get("timeInterval", Constants.DEFAULT_SETTINGS.timeInterval),
|
||||||
|
)}
|
||||||
onChange={(v: string) => {
|
onChange={(v: string) => {
|
||||||
const interval = Number(v);
|
const interval = Number(v);
|
||||||
if (interval >= Constants.MIN_UPDATE_INTERVAL) {
|
if (interval >= Constants.MIN_UPDATE_INTERVAL) {
|
||||||
saveSettings("timeInterval", interval);
|
set("timeInterval", interval);
|
||||||
|
update();
|
||||||
} else {
|
} else {
|
||||||
showToast(
|
showToast(
|
||||||
`Minimum interval is ${Constants.MIN_UPDATE_INTERVAL} seconds`,
|
`Minimum interval is ${Constants.MIN_UPDATE_INTERVAL} seconds`,
|
||||||
|
|
@ -118,43 +133,44 @@ export default function Settings() {
|
||||||
<TableRowGroup title="Options">
|
<TableRowGroup title="Options">
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Show 'Listening to' instead of 'Playing'"
|
label="Show 'Listening to' instead of 'Playing'"
|
||||||
value={
|
value={get("listeningTo", Constants.DEFAULT_SETTINGS.listeningTo)}
|
||||||
currentSettings.listeningTo ??
|
onValueChange={(value: boolean) => {
|
||||||
Constants.DEFAULT_SETTINGS.listeningTo
|
set("listeningTo", value);
|
||||||
}
|
update();
|
||||||
onValueChange={(value: boolean) =>
|
}}
|
||||||
saveSettings("listeningTo", value)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Show Timestamp"
|
label="Show Timestamp"
|
||||||
value={
|
value={get(
|
||||||
currentSettings.showTimestamp ??
|
"showTimestamp",
|
||||||
Constants.DEFAULT_SETTINGS.showTimestamp
|
Constants.DEFAULT_SETTINGS.showTimestamp,
|
||||||
}
|
)}
|
||||||
onValueChange={(value: boolean) =>
|
onValueChange={(value: boolean) => {
|
||||||
saveSettings("showTimestamp", value)
|
set("showTimestamp", value);
|
||||||
}
|
update();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Ignore when Spotify is playing"
|
label="Ignore when Spotify is playing"
|
||||||
value={
|
value={get(
|
||||||
currentSettings.ignoreSpotify ??
|
"ignoreSpotify",
|
||||||
Constants.DEFAULT_SETTINGS.ignoreSpotify
|
Constants.DEFAULT_SETTINGS.ignoreSpotify,
|
||||||
}
|
)}
|
||||||
onValueChange={(value: boolean) =>
|
onValueChange={(value: boolean) => {
|
||||||
saveSettings("ignoreSpotify", value)
|
set("ignoreSpotify", value);
|
||||||
}
|
update();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<TableSwitchRow
|
<TableSwitchRow
|
||||||
label="Verbose Logging"
|
label="Verbose Logging"
|
||||||
value={
|
value={get(
|
||||||
currentSettings.verboseLogging ??
|
"verboseLogging",
|
||||||
Constants.DEFAULT_SETTINGS.verboseLogging
|
Constants.DEFAULT_SETTINGS.verboseLogging,
|
||||||
}
|
)}
|
||||||
onValueChange={(value: boolean) =>
|
onValueChange={(value: boolean) => {
|
||||||
saveSettings("verboseLogging", value)
|
set("verboseLogging", value);
|
||||||
}
|
update();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue