Update jobline display and related jobs.

This commit is contained in:
Patrick Fic
2025-11-14 14:09:44 -08:00
parent ec7327e1fd
commit 5235519dd8
12 changed files with 326 additions and 59 deletions

View File

@@ -1,5 +1,4 @@
import axios from "axios";
import Constants from "expo-constants";
import * as FileSystem from "expo-file-system/legacy";
import * as ImagePicker from "expo-image-picker";
import * as MediaLibrary from "expo-media-library";
@@ -63,23 +62,24 @@ export function* onOpenImagePicker() {
export function* openImagePickerAction({ payload: jobid }) {
try {
if (Constants.platform.ios) {
const cameraRollStatus =
yield ImagePicker.requestMediaLibraryPermissionsAsync();
const cameraStatus = yield ImagePicker.requestCameraPermissionsAsync();
if (
cameraRollStatus.status !== "granted" ||
cameraStatus.status !== "granted"
) {
alert("Photo and Camera permissions have not been granted. Please open the settings app and allow these permissions to upload photos.");
return;
}
// if (Constants.platform.ios) {
const cameraRollStatus =
yield ImagePicker.requestMediaLibraryPermissionsAsync();
const cameraStatus = yield ImagePicker.requestCameraPermissionsAsync();
if (
cameraRollStatus.status !== "granted" ||
cameraStatus.status !== "granted"
) {
alert("Photo and Camera permissions have not been granted. Please open the settings app and allow these permissions to upload photos.");
return;
}
// }
let result = yield ImagePicker.launchImageLibraryAsync({
mediaTypes: ["images", "videos"],
aspect: [4, 3],
quality: 1,
allowsMultipleSelection: true,
allowsEditing: false,
exif: true,
});
if (!(result.canceled)) {
@@ -411,19 +411,55 @@ function* mediaUploadCompletedAction({ payload: photos }) {
const filesToDelete = Object.keys(progress).filter((key) => progress[key].status === 'completed').map((key) => progress[key]);
if (Platform.OS === "android") {
yield MediaLibrary.getPermissionsAsync(false);
const asset = filesToDelete[0];
let assetIdToDelete = asset.assetId;
// 2. ANDROID FIX: Find the original asset ID
if (!assetIdToDelete && Platform.OS === 'android') {
// Fetch the last 50 images from the gallery
const recentAssets = yield call(MediaLibrary.getAssetsAsync, {
first: 50,
sortBy: [MediaLibrary.SortBy.creationTime],
mediaType: MediaLibrary.MediaType.photo,
});
// Try to match based on width, height, and proximity of creation time
// Note: The cache file timestamp might differ slightly from the original
const foundAsset = recentAssets.assets.find(libraryItem => {
console.log("Comparing library item:", moment(asset.exif.DateTime, "YYYY:MM:DD HH:mm:ss").valueOf(), libraryItem.creationTime);
return (
libraryItem.width === asset.exif.ImageWidth &&
libraryItem.height === asset.exif.ImageLength &&
Math.abs(moment(asset.exif.DateTimeOriginal, "YYYY:MM:DD HH:mm:ss").valueOf() - libraryItem.creationTime) < 1000
);
});
if (foundAsset) {
assetIdToDelete = foundAsset.id;
}
}
// 3. Upload and Delete
if (assetIdToDelete) {
// await uploadFunction(asset.uri);
yield call(MediaLibrary.deleteAssetsAsync, assetIdToDelete);
}
//Create a new asset with the first file to delete.
// console.log('Trying new delete.');
yield MediaLibrary.getPermissionsAsync(false);
const album = yield call(MediaLibrary.createAlbumAsync,
"ImEX Mobile Deleted",
filesToDelete.pop(),
filesToDelete.pop().assetId,
false
);
//Move the rest.
if (filesToDelete.length > 0) {
const moveResult = yield call(MediaLibrary.addAssetsToAlbumAsync,
filesToDelete,
filesToDelete.map(f => f.assetId),
album,
false
);
@@ -447,7 +483,7 @@ function* onMediaUploadFailure() {
}
function* mediaUploadFailureAction({ payload: errorMessage }) {
Alert.alert("Upload Error", `An error occurred during upload: ${errorMessage}`);
Alert.alert("Upload Error", `An error occurred during upload: ${JSON.stringify(errorMessage)}`);
}