From ab1e04f5643e08d6d868f35c245b3a59a8854997 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Mon, 9 Nov 2020 18:43:59 -0800 Subject: [PATCH] Added app reducer, fixed package issues, begun camera screen updates --- babel-translations.babel | 31 +++ components/job-list/job-list.component.jsx | 2 +- components/job-notes/job-notes.component.jsx | 2 +- .../screen-camera/screen-camera.component.jsx | 45 ++- .../screen-main/screen-main.component.jsx | 23 +- .../screen-media-cache.component.jsx | 257 +++++++++++++++++- graphql/client.js | 6 +- graphql/jobs.queries.js | 20 +- package.json | 3 + redux/app/app.actions.js | 21 ++ redux/app/app.reducer.js | 39 +++ redux/app/app.sagas.js | 158 +++++++++++ redux/app/app.selectors.js | 16 ++ redux/app/app.types.js | 7 + redux/root.reducer.js | 17 +- redux/root.saga.js | 16 +- redux/store.js | 21 +- redux/user/user.sagas.js | 2 +- translations/en-US/common.json | 5 + translations/es-MX/common.json | 5 + translations/fr-CA/common.json | 5 + yarn.lock | 20 +- 22 files changed, 653 insertions(+), 68 deletions(-) create mode 100644 redux/app/app.actions.js create mode 100644 redux/app/app.reducer.js create mode 100644 redux/app/app.sagas.js create mode 100644 redux/app/app.selectors.js create mode 100644 redux/app/app.types.js diff --git a/babel-translations.babel b/babel-translations.babel index 8ea525b..ca5774d 100644 --- a/babel-translations.babel +++ b/babel-translations.babel @@ -47,6 +47,37 @@ + + camera + + + titles + + + cameratab + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + general diff --git a/components/job-list/job-list.component.jsx b/components/job-list/job-list.component.jsx index 81bcc63..580aabb 100644 --- a/components/job-list/job-list.component.jsx +++ b/components/job-list/job-list.component.jsx @@ -18,7 +18,7 @@ const mapStateToProps = createStructuredSelector({ export function JobListComponent({ bodyshop }) { const { loading, error, data, refetch } = useQuery(QUERY_ALL_ACTIVE_JOBS, { variables: { - statuses: bodyshop.md_ro_statuses.open_statuses || ["Open", "Open*"], + statuses: bodyshop.md_ro_statuses.active_statuses || ["Open", "Open*"], }, skip: !bodyshop, }); diff --git a/components/job-notes/job-notes.component.jsx b/components/job-notes/job-notes.component.jsx index 57197c9..9c696ff 100644 --- a/components/job-notes/job-notes.component.jsx +++ b/components/job-notes/job-notes.component.jsx @@ -18,7 +18,7 @@ export default function JobNotes({ job, loading, refetch }) { Job is not defined. ; } - console.log("job.notes :>> ", job.notes); + const onRefresh = async () => { return refetch(); }; diff --git a/components/screen-camera/screen-camera.component.jsx b/components/screen-camera/screen-camera.component.jsx index b2e2a6c..1f448ef 100644 --- a/components/screen-camera/screen-camera.component.jsx +++ b/components/screen-camera/screen-camera.component.jsx @@ -7,16 +7,36 @@ import { MaterialCommunityIcons, } from "@expo/vector-icons"; import { useNavigation } from "@react-navigation/native"; +import * as FileSystem from "expo-file-system"; +import * as Permissions from "expo-permissions"; +import * as MediaLibrary from "expo-media-library"; export default function ScreenCamera() { const navigation = useNavigation(); const [hasPermission, setHasPermission] = useState(null); + const [rollPermision, setRollPermission] = useState(null); const [type, setType] = useState(Camera.Constants.Type.back); const cameraRef = useRef(null); + useEffect(() => { (async () => { + //Ensure local photo direcotry exists. + console.log( + "ScreenCamera -> FileSystem.documentDirectory ", + FileSystem.documentDirectory + ); + + await FileSystem.makeDirectoryAsync( + FileSystem.documentDirectory + "photos" + ).catch((e) => { + console.log(e, "Directoryc already exists"); + }); + const { status } = await Camera.requestPermissionsAsync(); setHasPermission(status === "granted"); + // camera roll + const { cam_roll } = await Permissions.askAsync(Permissions.CAMERA_ROLL); + setRollPermission(cam_roll === "granted"); })(); }, []); @@ -31,8 +51,29 @@ export default function ScreenCamera() { const handleTakePicture = async () => { console.log("Taking the picture!"); if (cameraRef.current) { - let photo = await cameraRef.current.takePictureAsync(); - console.log("The Photo", photo); + const options = { + //quality: 0.5, + //base64: true, + //skipProcessing: true, + }; + + let photo = await cameraRef.current.takePictureAsync(options); + console.log("ScreenCamera -> photo", photo); + const filename = new Date().getTime() + ".jpg"; + + await FileSystem.copyAsync({ + from: photo.uri, + to: FileSystem.documentDirectory + "photos/" + filename, + }); + + console.log( + "List of Files", + await FileSystem.readDirectoryAsync(FileSystem.documentDirectory), + await FileSystem.readDirectoryAsync( + FileSystem.documentDirectory + "photos" + ) + ); + //const asset = await MediaLibrary.createAssetAsync(photo.uri); } }; diff --git a/components/screen-main/screen-main.component.jsx b/components/screen-main/screen-main.component.jsx index 5395f1d..556231b 100644 --- a/components/screen-main/screen-main.component.jsx +++ b/components/screen-main/screen-main.component.jsx @@ -75,11 +75,25 @@ const JobStackNavigator = ({ navigation }) => ( i18n.t("joblist.labels.detail"), })} /> - + ); +const CameraStackNavigator = ({ navigation }) => ( + + + + +); const MessagingStackNavigator = ({ navigation }) => ( ( iconName = "ios-list"; } else if (route.name === "MessagingTab") { iconName = "ios-chatboxes"; + } else if (route.name === "CameraTab") { + iconName = "ios-camera"; } return ; }, @@ -116,6 +132,11 @@ const BottomTabsNavigator = () => ( options={{ title: i18n.t("joblist.titles.jobtab") }} component={JobStackNavigator} /> + { +// console.log(p); +// }); - FileSystem.readDirectoryAsync(FileSystem.documentDirectory).then((p) => { - console.log(p); - }); - return ( - - This is the media cache screen. - - ); +// useEffect(() => { +// (async () => { +// if (Constants.platform.ios) { +// const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL); +// if (status !== "granted") { +// alert("Sorry, we need camera roll permissions to make this work!"); +// } +// } +// })(); +// }, []); + +// return ( +// +// This is the media cache screen. +//