diff --git a/src/clip/AClipElement.tsx b/src/clip/AClipElement.tsx new file mode 100644 index 0000000..7ddc9d1 --- /dev/null +++ b/src/clip/AClipElement.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { Clipboard } from 'react-native'; +import Toast from 'react-native-simple-toast'; + +export default class AClipElement extends React.Component { + + constructor(props: any) { + super(props); + } + + onCopy() { + Clipboard.setString(this.props.content); + Toast.show('Put "' + this.props.content + '" in clipboard', Toast.SHORT); + } + +} \ No newline at end of file diff --git a/src/clip/ClipElement.tsx b/src/clip/ClipElement.tsx deleted file mode 100644 index 54ca94b..0000000 --- a/src/clip/ClipElement.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import { View, Text, Clipboard } from 'react-native'; -import IconVector from 'react-native-vector-icons/FontAwesome5'; -import Toast from 'react-native-simple-toast'; - -export default class ClipElement extends React.Component { - - constructor(props: any) { - super(props); - } - - onCopy() { - Clipboard.setString(this.props.title); - Toast.show('Put "' + this.props.title + '" in clipboard', Toast.SHORT); - } - - render(): JSX.Element { - return - {this.props.title} - this.onCopy()} /> - ; - } -} \ No newline at end of file diff --git a/src/clip/ClipElementLocal.tsx b/src/clip/ClipElementLocal.tsx new file mode 100644 index 0000000..8db043d --- /dev/null +++ b/src/clip/ClipElementLocal.tsx @@ -0,0 +1,17 @@ +import { View, Text } from 'react-native'; +import IconVector from 'react-native-vector-icons/FontAwesome5'; +import AClipElement from './AClipElement'; + +export default class ClipElementLocal extends AClipElement { + + constructor(props: any) { + super(props); + } + + render(): JSX.Element { + return + {this.props.content} + this.onCopy()} /> + ; + } +} \ No newline at end of file diff --git a/src/clip/ClipElementRemote.tsx b/src/clip/ClipElementRemote.tsx new file mode 100644 index 0000000..8345230 --- /dev/null +++ b/src/clip/ClipElementRemote.tsx @@ -0,0 +1,21 @@ +import { View, Text } from 'react-native'; +import IconVector from 'react-native-vector-icons/FontAwesome5'; +import AClipElement from './AClipElement'; + +export default class ClipElementRemote extends AClipElement { + + constructor(props: any) { + super(props); + } + + render(): JSX.Element { + return + + {this.props.content} + {this.props.deviceName} + {this.props.timestamp} + + this.onCopy()} /> + ; + } +} \ No newline at end of file diff --git a/src/clip/ClipList.tsx b/src/clip/ClipList.tsx index 257e975..46cfdfc 100644 --- a/src/clip/ClipList.tsx +++ b/src/clip/ClipList.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { ScrollView } from 'react-native'; -import ClipElement from './ClipElement'; +import ClipElementLocal from './ClipElementLocal'; +import ClipElementRemote from './ClipElementRemote'; export default class ClipList extends React.Component { @@ -8,13 +9,18 @@ export default class ClipList extends React.Component { super(props); } - createClipElement(title: string): JSX.Element { - return ; + createClipElementLocal(content: string): JSX.Element { + return ; + } + + createClipElementRemote(content: string, deviceName: string, timestamp: number): JSX.Element { + return ; } render(): JSX.Element { - return - {this.props.clips.map((entry: any) => this.createClipElement(entry.title))} - ; + let clips; + if (this.props.type === "local") clips = this.props.clips.map((entry: any) => this.createClipElementLocal(entry.content)); + else clips = this.props.clips.map((entry: any) => this.createClipElementRemote(entry.content, entry.deviceName, entry.timestamp)); + return {clips}; } } \ No newline at end of file diff --git a/src/clip/ClipView.tsx b/src/clip/ClipView.tsx index fc557cb..985418e 100644 --- a/src/clip/ClipView.tsx +++ b/src/clip/ClipView.tsx @@ -1,17 +1,45 @@ +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 - Local Clipboard - + {this.props.type[0].toUpperCase() + this.props.type.slice(1) + " Clipboard"} + ; } } \ No newline at end of file