From b867a788e2f0ca89735e426132683bc41c0d2c72 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Thu, 9 Jan 2025 07:13:42 +0000 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E9=9D=A2=E6=95=B4=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Settings/NotificationSettings.js | 149 ++++++++++++++++++++ components/Settings/SettingTopPage.js | 57 ++++++-- components/Settings/settings.js | 18 +++ stateBox/useNotifications.tsx | 17 +-- 4 files changed, 217 insertions(+), 24 deletions(-) create mode 100644 components/Settings/NotificationSettings.js diff --git a/components/Settings/NotificationSettings.js b/components/Settings/NotificationSettings.js new file mode 100644 index 0000000..f0c5352 --- /dev/null +++ b/components/Settings/NotificationSettings.js @@ -0,0 +1,149 @@ +import React, { useEffect, useState } from "react"; +import { View, Text, TouchableOpacity, ScrollView,Clipboard } from "react-native"; + +import { CheckBox } from "react-native-elements"; +import { AS } from "../../storageControl"; +import { useNotification } from "../../stateBox/useNotifications"; + +export const NotificationSettings = ({ navigate }) => { + const { expoPushToken } = useNotification(); + const [traInfoEX, setTraInfoEX] = useState(false); + const [informations, setInformations] = useState(false); + const [strangeTrain, setStrangeTrain] = useState(false); + useEffect(() => { + AS.getItem("traInfoEX").then(setTraInfoEX); + AS.getItem("informations").then(setInformations); + AS.getItem("strangeTrain").then(setStrangeTrain); + }, []); + + return ( + + + + { + navigate("settingTopPage"); + }} + style={{ + flexDirection: "column", + flex: 1, + }} + > + + + < 設定/送信 + + + + + + + 通知設定(β) + + + { + fetch( + "https://n8n.haruk.in/webhook/jr-shikoku-notification-configurations", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + token: expoPushToken, + traInfoEX, + informations, + strangeTrain, + }), + } + ).then(() => { + Promise.all([ + AS.setItem("traInfoEX", traInfoEX.toString()), + AS.setItem("informations", informations.toString()), + AS.setItem("strangeTrain", strangeTrain.toString()), + ]).then(()=>alert("通知の設定を保存、登録しました")); + }); + }} + style={{ + flexDirection: "column", + flex: 1, + }} + > + + + 登録実行 + + + + + + + + + + { + Clipboard.setString(expoPushToken); + }}> + 通知を受け取りたい項目を選択してください。チェックボックスを選び、右上の「登録実行」を押すと設定が反映され、通知が届くようになります。 + + + + ); +}; + +const SimpleSwitch = ({ bool, setBool, str }) => ( + + setBool(bool == "true" ? "false" : "true")} + containerStyle={{ + flex: 1, + backgroundColor: "#00000000", + borderColor: "white", + alignContent: "center", + }} + textStyle={{ fontSize: 20, fontWeight: "normal" }} + title={str} + /> + +); diff --git a/components/Settings/SettingTopPage.js b/components/Settings/SettingTopPage.js index 382de1b..40a007f 100644 --- a/components/Settings/SettingTopPage.js +++ b/components/Settings/SettingTopPage.js @@ -12,11 +12,19 @@ import * as Updates from "expo-updates"; import { useWindowDimensions } from "react-native"; import { ListItem } from "native-base"; import { SwitchArea } from "../atom/SwitchArea"; +import { useNotification } from "../../stateBox/useNotifications"; const versionCode = "5.5.1"; -export const SettingTopPage = ({ navigate, testNFC,startPage,setStartPage, updateAndReload }) => { +export const SettingTopPage = ({ + navigate, + testNFC, + startPage, + setStartPage, + updateAndReload, +}) => { const { width } = useWindowDimensions(); + const { expoPushToken } = useNotification(); return ( @@ -102,18 +110,18 @@ export const SettingTopPage = ({ navigate, testNFC,startPage,setStartPage, updat + navigate("FavoriteSettings")} > - "} + navigate("NotificationSettings")} + disabled={expoPushToken == ""} + > + + 通知設定{expoPushToken == "" ? "(通知設定をオンにしてください)" : "(β)"} + + + + {">"} + + navigate("LayoutSettings")} diff --git a/components/Settings/settings.js b/components/Settings/settings.js index 4f9004f..d375630 100644 --- a/components/Settings/settings.js +++ b/components/Settings/settings.js @@ -22,6 +22,7 @@ import { SettingTopPage } from "./SettingTopPage"; import { LayoutSettings } from "./LayoutSettings"; import { FavoriteSettings } from "./FavoriteSettings"; import { WidgetSettings } from "./WidgetSettings"; +import { NotificationSettings } from "./NotificationSettings"; const Stack = createStackNavigator(); export default function Setting(props) { @@ -118,6 +119,23 @@ export default function Setting(props) { /> )} + + {(props) => ( + + )} + = ({ children }) => { Notifications.removeNotificationSubscription(responseListener.current); }; }, []); - useEffect(() => { - if (expoPushToken) { - //alert(expoPushToken); - Clipboard.setString(expoPushToken); - //sendPushNotification(expoPushToken); - } - }, [expoPushToken]); return ( - + {children} );