continue generating flow, add backend connection on main tabs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable react/display-name */
|
||||
import React from "reactn";
|
||||
import React, { useEffect, useGlobal } from "reactn";
|
||||
import Page from "../../layouts/Page";
|
||||
import { gutters, Palette, Style } from "../../styles";
|
||||
import { background } from "../../assets";
|
||||
@@ -8,11 +8,33 @@ import { responsiveHeight } from "react-native-responsive-dimensions";
|
||||
import { BlurView } from "expo-blur";
|
||||
import Switch from "../../components/Switch";
|
||||
import { useState } from "react";
|
||||
import firebase, { usersRef } from "../../config/firebase";
|
||||
import { FONT_FAMILY } from "../../styles/Fonts";
|
||||
|
||||
export default (props) => {
|
||||
const [currentUID] = useGlobal("currentUID");
|
||||
const [currentUserData] = useGlobal("currentUserData");
|
||||
const [, setTooltip] = useGlobal("_tooltip");
|
||||
|
||||
const [isSwitch, setIsSwitch] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsSwitch(!!currentUserData?.notifications);
|
||||
}, [currentUserData?.notifications]);
|
||||
|
||||
const onToggle = async (next) => {
|
||||
try {
|
||||
setIsSwitch(next);
|
||||
const uid = currentUID || firebase.auth().currentUser?.uid;
|
||||
if (!uid) return;
|
||||
await usersRef.doc(uid).set({ notifications: next }, { merge: true });
|
||||
setTooltip({ type: "success", text: "Préférence enregistrée" });
|
||||
} catch (e) {
|
||||
setIsSwitch(!next);
|
||||
setTooltip({ type: "error", text: e?.message || "Enregistrement impossible" });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Page
|
||||
headerType="NAVIGATE"
|
||||
@@ -50,7 +72,7 @@ export default (props) => {
|
||||
>
|
||||
Notifications
|
||||
</Text>
|
||||
<Switch value={isSwitch} setValue={setIsSwitch} />
|
||||
<Switch value={isSwitch} setValue={onToggle} />
|
||||
</View>
|
||||
<Text
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user