Skip to content

Commit

Permalink
2.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Apr 20, 2022
1 parent 299dafc commit ac99465
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/components/ActionSheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) || ""
Expand Down Expand Up @@ -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) || ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -435,6 +436,7 @@ export const TopBarActionSheet = memo(({ navigation }) => {
setCanShowRemoveSharedIn(true)
setCanShowStopSharing(true)
setCanMakeAvailableOffline(true)
setCanDownload(true)

if(routeURL.indexOf("photos") !== -1){
setCanShowListViewStyle(false)
Expand Down
110 changes: 105 additions & 5 deletions src/components/Toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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([
Expand All @@ -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
Expand Down Expand Up @@ -401,7 +427,7 @@ export const MoveToast = memo(({ message }) => {
}
}}>
<Text style={{
color: "white"
color: (currentRouteURL.indexOf("shared-in") == -1 && currentRouteURL.indexOf("recents") == -1 && currentRouteURL.indexOf("trash") == -1 && currentRouteURL.indexOf("photos") == -1 && currentRouteURL.indexOf("offline") == -1 && currentParent.length > 32) ? darkMode ? "white" : "black" : "gray"
}}>
{i18n(lang, "move")}
</Text>
Expand All @@ -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([])
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -587,7 +637,7 @@ export const UploadToast = memo(({ message }) => {
hideAllToasts()
}}>
<Text style={{
color: darkMode ? "white" : "black"
color: (currentRouteURL.indexOf("shared-in") == -1 && currentRouteURL.indexOf("recents") == -1 && currentRouteURL.indexOf("trash") == -1 && currentRouteURL.indexOf("photos") == -1 && currentRouteURL.indexOf("offline") == -1 && currentParent.length > 32) ? darkMode ? "white" : "black" : "gray"
}}>
{i18n(lang, "upload")}
</Text>
Expand All @@ -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 (
<View style={{
Expand Down Expand Up @@ -663,6 +727,16 @@ export const CameraUploadChooseFolderToast = memo(({ message, navigation }) => {
}} 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

Expand Down Expand Up @@ -718,7 +792,7 @@ export const CameraUploadChooseFolderToast = memo(({ message, navigation }) => {
})
}}>
<Text style={{
color: darkMode ? "white" : "black"
color: (currentRouteURL.indexOf("shared-in") == -1 && currentRouteURL.indexOf("recents") == -1 && currentRouteURL.indexOf("trash") == -1 && currentRouteURL.indexOf("photos") == -1 && currentRouteURL.indexOf("offline") == -1 && currentParent.length > 32) ? darkMode ? "white" : "black" : "gray"
}}>
{i18n(lang, "choose")}
</Text>
Expand All @@ -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", {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -880,7 +980,7 @@ export const MoveBulkToast = memo(({ message }) => {
})
}}>
<Text style={{
color: "white"
color: (currentRouteURL.indexOf("shared-in") == -1 && currentRouteURL.indexOf("recents") == -1 && currentRouteURL.indexOf("trash") == -1 && currentRouteURL.indexOf("photos") == -1 && currentRouteURL.indexOf("offline") == -1 && currentParent.length > 32) ? darkMode ? "white" : "black" : "gray"
}}>
{i18n(lang, "move")}
</Text>
Expand Down
4 changes: 1 addition & 3 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1787,9 +1787,7 @@ export const restoreItem = ({ item }) => {
item,
routeURL: "trash"
}).then(() => {
clearLoadItemsCacheLastResponse({
parent: item.parent
}).then(() => {
clearLoadItemsCacheLastResponse().then(() => {
return resolve()
})
})
Expand Down
22 changes: 22 additions & 0 deletions src/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/lib/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/services/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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()
Expand Down

0 comments on commit ac99465

Please sign in to comment.