Skip to content

Commit

Permalink
adjust a bug with download
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Jan 8, 2024
1 parent 1dda756 commit 462a78a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
7 changes: 1 addition & 6 deletions capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ const config: CapacitorConfig = {
androidScheme: "https",
},
android: {
buildOptions: {
keystorePath:
"/Users/willkelly/Documents/Work/Code_support_files/DotMobile/DotMobileKs",
keystoreAlias: "key0",
signingType: "apksigner",
},
buildOptions: {},
},
};

Expand Down
25 changes: 17 additions & 8 deletions src/components/Settings/BulkListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function BulkListing({
const [booksToCancel, setBooksToCancel] = useState<Array<string | undefined>>(
[],
);

function allBooks() {
const allVals = Object.values(playlistData.formattedVideos).map((value) => {
return {
Expand Down Expand Up @@ -102,7 +103,7 @@ export function BulkListing({
}
}
}
function cancelButonText() {
function cancelButtonText() {
if (window.dotAppStopAllDownloads) {
return t("cancelling");
}
Expand Down Expand Up @@ -161,13 +162,17 @@ export function BulkListing({
vidName: currentVid.name || currentVid.reference_id || "unknown video",
vidId: currentVid.id || "",
});
// reset selection when action is finished
setBooksSelected(undefined);
setBookNamesSelected([]);
}, 1000);
window.dotAppBooksToCancel = [];
window.dotAppStopAllDownloads = false;
}
async function deleteSelectedBooks() {
if (!booksSelected) return;
for await (const book of booksSelected) {
async function deleteSelectedBooks(books?: IVidWithCustom[][]) {
const booksToUse = books ? books : booksSelected;
if (!booksToUse) return;
for await (const book of booksToUse) {
for await (const vidChapter of book) {
const vidSaver = makeVidSaver(playlistSlug, vidChapter);
const currentPlaylistData =
Expand All @@ -184,14 +189,19 @@ export function BulkListing({
setShapedPlaylist: setShapedPlaylist,
setCurrentVid: setCurrentVid,
});
// reset selection when action is finished
setBooksSelected(undefined);
setBookNamesSelected([]);
}

function addAllVidsFromBook(videos: IVidWithCustom[]) {
function clearBookFromFs(videos: IVidWithCustom[]) {
setBooksSelected((prev) => {
if (prev) {
const newState = [...prev, videos];
return newState;
}
// A side cb
deleteSelectedBooks([videos]);
return [videos];
});
}
Expand Down Expand Up @@ -222,7 +232,7 @@ export function BulkListing({
"--padding-top": ".625rem",
}}
>
{cancelButonText()}
{cancelButtonText()}
</IonButton>
</div>
<ul className="gap-4">
Expand All @@ -235,8 +245,7 @@ export function BulkListing({
bookNamesSelected={bookNamesSelected}
booksToCancel={booksToCancel}
setBooksToCancel={setBooksToCancel}
addAllVidsFromBook={addAllVidsFromBook}
deleteSelectedBooks={deleteSelectedBooks}
clearBookFromFs={clearBookFromFs}
/>
))}
</ul>
Expand Down
14 changes: 10 additions & 4 deletions src/components/Settings/DownloadBookItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type BookToDownloadProps = {
bookNamesSelected: string[];
booksToCancel: (string | undefined)[];
setBooksToCancel: Dispatch<SetStateAction<(string | undefined)[]>>;
addAllVidsFromBook(videos: IVidWithCustom[]): void;
deleteSelectedBooks(): Promise<void>;
clearBookFromFs(videos: IVidWithCustom[]): void;
};
function bookIsFullyDownloaded(book: IVidWithCustom[]) {
return book.every((vid) => !!vid.savedSources?.video);
}
export function BookToDownload(props: BookToDownloadProps) {
const { t } = useTranslation();
const { book } = props;
Expand Down Expand Up @@ -65,6 +67,9 @@ export function BookToDownload(props: BookToDownloadProps) {
function getCurrentProgress() {
return props.downloadProgress?.amount || 0;
}
function isChecked() {
return props.bookNamesSelected.includes(bookName || "");
}
return (
<li
key={book.bookName}
Expand All @@ -76,7 +81,9 @@ export function BookToDownload(props: BookToDownloadProps) {
onIonChange={(e) => {
props.handleChecked(e, book.value, bookName || "");
}}
checked={isChecked()}
labelPlacement="end"
disabled={bookIsFullyDownloaded(book.value)}
>
<span className="flex gap-1">
{book.bookName}{" "}
Expand All @@ -98,8 +105,7 @@ export function BookToDownload(props: BookToDownloadProps) {
color="primary"
className="text-surface"
onClick={() => {
props.addAllVidsFromBook(book.value);
props.deleteSelectedBooks();
props.clearBookFromFs(book.value);
}}
style={{
"--border-width": "1px",
Expand Down

0 comments on commit 462a78a

Please sign in to comment.