1
1
import { Button , ScrollView , StyleSheet , Text , TouchableOpacity , View } from 'react-native' ;
2
- import * as React from 'react' ;
3
- import { useContext , useEffect } from 'react' ;
2
+ import React , { useContext , useEffect , useState } from 'react' ;
4
3
import { ThemeContext } from '../../Theme' ;
5
4
import { NavBar } from '../NavBar' ;
6
5
import { Divider } from 'react-native-paper' ;
@@ -10,13 +9,66 @@ import Share from 'react-native-share';
10
9
import RNFS from 'react-native-fs' ;
11
10
import Clipboard from '@react-native-clipboard/clipboard' ;
12
11
12
+ export function NavbarRightSide ( props : {
13
+ mockResponsesCopy : MockResponse [ ] ;
14
+ setMockResponsesCopy : ( mockResponsesCopy : MockResponse [ ] ) => void ;
15
+ } ) {
16
+ const theme = useContext ( ThemeContext ) ;
17
+
18
+ return (
19
+ < >
20
+ < TouchableOpacity
21
+ onPress = { ( ) => {
22
+ Clipboard . getString ( ) . then ( responses => {
23
+ if ( responses ) {
24
+ resetMockResponses ( responses ) ;
25
+ props . setMockResponsesCopy ( getMockResponses ( ) ) ;
26
+ }
27
+ } ) ;
28
+ } }
29
+ style = { [ styles . button , { borderLeftWidth : 0 } ] }
30
+ >
31
+ < FeatherIcon name = "download" color = { theme . textColorOne } size = { 24 } />
32
+ </ TouchableOpacity >
33
+ { props . mockResponsesCopy . length > 0 && (
34
+ < TouchableOpacity
35
+ style = { [ styles . button , { borderLeftWidth : 0 } ] }
36
+ onPress = { ( ) => {
37
+ RNFS . copyFile ( FILE_PATH , `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` )
38
+ . then ( ( ) => {
39
+ Share . open ( {
40
+ title : 'Export Mock preset' ,
41
+ url : `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` ,
42
+ type : 'text/plain' ,
43
+ // excludedActivityTypes: []
44
+ } ) . then ( ( ) => {
45
+ RNFS . unlink ( `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` ) ;
46
+ } ) ;
47
+ } )
48
+ . catch ( console . error ) ;
49
+ } }
50
+ >
51
+ < FeatherIcon name = "upload" color = { theme . textColorOne } size = { 24 } />
52
+ </ TouchableOpacity >
53
+ ) }
54
+ < Button
55
+ title = { 'Clear' }
56
+ onPress = { ( ) => {
57
+ clearMockResponses ( ) ;
58
+ props . setMockResponsesCopy ( [ ] ) ;
59
+ } }
60
+ />
61
+ </ >
62
+ ) ;
63
+ }
64
+
13
65
export function MockList ( props : {
14
66
showEdit : ( mockResponse : MockResponse , update : boolean ) => void ;
15
67
onPressBack : ( ) => void ;
16
68
} ) {
17
69
const theme = useContext ( ThemeContext ) ;
18
70
19
- const [ mockResponsesCopy , setMockResponsesCopy ] = React . useState < MockResponse [ ] > ( [ ] ) ;
71
+ const [ mockResponsesCopy , setMockResponsesCopy ] = useState < MockResponse [ ] > ( [ ] ) ;
20
72
21
73
useEffect ( ( ) => {
22
74
setMockResponsesCopy ( getMockResponses ( ) ) ;
@@ -29,53 +81,7 @@ export function MockList(props: {
29
81
title = { 'Mock List' }
30
82
onPressBack = { props . onPressBack }
31
83
rightComponent = {
32
- < >
33
- < TouchableOpacity style = { [ styles . button , { borderLeftWidth : 0 } ] } >
34
- < FeatherIcon
35
- name = "download"
36
- color = { theme . textColorOne }
37
- size = { 24 }
38
- onPress = { ( ) => {
39
- Clipboard . getString ( ) . then ( responses => {
40
- if ( responses ) {
41
- resetMockResponses ( responses ) ;
42
- setMockResponsesCopy ( getMockResponses ( ) ) ;
43
- }
44
- } ) ;
45
- } }
46
- />
47
- </ TouchableOpacity >
48
- { mockResponsesCopy . length > 0 && (
49
- < TouchableOpacity style = { [ styles . button , { borderLeftWidth : 0 } ] } >
50
- < FeatherIcon
51
- name = "upload"
52
- color = { theme . textColorOne }
53
- size = { 24 }
54
- onPress = { ( ) => {
55
- RNFS . copyFile ( FILE_PATH , `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` )
56
- . then ( ( ) => {
57
- Share . open ( {
58
- title : 'Export Mock preset' ,
59
- url : `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` ,
60
- type : 'text/plain' ,
61
- // excludedActivityTypes: []
62
- } ) . then ( ( ) => {
63
- RNFS . unlink ( `${ RNFS . DocumentDirectoryPath } /mocks-preset.json` ) ;
64
- } ) ;
65
- } )
66
- . catch ( console . error ) ;
67
- } }
68
- />
69
- </ TouchableOpacity >
70
- ) }
71
- < Button
72
- title = { 'Clear' }
73
- onPress = { ( ) => {
74
- clearMockResponses ( ) ;
75
- setMockResponsesCopy ( [ ] ) ;
76
- } }
77
- />
78
- </ >
84
+ < NavbarRightSide mockResponsesCopy = { mockResponsesCopy } setMockResponsesCopy = { setMockResponsesCopy } />
79
85
}
80
86
/>
81
87
0 commit comments