This commit is contained in:
Fredrik Burmester
2024-09-28 20:24:39 +02:00
parent ddcb410df6
commit ff88c45d43
11 changed files with 26 additions and 111 deletions

View File

@@ -39,59 +39,6 @@ const downloads: React.FC = () => {
return Object.values(series);
}, [downloadedFiles]);
useEffect(() => {
(async () => {
const dir = FileSystem.documentDirectory;
if (dir) {
const items = await FileSystem.readDirectoryAsync(dir);
if (items.length === 0) {
console.log("No items found in the document directory.");
return;
}
for (const item of items) {
const fullPath = `${dir}${item}`;
const info = await FileSystem.getInfoAsync(fullPath);
if (info.exists) {
if (info.isDirectory) {
// List items in the directory
// const subItems = await FileSystem.readDirectoryAsync(fullPath);
// if (subItems.length === 0) {
// console.log(`Directory ${item} is empty.`);
// } else {
// console.log(`Items in ${item}:`, subItems);
// // If item ends in m3u8, print the content of the file
// const m3u8Files = subItems.filter((subItem) =>
// subItem.endsWith(".m3u8")
// );
// if (m3u8Files.length === 0) {
// console.log(`No .m3u8 files found in ${item}.`);
// } else {
// for (let subItem of m3u8Files) {
// console.log(
// `Content of ${subItem}:`,
// await FileSystem.readAsStringAsync(
// `${fullPath}/${subItem}`
// )
// );
// }
// }
// }
} else {
console.log(`${item} is a file`);
}
} else {
console.log(`${item} does not exist.`);
}
}
} else {
console.log("Document directory is not available.");
}
})();
}, []);
const insets = useSafeAreaInsets();
return (
@@ -121,9 +68,9 @@ const downloads: React.FC = () => {
<TouchableOpacity
onPress={() => {
clearProcess();
setQueue(async (prev) => {
setQueue((prev) => {
if (!prev) return [];
return [...(await prev).filter((i) => i.id !== q.id)];
return [...prev.filter((i) => i.id !== q.id)];
});
}}
>

View File

@@ -39,7 +39,6 @@ export default function settings() {
code: text,
userId: user?.Id,
});
console.log(res.status, res.statusText, res.data);
if (res.status === 200) {
Haptics.notificationAsync(
Haptics.NotificationFeedbackType.Success

View File

@@ -20,8 +20,6 @@ const page: React.FC = () => {
seasonIndex: string;
};
console.log("seasonIndex", seasonIndex);
const [api] = useAtom(apiAtom);
const [user] = useAtom(userAtom);

View File

@@ -69,13 +69,11 @@ const Page = () => {
useEffect(() => {
const sop = getSortOrderPreference(libraryId, sortOrderPreference);
if (sop) {
console.log("getSortOrderPreference ~", sop, libraryId);
_setSortOrder([sop]);
} else {
_setSortOrder([SortOrderOption.Ascending]);
}
const obp = getSortByPreference(libraryId, sortByPreference);
console.log("getSortByPreference ~", obp, libraryId);
if (obp) {
_setSortBy([obp]);
} else {
@@ -87,7 +85,6 @@ const Page = () => {
(sortBy: SortByOption[]) => {
const sop = getSortByPreference(libraryId, sortByPreference);
if (sortBy[0] !== sop) {
console.log("setSortByPreference ~", sortBy[0], libraryId);
setSortByPreference({ ...sortByPreference, [libraryId]: sortBy[0] });
}
_setSortBy(sortBy);
@@ -99,7 +96,6 @@ const Page = () => {
(sortOrder: SortOrderOption[]) => {
const sop = getSortOrderPreference(libraryId, sortOrderPreference);
if (sortOrder[0] !== sop) {
console.log("setSortOrderPreference ~", sortOrder[0], libraryId);
setOderByPreference({
...sortOrderPreference,
[libraryId]: sortOrder[0],

View File

@@ -99,7 +99,6 @@ function Layout() {
useEffect(() => {
const subscription = ScreenOrientation.addOrientationChangeListener(
(event) => {
console.log(event.orientationInfo.orientation);
setOrientation(event.orientationInfo.orientation);
}
);

View File

@@ -29,6 +29,7 @@ import { Loader } from "./Loader";
import { MediaSourceSelector } from "./MediaSourceSelector";
import ProgressCircle from "./ProgressCircle";
import { SubtitleTrackSelector } from "./SubtitleTrackSelector";
import { toast } from "sonner-native";
interface DownloadProps extends ViewProps {
item: BaseItemDto;
@@ -65,9 +66,7 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
bottomSheetModalRef.current?.present();
}, []);
const handleSheetChanges = useCallback((index: number) => {
console.log("handleSheetChanges", index);
}, []);
const handleSheetChanges = useCallback((index: number) => {}, []);
const closeModal = useCallback(() => {
bottomSheetModalRef.current?.dismiss();
@@ -286,22 +285,19 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
onPress={() => {
if (userCanDownload === true) {
if (!item.Id) {
Alert.alert("Error", "Item ID is undefined.");
return;
throw new Error("No item id");
}
closeModal();
queueActions.enqueue(queue, setQueue, {
id: item.Id,
execute: async () => {
await initiateDownload();
},
item,
});
initiateDownload();
// Remove for now
// queueActions.enqueue(queue, setQueue, {
// id: item.Id,
// execute: async () => {
// },
// item,
// });
} else {
Alert.alert(
"Disabled",
"This user is not allowed to download files."
);
toast.error("You are not allowed to download files.");
}
}}
color="purple"

View File

@@ -118,8 +118,6 @@ export const ItemContent: React.FC<{ id: string }> = React.memo(({ id }) => {
itemId: id,
});
console.log("itemID", res?.Id);
return res;
},
enabled: !!id && !!api,

View File

@@ -163,7 +163,6 @@ export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
});
break;
case 1:
console.log("Device");
setCurrentlyPlayingState({ item, url });
router.push("/play");
break;

View File

@@ -76,7 +76,6 @@ export const ActiveDownload: React.FC<Props> = ({ ...props }) => {
<View className="p-4 flex flex-row items-center justify-between w-full">
<View>
<Text className="font-semibold">{process.item.Name}</Text>
<Text className="text-xs opacity-50">{process.item.Id}</Text>
<Text className="text-xs opacity-50">{process.item.Type}</Text>
<View className="flex flex-row items-center space-x-2 mt-1 text-purple-600">
<Text className="text-xs">{process.progress.toFixed(0)}%</Text>

View File

@@ -14,6 +14,7 @@ import {
} from "@tanstack/react-query";
import axios from "axios";
import * as FileSystem from "expo-file-system";
import { useRouter } from "expo-router";
import React, {
createContext,
useCallback,
@@ -42,7 +43,7 @@ function useDownloadProvider() {
const queryClient = useQueryClient();
const [process, setProcess] = useState<ProcessItem | null>(null);
const [settings] = useSettings();
const router = useRouter();
const authHeader = useMemo(() => {
return `Bearer ${settings?.optimizedVersionsAuthHeader}`;
}, [settings]);
@@ -185,8 +186,6 @@ function useDownloadProvider() {
return;
}
// console.log("Job ~", job);
// Update the local process state with the state from the server.
let newState: ProcessItem["state"] = "optimizing";
if (job.status === "completed") {
@@ -260,7 +259,14 @@ function useDownloadProvider() {
state: "optimizing",
});
toast.success(`Optimization started for ${item.Name}`);
toast.success(`Optimization started for ${item.Name}`, {
action: {
label: "Go to download",
onClick: () => {
router.push("/downloads");
},
},
});
} catch (error) {
console.error("Error in startBackgroundDownload:", error);
toast.error(`Failed to start download for ${item.Name}`);

View File

@@ -10,31 +10,9 @@ export interface Job {
execute: () => void | Promise<void>;
}
export const runningAtom = atomWithStorage<boolean>("queueRunning", false, {
getItem: async (key) => {
const value = await AsyncStorage.getItem(key);
return value ? JSON.parse(value) : false;
},
setItem: async (key, value) => {
await AsyncStorage.setItem(key, JSON.stringify(value));
},
removeItem: async (key) => {
await AsyncStorage.removeItem(key);
},
});
export const runningAtom = atom<boolean>(false);
export const queueAtom = atomWithStorage<Job[]>("queueJobs", [], {
getItem: async (key) => {
const value = await AsyncStorage.getItem(key);
return value ? JSON.parse(value) : [];
},
setItem: async (key, value) => {
await AsyncStorage.setItem(key, JSON.stringify(value));
},
removeItem: async (key) => {
await AsyncStorage.removeItem(key);
},
});
export const queueAtom = atom<Job[]>([]);
export const queueActions = {
enqueue: (queue: Job[], setQueue: (update: Job[]) => void, job: Job) => {