diff --git a/src/App.tsx b/src/App.tsx index 8a005a9..18094c6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -24,7 +24,10 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import SignIn from './auth/SignIn'; import SignUp from './auth/SignUp'; import { Provider } from 'react-redux'; -import store from './redux/store'; +import { store, persistor } from './redux/store'; +import { PersistGate } from 'redux-persist/integration/react'; + + const Stack = createNativeStackNavigator(); const Tab = createMaterialBottomTabNavigator(); @@ -38,77 +41,40 @@ class App extends React.Component { username: "" } store.subscribe(() => { - this.setState({ token: store.getState().userReducer.token }); + this.setState({ token: store.getState().persistedUserReducer.token }); }); } - Auth() { - return - - } name="Login" options={{ title: 'Connexion' }} /> - } name="Register" options={{ title: 'Créer un compte' }} /> - - ; - } - - Clip() { - return ( - - - {(props) => } - - - {(props) => } - - - ); - } - render(): React.ReactNode { console.log("render app", store.getState()); console.log("app state", this.state); - return - { - this.state.token === "" - ? + return + + + + { + this.state.token === "" + ? + //////////////////////////////////////////////////////////// + <> + } name="Login" options={{ title: 'Connexion' }} /> + } name="Register" options={{ title: 'Créer un compte' }} /> + + : + //////////////////////////////////////////////////////////// + <> + + {(props) => } + + + {(props) => } + + //////////////////////////////////////////////////////////// - <> - } name="Login" options={{ title: 'Connexion' }} /> - } name="Register" options={{ title: 'Créer un compte' }} /> - - : - //////////////////////////////////////////////////////////// - <> - - {(props) => } - - - {(props) => } - - - //////////////////////////////////////////////////////////// - } - + } + + }; } -const styles = StyleSheet.create({ - sectionContainer: { - marginTop: 32, - paddingHorizontal: 24, - }, - sectionTitle: { - fontSize: 24, - fontWeight: '600', - }, - sectionDescription: { - marginTop: 8, - fontSize: 18, - fontWeight: '400', - }, - highlight: { - fontWeight: '700', - }, -}); - export default App; diff --git a/src/clip/ClipElementLocal.tsx b/src/clip/ClipElementLocal.tsx index 1b99bf5..4c16af1 100644 --- a/src/clip/ClipElementLocal.tsx +++ b/src/clip/ClipElementLocal.tsx @@ -10,7 +10,7 @@ export default class ClipElementLocal extends AClipElement { async sendToRemote() { const data = new FormData(); - data.append("token", this.props.store.getState().userReducer.token); + data.append("token", this.props.store.getState().persistedUserReducer.token); data.append("content", this.props.content); data.append("deviceName", "TODOChangeThisMobileDevice"); const sendToRemoteResponse = await fetch( diff --git a/src/clip/ClipViewLocal.tsx b/src/clip/ClipViewLocal.tsx index feca26b..0cddc57 100644 --- a/src/clip/ClipViewLocal.tsx +++ b/src/clip/ClipViewLocal.tsx @@ -1,18 +1,32 @@ import axios from 'axios'; import React from 'react'; -import { ScrollView, Text, Button } from 'react-native'; +import { ScrollView, Text, Button, Clipboard } from 'react-native'; import ClipList from './ClipList'; import AClipView from './AClipView'; +import { addToLocal as addToLocalStorage } from '../redux/actions'; export default class ClipViewLocal extends AClipView { constructor(props: any) { super(props); + this.state = { + localClips : [] + }; + this.getClips(); + this.props.store.subscribe(() => { + this.setState({localClips : this.props.store.getState().persistedUserReducer.clips }); + }); } getClips() { - return [{ content: "test" }, { content: "test2" }]; + const clips = this.props.store.getState().persistedUserReducer.clips; + this.setState({localClips: clips}); + } + + async addToLocal(){ + console.log("should add clip"); + this.props.store.dispatch(addToLocalStorage(await Clipboard.getString())); } componentDidMount() { @@ -26,6 +40,7 @@ export default class ClipViewLocal extends AClipView { let notTitle = "Remote Clipboard"; return {title} +