misc
This commit is contained in:
@@ -21,9 +21,11 @@ export default function MediaRequestForm() {
|
||||
const [isSearching, setIsSearching] = useState(false);
|
||||
const [loadingAlbumId, setLoadingAlbumId] = useState(null);
|
||||
const [expandedAlbums, setExpandedAlbums] = useState([]);
|
||||
const [isFetching, setIsFetching] = useState(false);
|
||||
|
||||
const debounceTimeout = useRef(null);
|
||||
const autoCompleteRef = useRef(null);
|
||||
const metadataFetchToastId = useRef(null);
|
||||
|
||||
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); // Helper for delays
|
||||
|
||||
@@ -111,7 +113,13 @@ export default function MediaRequestForm() {
|
||||
|
||||
// Search button click handler
|
||||
const handleSearch = async () => {
|
||||
toast.dismiss();
|
||||
setIsSearching(true);
|
||||
metadataFetchToastId.current = toast.info("Retrieving metadata...",
|
||||
{
|
||||
autoClose: false,
|
||||
}
|
||||
);
|
||||
if (type === "artist") {
|
||||
if (!selectedArtist) {
|
||||
toast.error("Please select a valid artist from suggestions.");
|
||||
@@ -221,6 +229,7 @@ export default function MediaRequestForm() {
|
||||
|
||||
const fetchTracksSequentially = async () => {
|
||||
const minDelay = 600; // ms between API requests
|
||||
setIsFetching(true);
|
||||
for (const album of albumsToFetch) {
|
||||
if (isCancelled) break;
|
||||
|
||||
@@ -242,7 +251,7 @@ export default function MediaRequestForm() {
|
||||
setTracksByAlbum((prev) => ({ ...prev, [album.id]: data }));
|
||||
setSelectedTracks((prev) => ({
|
||||
...prev,
|
||||
[album.id]: data.map((t) => String(t.id)),
|
||||
[album.id]: data.map((t) => t.id),
|
||||
}));
|
||||
} catch (err) {
|
||||
toast.error(`Failed to fetch tracks for album ${album.album}.`);
|
||||
@@ -251,6 +260,12 @@ export default function MediaRequestForm() {
|
||||
}
|
||||
}
|
||||
setLoadingAlbumId(null);
|
||||
setIsFetching(false);
|
||||
try {
|
||||
toast.done(metadataFetchToastId.current);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
};
|
||||
};
|
||||
|
||||
fetchTracksSequentially();
|
||||
@@ -311,6 +326,10 @@ export default function MediaRequestForm() {
|
||||
|
||||
// Submit request handler with progress indicator
|
||||
const handleSubmitRequest = async () => {
|
||||
if (isFetching) {
|
||||
// tracks are not done being fetched
|
||||
return toast.error("Still fetching track metadata, please wait a moment.");
|
||||
}
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
// Example: simulate submission delay
|
||||
|
||||
Reference in New Issue
Block a user