From ac9946523a9cba5bedf66f0abb40dff1d4fa1d8d Mon Sep 17 00:00:00 2001 From: Dwynr Date: Wed, 20 Apr 2022 15:27:35 +0200 Subject: [PATCH] 2.0.13 --- src/components/ActionSheets.js | 6 +- src/components/Toasts.js | 110 +++++++++++++++++++++++++++++++-- src/lib/api.js | 4 +- src/lib/helpers.js | 22 +++++++ src/lib/permissions.js | 14 ++--- src/lib/services/items.js | 6 +- src/lib/upload.js | 12 ++-- 7 files changed, 147 insertions(+), 27 deletions(-) diff --git a/src/components/ActionSheets.js b/src/components/ActionSheets.js index 24a56346a..b334d4d22 100644 --- a/src/components/ActionSheets.js +++ b/src/components/ActionSheets.js @@ -154,7 +154,7 @@ export const BottomBarAddActionSheet = memo(({ navigation, route }) => { queueFileUpload({ pickedFile: { - name: i18n(lang, getFilePreviewType(getFileExt(fileName)) == "image" ? "photo" : "video") + "_" + new Date().toLocaleString().split(" ").join("_").split(",").join("_").split(":").join("_").split(".").join("_").split("/").join(".").split("\\").join("_").split("-").join("_") + "." + getFileExt(fileName), + name: i18n(lang, getFilePreviewType(getFileExt(fileName)) == "image" ? "photo" : "video") + "_" + new Date().toLocaleString().split(" ").join("_").split(",").join("_").split(":").join("_").split(".").join("_").split("/").join("_").split("\\").join("_").split("-").join("_") + "." + getFileExt(fileName), size: asset.fileSize || typeof stat.size == "string" ? parseInt(stat.size) : stat.size, type: asset.type || "", uri: decodeURIComponent(asset.uri) || "" @@ -227,7 +227,7 @@ export const BottomBarAddActionSheet = memo(({ navigation, route }) => { queueFileUpload({ pickedFile: { - name: i18n(lang, getFilePreviewType(getFileExt(fileName)) == "image" ? "photo" : "video") + "_" + new Date(asset.timestamp || (+new Date())).toLocaleString().split(" ").join("_").split(",").join("_").split(":").join("_").split(".").join("_").split("/").join(".").split("\\").join("_").split("-").join("_") + "." + getFileExt(fileName), + name: i18n(lang, getFilePreviewType(getFileExt(fileName)) == "image" ? "photo" : "video") + "_" + new Date(asset.timestamp || (+new Date())).toLocaleString().split(" ").join("_").split(",").join("_").split(":").join("_").split(".").join("_").split("/").join("_").split("\\").join("_").split("-").join("_") + "." + getFileExt(fileName), size: asset.fileSize || typeof stat.size == "string" ? parseInt(stat.size) : stat.size, type: asset.type || "", uri: decodeURIComponent(asset.uri) || "" @@ -350,6 +350,7 @@ export const TopBarActionSheet = memo(({ navigation }) => { const [privateKey, setPrivateKey] = useMMKVString("privateKey", storage) const [currentRouteName, setCurrentRouteName] = useState("") const [canMakeAvailableOffline, setCanMakeAvailableOffline] = useState(false) + const [canDownload, setCanDownload] = useState(false) const maxBulkActionsItemsCount = 100 const minBulkActionsItemCount = 2 @@ -435,6 +436,7 @@ export const TopBarActionSheet = memo(({ navigation }) => { setCanShowRemoveSharedIn(true) setCanShowStopSharing(true) setCanMakeAvailableOffline(true) + setCanDownload(true) if(routeURL.indexOf("photos") !== -1){ setCanShowListViewStyle(false) diff --git a/src/components/Toasts.js b/src/components/Toasts.js index e3f6e0db4..f92f13970 100644 --- a/src/components/Toasts.js +++ b/src/components/Toasts.js @@ -181,6 +181,20 @@ export const MoveToast = memo(({ message }) => { const [buttonsDisabled, setButtonsDisabled] = useState(false) const [lang, setLang] = useMMKVString("lang", storage) const initParent = useRef() + const currentRoutes = useStore(useCallback(state => state.currentRoutes)) + const [currentParent, setCurrentParent] = useState("") + const [currentRouteURL, setCurrentRouteURL] = useState("") + + useEffect(() => { + if(Array.isArray(currentRoutes)){ + const parent = getParent(currentRoutes[currentRoutes.length - 1]) + + if(typeof parent == "string" && parent.length > 0){ + setCurrentParent(parent) + setCurrentRouteURL(getRouteURL(currentRoutes[currentRoutes.length - 1])) + } + } + }, [currentRoutes]) useEffect(() => { DeviceEventEmitter.emit("event", { @@ -245,6 +259,18 @@ export const MoveToast = memo(({ message }) => { return false } + if( + currentRouteURL.indexOf("shared-in") !== -1 || + currentRouteURL.indexOf("recents") !== -1 || + currentRouteURL.indexOf("trash") !== -1 || + currentRouteURL.indexOf("photos") !== -1 || + currentRouteURL.indexOf("offline") !== -1 + ){ + showToast({ message: i18n(lang, "cannotMoveFileHere") }) + + return false + } + const parent = getParent() if([ @@ -263,7 +289,7 @@ export const MoveToast = memo(({ message }) => { return false } - if(parent.length <= 32 && currentActionSheetItem.type == "file"){ + if(parent.length <= 32){ //&& currentActionSheetItem.type == "file" showToast({ message: i18n(lang, "cannotMoveFileHere") }) return false @@ -401,7 +427,7 @@ export const MoveToast = memo(({ message }) => { } }}> 32) ? darkMode ? "white" : "black" : "gray" }}> {i18n(lang, "move")} @@ -417,6 +443,20 @@ export const UploadToast = memo(({ message }) => { const currentShareItems = useStore(useCallback(state => state.currentShareItems)) const setCurrentShareItems = useStore(useCallback(state => state.setCurrentShareItems)) const [items, setItems] = useState([]) + const currentRoutes = useStore(useCallback(state => state.currentRoutes)) + const [currentParent, setCurrentParent] = useState("") + const [currentRouteURL, setCurrentRouteURL] = useState("") + + useEffect(() => { + if(Array.isArray(currentRoutes)){ + const parent = getParent(currentRoutes[currentRoutes.length - 1]) + + if(typeof parent == "string" && parent.length > 0){ + setCurrentParent(parent) + setCurrentRouteURL(getRouteURL(currentRoutes[currentRoutes.length - 1])) + } + } + }, [currentRoutes]) useEffect(() => { setItems([]) @@ -500,6 +540,16 @@ export const UploadToast = memo(({ message }) => { }} style={{ marginLeft: 20 }} onPress={() => { + if( + currentRouteURL.indexOf("shared-in") !== -1 || + currentRouteURL.indexOf("recents") !== -1 || + currentRouteURL.indexOf("trash") !== -1 || + currentRouteURL.indexOf("photos") !== -1 || + currentRouteURL.indexOf("offline") !== -1 + ){ + return false + } + if(!Array.isArray(items)){ return false } @@ -587,7 +637,7 @@ export const UploadToast = memo(({ message }) => { hideAllToasts() }}> 32) ? darkMode ? "white" : "black" : "gray" }}> {i18n(lang, "upload")} @@ -603,6 +653,20 @@ export const UploadToast = memo(({ message }) => { export const CameraUploadChooseFolderToast = memo(({ message, navigation }) => { const [darkMode, setDarkMode] = useMMKVBoolean("darkMode", storage) const [lang, setLang] = useMMKVString("lang", storage) + const currentRoutes = useStore(useCallback(state => state.currentRoutes)) + const [currentParent, setCurrentParent] = useState("") + const [currentRouteURL, setCurrentRouteURL] = useState("") + + useEffect(() => { + if(Array.isArray(currentRoutes)){ + const parent = getParent(currentRoutes[currentRoutes.length - 1]) + + if(typeof parent == "string" && parent.length > 0){ + setCurrentParent(parent) + setCurrentRouteURL(getRouteURL(currentRoutes[currentRoutes.length - 1])) + } + } + }, [currentRoutes]) return ( { }} style={{ marginLeft: 20 }} onPress={() => { + if( + currentRouteURL.indexOf("shared-in") !== -1 || + currentRouteURL.indexOf("recents") !== -1 || + currentRouteURL.indexOf("trash") !== -1 || + currentRouteURL.indexOf("photos") !== -1 || + currentRouteURL.indexOf("offline") !== -1 + ){ + return false + } + const parent = getParent() let folderName = undefined @@ -718,7 +792,7 @@ export const CameraUploadChooseFolderToast = memo(({ message, navigation }) => { }) }}> 32) ? darkMode ? "white" : "black" : "gray" }}> {i18n(lang, "choose")} @@ -735,6 +809,20 @@ export const MoveBulkToast = memo(({ message }) => { const [lang, setLang] = useMMKVString("lang", storage) const currentBulkItems = useStore(useCallback(state => state.currentBulkItems)) const initParent = useRef() + const currentRoutes = useStore(useCallback(state => state.currentRoutes)) + const [currentParent, setCurrentParent] = useState("") + const [currentRouteURL, setCurrentRouteURL] = useState("") + + useEffect(() => { + if(Array.isArray(currentRoutes)){ + const parent = getParent(currentRoutes[currentRoutes.length - 1]) + + if(typeof parent == "string" && parent.length > 0){ + setCurrentParent(parent) + setCurrentRouteURL(getRouteURL(currentRoutes[currentRoutes.length - 1])) + } + } + }, [currentRoutes]) useEffect(() => { DeviceEventEmitter.emit("event", { @@ -799,6 +887,18 @@ export const MoveBulkToast = memo(({ message }) => { return false } + if( + currentRouteURL.indexOf("shared-in") !== -1 || + currentRouteURL.indexOf("recents") !== -1 || + currentRouteURL.indexOf("trash") !== -1 || + currentRouteURL.indexOf("photos") !== -1 || + currentRouteURL.indexOf("offline") !== -1 + ){ + showToast({ message: i18n(lang, "cannotMoveItemsHere") }) + + return false + } + if(currentBulkItems.length == 0){ hideAllToasts() @@ -880,7 +980,7 @@ export const MoveBulkToast = memo(({ message }) => { }) }}> 32) ? darkMode ? "white" : "black" : "gray" }}> {i18n(lang, "move")} diff --git a/src/lib/api.js b/src/lib/api.js index c21c774a9..c5c4430eb 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -1787,9 +1787,7 @@ export const restoreItem = ({ item }) => { item, routeURL: "trash" }).then(() => { - clearLoadItemsCacheLastResponse({ - parent: item.parent - }).then(() => { + clearLoadItemsCacheLastResponse().then(() => { return resolve() }) }) diff --git a/src/lib/helpers.js b/src/lib/helpers.js index 44c29d651..ef1e651e8 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -708,6 +708,28 @@ export function orderItemsByType(items, type){ return sortedFolders.concat(sortedFiles) } + else if(type == "lastModifiedAsc"){ + let sortedFiles = files.sort((a, b) => { + return a.lastModifiedSort - b.lastModifiedSort + }) + + let sortedFolders = folders.sort((a, b) => { + return b.timestamp - a.timestamp + }) + + return sortedFolders.concat(sortedFiles) + } + else if(type == "lastModifiedDesc"){ + let sortedFiles = files.sort((a, b) => { + return b.lastModifiedSort - a.lastModifiedSort + }) + + let sortedFolders = folders.sort((a, b) => { + return b.timestamp - a.timestamp + }) + + return sortedFolders.concat(sortedFiles) + } else{ //default, dateDesc diff --git a/src/lib/permissions.js b/src/lib/permissions.js index 6399ba905..cb2affee5 100644 --- a/src/lib/permissions.js +++ b/src/lib/permissions.js @@ -3,7 +3,7 @@ import { check, PERMISSIONS, RESULTS, request, requestMultiple, checkMultiple } import { storage } from "./storage" import { i18n } from "../i18n/i18n" -export const hasWritePermissions = (requestPermissions) => { +export const hasWritePermissions = (requestPermissions = true) => { return new Promise((resolve, reject) => { if(Platform.OS == "android"){ check(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE).then((status) => { @@ -30,7 +30,7 @@ export const hasWritePermissions = (requestPermissions) => { }) } -export const hasReadPermissions = (requestPermissions) => { +export const hasReadPermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "android"){ check(PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE).then((status) => { @@ -57,7 +57,7 @@ export const hasReadPermissions = (requestPermissions) => { }) } -export const hasCameraPermissions = (requestPermissions) => { +export const hasCameraPermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "android"){ check(PERMISSIONS.ANDROID.CAMERA).then((status) => { @@ -100,7 +100,7 @@ export const hasCameraPermissions = (requestPermissions) => { }) } -export const hasBiometricPermissions = (requestPermissions) => { +export const hasBiometricPermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "android"){ return resolve(true) @@ -127,7 +127,7 @@ export const hasBiometricPermissions = (requestPermissions) => { }) } -export const hasPhotoLibraryPermissions = (requestPermissions) => { +export const hasPhotoLibraryPermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "android"){ hasStoragePermissions().then(resolve).catch(reject) @@ -154,7 +154,7 @@ export const hasPhotoLibraryPermissions = (requestPermissions) => { }) } -export const hasStoragePermissions = (requestPermissions) => { +export const hasStoragePermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "ios"){ return resolve(true) @@ -178,7 +178,7 @@ export const hasStoragePermissions = (requestPermissions) => { }) } -export const hasLocationPermissions = (requestPermissions) => { +export const hasLocationPermissions = (requestPermissions = true) => { return new Promise(async (resolve, reject) => { if(Platform.OS == "android"){ check(PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION).then((status) => { diff --git a/src/lib/services/items.js b/src/lib/services/items.js index 519df3052..378f99f2f 100644 --- a/src/lib/services/items.js +++ b/src/lib/services/items.js @@ -913,14 +913,14 @@ export const getThumbnailCacheKey = ({ uuid }) => { } /* -Clear last response cache when parent is in a route URL +Clear last response cache */ -export const clearLoadItemsCacheLastResponse = ({ parent }) => { +export const clearLoadItemsCacheLastResponse = () => { return new Promise((resolve, reject) => { const keys = storage.getAllKeys() for(let i = 0; i < keys.length; i++){ - if(keys[i].indexOf("loadItemsCache:lastResponse:") !== -1 && keys[i].indexOf(parent) !== -1){ + if(keys[i].indexOf("loadItemsCache:lastResponse:") !== -1){ storage.delete(keys[i]) } } diff --git a/src/lib/upload.js b/src/lib/upload.js index fdc0a54cc..f9c41e1ee 100644 --- a/src/lib/upload.js +++ b/src/lib/upload.js @@ -104,9 +104,11 @@ export const queueFileUpload = async ({ pickedFile, parent, progressCallback, ca showToast({ message: e.toString() }) } + let generatedFileName = pickedFile.name.split("/").join("_").split("\\").join("_") + var item = { uuid: "", - name: pickedFile.name, + name: generatedFileName, size: pickedFile.size, mime: pickedFile.type || "", key: "", @@ -119,12 +121,8 @@ export const queueFileUpload = async ({ pickedFile, parent, progressCallback, ca versionedUUID: undefined } - pickedFile.name = pickedFile.name.split("/").join("_").split("\\").join("_") - - let generatedFileName = "" - - if(pickedFile.name.indexOf(".") !== -1){ - let fileNameEx = pickedFile.name.split(".") + if(generatedFileName.indexOf(".") !== -1){ + let fileNameEx = generatedFileName.split(".") let lowerCaseFileEnding = fileNameEx[fileNameEx.length - 1].toLowerCase() fileNameEx.pop()