コード整理

This commit is contained in:
harukin-expo-dev-env 2024-05-21 10:33:41 +00:00
parent 9df3d0c62a
commit 1fafe1649c
4 changed files with 44 additions and 52 deletions

View File

@ -4,6 +4,25 @@ import {
TextWidget,
ListWidget,
} from "react-native-android-widget";
import dayjs from "dayjs";
import { ToastAndroid } from "react-native";
export const getInfoString = async () => {
// Fetch data from the server
const time = dayjs().format("HH:mm");
const text = await fetch(
"https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${text}`, ToastAndroid.SHORT);
return { time, text };
};
export function InfoWidget({ time, text }) {
return (

View File

@ -4,7 +4,25 @@ import {
TextWidget,
ListWidget,
} from "react-native-android-widget";
import dayjs from "dayjs";
import { ToastAndroid } from "react-native";
export const getDelayData = async () => {
// Fetch data from the server
const time = dayjs().format("HH:mm");
const delayString = await fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT);
return { time, delayString };
};
export function TraInfoEXWidget({ time, delayString }) {
return (
<FlexWidget

View File

@ -1,8 +1,7 @@
import React from "react";
import { TraInfoEXWidget } from "./TraInfoEXWidget";
import dayjs from "dayjs";
import { TraInfoEXWidget, getDelayData } from "./TraInfoEXWidget";
import { ToastAndroid } from "react-native";
import { InfoWidget } from "./InfoWidget";
import { InfoWidget, getInfoString } from "./InfoWidget";
import { AS } from "../../storageControl";
export const nameToWidget = {
@ -10,39 +9,6 @@ export const nameToWidget = {
Info_Widget: InfoWidget,
};
export const getInfoString = async () => {
// Fetch data from the server
const time = dayjs().format("HH:mm");
const text = await fetch(
"https://script.google.com/macros/s/AKfycbz80LcaEUrhnlEsLkJy0LG2IRO3DBVQhfNmN1d_0f_HvtsujNQpxM90SrV9yKWH_JG1Ww/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${text}`, ToastAndroid.SHORT);
return { time, text };
};
export const getDelayData = async () => {
// Fetch data from the server
const time = dayjs().format("HH:mm");
const delayString = await fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT);
return { time, delayString };
};
export async function widgetTaskHandler(props) {
const {
widgetInfo,
@ -65,18 +31,12 @@ export async function widgetTaskHandler(props) {
case "WIDGET_CLICK":
case "WIDGET_RESIZED":
switch (WidgetName) {
case "JR_shikoku_train_info": {
const { time, delayString } = await getDelayData();
renderWidget(
<TraInfoEXWidget time={time} delayString={delayString} />
);
break;
}
case "Info_Widget": {
const { time, text } = await getInfoString();
renderWidget(<InfoWidget time={time} text={text} />);
break;
}
case "JR_shikoku_train_info":
default: {
const { time, delayString } = await getDelayData();
renderWidget(

View File

@ -4,13 +4,10 @@ import { SwitchArea } from "../atom/SwitchArea";
import { CheckBox } from "react-native-elements";
import { TripleSwitchArea } from "../atom/TripleSwitchArea";
import { getWidgetInfo, WidgetPreview } from "react-native-android-widget";
import { TraInfoEXWidget } from "../AndroidWidget/TraInfoEXWidget";
import { getDelayData } from "../AndroidWidget/TraInfoEXWidget";
import { getInfoString } from "../AndroidWidget/InfoWidget";
import { AS } from "../../storageControl";
import {
getDelayData,
nameToWidget,
getInfoString,
} from "../AndroidWidget/widget-task-handler";
import { nameToWidget } from "../AndroidWidget/widget-task-handler";
import { ListItem } from "native-base";
export const WidgetSettings = ({ navigate }) => {
@ -116,9 +113,7 @@ export const WidgetSettings = ({ navigate }) => {
}}
>
<WidgetPreview
renderWidget={() => (
<Info_Widget time={time} delayString={trainInfo} />
)}
renderWidget={() => <Info_Widget time={time} text={trainInfo} />}
width={400}
height={250}
/>