From cceb78f7c3767c30cccf7b8bc527c4b26c4a4a36 Mon Sep 17 00:00:00 2001 From: Romain CLEMENT Date: Sat, 8 Apr 2023 01:23:48 +0200 Subject: [PATCH] Separated local/remote clipboard views --- src/App.tsx | 90 +++++++++++++++++-------------------- src/clip/AClipView.tsx | 18 ++++++++ src/clip/ClipView.tsx | 45 ------------------- src/clip/ClipViewLocal.tsx | 32 +++++++++++++ src/clip/ClipViewRemote.tsx | 32 +++++++++++++ 5 files changed, 124 insertions(+), 93 deletions(-) create mode 100644 src/clip/AClipView.tsx delete mode 100644 src/clip/ClipView.tsx create mode 100644 src/clip/ClipViewLocal.tsx create mode 100644 src/clip/ClipViewRemote.tsx diff --git a/src/App.tsx b/src/App.tsx index c0e6d3f..1c821a7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,63 +5,57 @@ * @format */ import * as React from 'react'; -import {NavigationContainer} from '@react-navigation/native'; -import type {PropsWithChildren} from 'react'; +import { NavigationContainer } from '@react-navigation/native'; +import type { PropsWithChildren } from 'react'; import { - SafeAreaView, - ScrollView, - StatusBar, - StyleSheet, - Text, - useColorScheme, - View, + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + useColorScheme, + View, } from 'react-native'; -import {createNativeStackNavigator} from '@react-navigation/native-stack'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import ClipViewLocal from './clip/ClipViewLocal'; +import ClipViewRemote from './clip/ClipViewRemote'; +import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs'; -const Stack = createNativeStackNavigator(); +const Stack = createMaterialBottomTabNavigator(); function App(): JSX.Element { - return ( - - - {/* - \ - */} - - - ); + return ( + + + + {(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', - }, + 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/AClipView.tsx b/src/clip/AClipView.tsx new file mode 100644 index 0000000..38e0f59 --- /dev/null +++ b/src/clip/AClipView.tsx @@ -0,0 +1,18 @@ +import React from 'react'; +import { ScrollView, Text, Button } from 'react-native'; +import ClipList from './ClipList'; + + +export default abstract class AClipView extends React.Component { + + constructor(props: any) { + super(props); + this.state = { + clips: [] + } + } + + abstract getClips(): any; + + abstract componentDidMount(): any; +} \ No newline at end of file diff --git a/src/clip/ClipView.tsx b/src/clip/ClipView.tsx deleted file mode 100644 index 985418e..0000000 --- a/src/clip/ClipView.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import axios from 'axios'; -import React from 'react'; -import { ScrollView, Text } from 'react-native'; -import ClipList from './ClipList'; - -type Clip = { - content: string; - token: string; - deviceName: string; - id: number; - timestamp: number; -}; - -async function getLocalClips() { - return [{ content: "test" }, { content: "test2" }]; -} - -async function getRemoteClips() { - const { data, status } = await axios.get("http://notifysync.simailadjalim.fr/clipboard?token=FFmkeNAxguFM5My52PhhzlOB_1ZwDr0ureD2kzuewMlhmJ6Ia6YkhcdZd1Nw4SXdLu9Ji0gzVYCfGCcgB8v8zQ"); - return Object.values(data['clipboard']); -} - -export default class ClipView extends React.Component { - - constructor(props: any) { - super(props); - this.state = { - clips: [] - } - } - - async componentDidMount() { - let clips; - if (this.props.type === "local") clips = await getLocalClips(); - else clips = await getRemoteClips(); - this.setState({clips: clips}); - } - - render(): JSX.Element { - return - {this.props.type[0].toUpperCase() + this.props.type.slice(1) + " Clipboard"} - - ; - } -} \ No newline at end of file diff --git a/src/clip/ClipViewLocal.tsx b/src/clip/ClipViewLocal.tsx new file mode 100644 index 0000000..734e5c6 --- /dev/null +++ b/src/clip/ClipViewLocal.tsx @@ -0,0 +1,32 @@ +import axios from 'axios'; +import React from 'react'; +import { ScrollView, Text, Button } from 'react-native'; +import ClipList from './ClipList'; +import AClipView from './AClipView'; + + +export default class ClipViewLocal extends AClipView { + + constructor(props: any) { + super(props); + } + + getClips() { + return [{ content: "test" }, { content: "test2" }]; + } + + componentDidMount() { + let clips; + clips = this.getClips(); + this.setState({clips: clips}); + } + + render(): JSX.Element { + let title = "Local Clipboard"; + let notTitle = "Remote Clipboard"; + return + {title} + + ; + } +} \ No newline at end of file diff --git a/src/clip/ClipViewRemote.tsx b/src/clip/ClipViewRemote.tsx new file mode 100644 index 0000000..cd44dbc --- /dev/null +++ b/src/clip/ClipViewRemote.tsx @@ -0,0 +1,32 @@ +import axios from 'axios'; +import React from 'react'; +import { ScrollView, Text, Button } from 'react-native'; +import ClipList from './ClipList'; +import AClipView from './AClipView'; + +export default class ClipViewRemote extends AClipView { + constructor(props: any) { + super(props); + } + + async getClips() { + const { data, status } = await axios.get("http://notifysync.simailadjalim.fr/clipboard?token=FFmkeNAxguFM5My52PhhzlOB_1ZwDr0ureD2kzuewMlhmJ6Ia6YkhcdZd1Nw4SXdLu9Ji0gzVYCfGCcgB8v8zQ"); + return Object.values(data['clipboard']); + } + + async componentDidMount() { + let clips; + clips = await this.getClips(); + this.setState({clips: clips}); + } + + render(): JSX.Element { + let title = "Remote Clipboard"; + let notTitle = "Local Clipboard"; + return + {title} + +