shane0 / shane0.github.io

shane null's github pages
https://shane0.github.io/
MIT License
1 stars 0 forks source link

meditation app ideas #11

Open shane0 opened 1 year ago

shane0 commented 1 year ago

timer beep every 5m vibrate every 1m

import React, { useState, useEffect } from 'react';
import { View, Text, Vibration, StyleSheet } from 'react-native';
import { Audio } from 'expo-av';

export default function MeditationTimer() {
  const [time, setTime] = useState(0);
  const [beepSound, setBeepSound] = useState(null);

  useEffect(() => {
    // Load the beep sound
    async function loadBeepSound() {
      const { sound } = await Audio.Sound.createAsync(
        require('./beep.mp3')
      );
      setBeepSound(sound);
    }
    loadBeepSound();

    // Start the timer
    const intervalId = setInterval(() => {
      setTime(prevTime => prevTime + 1);
    }, 60000); // Every 1 minute

    return () => {
      // Clean up the timer and the sound
      clearInterval(intervalId);
      beepSound && beepSound.unloadAsync();
    };
  }, []);

  useEffect(() => {
    // Play the beep sound every 5 minutes
    if (time % 5 === 0 && time !== 0 && beepSound) {
      beepSound.playAsync();
    }

    // Vibrate every 1 minute
    Vibration.vibrate(500);

    return () => {
      // Stop vibrating
      Vibration.cancel();
    };
  }, [time, beepSound]);

  return (
    <View style={styles.container}>
      <Text style={styles.timerText}>{`${Math.floor(time / 60)}:${
        time % 60 < 10 ? '0' : ''
      }${time % 60}`}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  timerText: {
    fontSize: 48,
  },
});
import React, { useState, useEffect } from 'react';
import { View, Text, Button, Vibration } from 'react-native';

const MeditationTimer = () => {
  const [elapsedTime, setElapsedTime] = useState(0);

  useEffect(() => {
    const interval = setInterval(() => {
      setElapsedTime((time) => time + 1);
    }, 1000);
    return () => clearInterval(interval);
  }, []);

  useEffect(() => {
    if (elapsedTime % 60 === 0) {
      Vibration.vibrate();
    }
  }, [elapsedTime]);

  return (
    <View>
      <Text style={{ fontSize: 32 }}>Elapsed Time: {elapsedTime}</Text>
    </View>
  );
};

export default MeditationTimer;
import React from 'react';
import { SafeAreaView } from 'react-native';
import MeditationTimer from './MeditationTimer';

const App = () => {
  return (
    <SafeAreaView>
      <MeditationTimer />
    </SafeAreaView>
  );
};

export default App;
shane0 commented 1 year ago

The Four Noble Truths in Sanskrit are:

  1. Duhkha (suffering)
  2. Samudaya (origin of suffering)
  3. Nirodha (cessation of suffering)
  4. Marga (path to the cessation of suffering)

Duhkha

Duhkha is a Sanskrit word that can be translated as "suffering," "pain," or "unsatisfactoriness." It is the first of the Four Noble Truths, and it refers to the fact that all life is characterized by suffering. Suffering can take many forms, including physical pain, emotional distress, and the impermanence of all things.

Samudaya

Samudaya is the second of the Four Noble Truths, and it refers to the origin of suffering. The Buddha taught that suffering arises from craving, or attachment to things that are impermanent and unsatisfactory. When we crave things that we do not have, or when we cling to things that we do have, we create suffering for ourselves.

Nirodha

Nirodha is the third of the Four Noble Truths, and it refers to the cessation of suffering. The Buddha taught that suffering can be ceased by the abandonment of craving. When we let go of our attachments, we can free ourselves from suffering.

Marga

Marga is the fourth and final of the Four Noble Truths, and it refers to the path to the cessation of suffering. The Buddha taught that the Noble Eightfold Path is the path to the cessation of suffering. The Noble Eightfold Path is a set of eight practices that lead to the development of wisdom, morality, and concentration.

The Four Noble Truths are the foundation of Buddhist teaching. They provide a framework for understanding the nature of suffering and the path to liberation from suffering.