Files
wol-app/App.js
2024-02-16 22:52:53 +01:00

39 lines
1.2 KiB
JavaScript

import React from 'react';
import { TouchableWithoutFeedback, View, Text, Alert } from 'react-native';
const MyButton = () => {
const handleLongPress = () => {
// Obsługa przytrzymania guzika
Alert.alert('Button Long Pressed', 'You long pressed the button');
};
const handlePress = () => {
// Obsługa zwykłego kliknięcia guzika
fetch('https://wol.turtel.xyz/wolweb/wake/pajonk')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log(data);
Alert.alert('Response', JSON.stringify(data));
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
Alert.alert('Error', 'There was a problem with the request');
});
};
return (
<TouchableWithoutFeedback onPress={handlePress} onLongPress={handleLongPress}>
<View style={{ padding: 10, backgroundColor: 'blue', borderRadius: 5 }}>
<Text style={{ color: 'white' }}>Send Request</Text>
</View>
</TouchableWithoutFeedback>
);
};
export default MyButton;