@behindthemusictree/app-kit 35.0.0 → 37.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-4TE4OSOM.js → chunk-7S6EALIP.js} +90 -26
- package/dist/chunk-7S6EALIP.js.map +1 -0
- package/dist/{chunk-HLAKW2YJ.js → chunk-G5ULARLT.js} +1 -1
- package/dist/{chunk-ULSVAC23.js → chunk-XIJPC7D5.js} +45 -34
- package/dist/chunk-XIJPC7D5.js.map +1 -0
- package/dist/genre-tree/index.cjs +338 -265
- package/dist/genre-tree/index.cjs.map +1 -1
- package/dist/genre-tree/index.d.ts +51 -2
- package/dist/genre-tree/index.js +2 -2
- package/dist/index.cjs +413 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -3
- package/dist/transport/index.cjs +198 -130
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.ts +30 -6
- package/dist/transport/index.js +6 -2
- package/dist/useFetchWrapper-C5lt5fQz.d.ts +15 -0
- package/package.json +1 -1
- package/dist/chunk-4TE4OSOM.js.map +0 -1
- package/dist/chunk-ULSVAC23.js.map +0 -1
- package/dist/scope-BoMVOHmz.d.ts +0 -4
- /package/dist/{chunk-HLAKW2YJ.js.map → chunk-G5ULARLT.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -190,6 +190,8 @@ __export(src_exports, {
|
|
|
190
190
|
useListTracks: () => useListTracks,
|
|
191
191
|
useLogout: () => useLogout,
|
|
192
192
|
usePlaybackContext: () => usePlaybackContext,
|
|
193
|
+
usePlaybackFetch: () => usePlaybackFetch,
|
|
194
|
+
usePlaybackQuery: () => usePlaybackQuery,
|
|
193
195
|
usePlayer: () => usePlayer,
|
|
194
196
|
usePopup: () => usePopup,
|
|
195
197
|
usePrefetchGenreOverview: () => usePrefetchGenreOverview,
|
|
@@ -670,110 +672,25 @@ var fetchWrapper = async (url, requiresAuth, options = {}, accessToken, queryPar
|
|
|
670
672
|
}
|
|
671
673
|
};
|
|
672
674
|
|
|
673
|
-
// src/transport/PlaybackContext.tsx
|
|
674
|
-
var import_react = require("react");
|
|
675
|
-
var import_zod = require("zod");
|
|
676
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
677
|
-
var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
|
|
678
|
-
var unmanaged = {
|
|
679
|
-
country: null,
|
|
680
|
-
key: null,
|
|
681
|
-
ready: true,
|
|
682
|
-
error: null,
|
|
683
|
-
isCurrent: (_key) => true,
|
|
684
|
-
snapshot: () => ({ key: null, country: null }),
|
|
685
|
-
refresh: async (_force = false) => null
|
|
686
|
-
};
|
|
687
|
-
var PlaybackContext = (0, import_react.createContext)(unmanaged);
|
|
688
|
-
var usePlaybackContext = () => (0, import_react.useContext)(PlaybackContext);
|
|
689
|
-
function PlaybackContextProvider({ children, loadContext }) {
|
|
690
|
-
const [state, setState] = (0, import_react.useState)({
|
|
691
|
-
country: null,
|
|
692
|
-
ready: false,
|
|
693
|
-
revision: 0,
|
|
694
|
-
error: null
|
|
695
|
-
});
|
|
696
|
-
const current = (0, import_react.useRef)(state);
|
|
697
|
-
const checkedAt = (0, import_react.useRef)(0);
|
|
698
|
-
const pending = (0, import_react.useRef)(null);
|
|
699
|
-
const refresh = (0, import_react.useCallback)((force = false) => {
|
|
700
|
-
if (pending.current) return pending.current;
|
|
701
|
-
if (!force && current.current.ready && Date.now() - checkedAt.current < 6e4) {
|
|
702
|
-
return Promise.resolve(current.current.country);
|
|
703
|
-
}
|
|
704
|
-
pending.current = loadContext().then((raw) => {
|
|
705
|
-
const { country } = PlaybackContextSchema.parse(raw);
|
|
706
|
-
const previous = current.current;
|
|
707
|
-
const next = {
|
|
708
|
-
country,
|
|
709
|
-
ready: true,
|
|
710
|
-
error: null,
|
|
711
|
-
revision: previous.revision + (country !== previous.country ? 1 : 0)
|
|
712
|
-
};
|
|
713
|
-
current.current = next;
|
|
714
|
-
checkedAt.current = Date.now();
|
|
715
|
-
setState(next);
|
|
716
|
-
return country;
|
|
717
|
-
}).catch((error) => {
|
|
718
|
-
const next = {
|
|
719
|
-
...current.current,
|
|
720
|
-
error: error instanceof Error ? error.message : "Unable to check playback location"
|
|
721
|
-
};
|
|
722
|
-
current.current = next;
|
|
723
|
-
setState(next);
|
|
724
|
-
throw error;
|
|
725
|
-
}).finally(() => {
|
|
726
|
-
pending.current = null;
|
|
727
|
-
});
|
|
728
|
-
return pending.current;
|
|
729
|
-
}, [loadContext]);
|
|
730
|
-
(0, import_react.useEffect)(() => {
|
|
731
|
-
const update = () => {
|
|
732
|
-
void refresh(true).catch(() => {
|
|
733
|
-
});
|
|
734
|
-
};
|
|
735
|
-
update();
|
|
736
|
-
window.addEventListener("focus", update);
|
|
737
|
-
window.addEventListener("online", update);
|
|
738
|
-
return () => {
|
|
739
|
-
window.removeEventListener("focus", update);
|
|
740
|
-
window.removeEventListener("online", update);
|
|
741
|
-
};
|
|
742
|
-
}, [refresh]);
|
|
743
|
-
const isCurrent = (0, import_react.useCallback)(
|
|
744
|
-
(key) => key === `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
745
|
-
[]
|
|
746
|
-
);
|
|
747
|
-
const snapshot = (0, import_react.useCallback)(() => ({
|
|
748
|
-
key: `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
749
|
-
country: current.current.country
|
|
750
|
-
}), []);
|
|
751
|
-
const value = (0, import_react.useMemo)(() => ({
|
|
752
|
-
...state,
|
|
753
|
-
isCurrent,
|
|
754
|
-
snapshot,
|
|
755
|
-
key: `${state.country ?? "unknown"}:${state.revision}`,
|
|
756
|
-
refresh
|
|
757
|
-
}), [state, refresh, isCurrent, snapshot]);
|
|
758
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackContext.Provider, { value, children });
|
|
759
|
-
}
|
|
760
|
-
|
|
761
675
|
// src/transport/useFetchWrapper.ts
|
|
762
676
|
var import_react4 = require("react");
|
|
763
677
|
|
|
678
|
+
// src/transport/lib/use-backend-request.ts
|
|
679
|
+
var import_react3 = require("react");
|
|
680
|
+
|
|
764
681
|
// src/transport/connectivity-error-context.tsx
|
|
765
|
-
var
|
|
766
|
-
var
|
|
767
|
-
var ConnectivityErrorContext = (0,
|
|
682
|
+
var import_react = require("react");
|
|
683
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
684
|
+
var ConnectivityErrorContext = (0, import_react.createContext)(void 0);
|
|
768
685
|
function ConnectivityErrorProvider({ children }) {
|
|
769
|
-
const [connectivityError, setConnectivityError] = (0,
|
|
770
|
-
const clearConnectivityError = (0,
|
|
686
|
+
const [connectivityError, setConnectivityError] = (0, import_react.useState)(null);
|
|
687
|
+
const clearConnectivityError = (0, import_react.useCallback)(() => {
|
|
771
688
|
setConnectivityError(null);
|
|
772
689
|
}, []);
|
|
773
|
-
const handleSetConnectivityError = (0,
|
|
690
|
+
const handleSetConnectivityError = (0, import_react.useCallback)((error) => {
|
|
774
691
|
setConnectivityError(error);
|
|
775
692
|
}, []);
|
|
776
|
-
const value = (0,
|
|
693
|
+
const value = (0, import_react.useMemo)(
|
|
777
694
|
() => ({
|
|
778
695
|
connectivityError,
|
|
779
696
|
setConnectivityError: handleSetConnectivityError,
|
|
@@ -781,10 +698,10 @@ function ConnectivityErrorProvider({ children }) {
|
|
|
781
698
|
}),
|
|
782
699
|
[connectivityError, handleSetConnectivityError, clearConnectivityError]
|
|
783
700
|
);
|
|
784
|
-
return /* @__PURE__ */ (0,
|
|
701
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConnectivityErrorContext.Provider, { value, children });
|
|
785
702
|
}
|
|
786
703
|
function useConnectivityError() {
|
|
787
|
-
const context = (0,
|
|
704
|
+
const context = (0, import_react.useContext)(ConnectivityErrorContext);
|
|
788
705
|
if (context === void 0) {
|
|
789
706
|
throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
|
|
790
707
|
}
|
|
@@ -792,7 +709,7 @@ function useConnectivityError() {
|
|
|
792
709
|
}
|
|
793
710
|
|
|
794
711
|
// src/auth/SessionContext.tsx
|
|
795
|
-
var
|
|
712
|
+
var import_react2 = require("react");
|
|
796
713
|
|
|
797
714
|
// src/transport/query-client.ts
|
|
798
715
|
var import_react_query = require("@tanstack/react-query");
|
|
@@ -822,18 +739,18 @@ function clearSpotifyRequiredCached() {
|
|
|
822
739
|
}
|
|
823
740
|
|
|
824
741
|
// src/auth/SessionContext.tsx
|
|
825
|
-
var
|
|
742
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
826
743
|
var defaultSession = {
|
|
827
744
|
accessToken: null,
|
|
828
745
|
refreshToken: null,
|
|
829
746
|
expiresAt: null
|
|
830
747
|
};
|
|
831
748
|
var SESSION_STORAGE_KEY = "session";
|
|
832
|
-
var SessionContext = (0,
|
|
749
|
+
var SessionContext = (0, import_react2.createContext)(void 0);
|
|
833
750
|
function SessionProvider({ children }) {
|
|
834
|
-
const [session, setSessionState] = (0,
|
|
835
|
-
const [sessionRestored, setSessionRestored] = (0,
|
|
836
|
-
(0,
|
|
751
|
+
const [session, setSessionState] = (0, import_react2.useState)(defaultSession);
|
|
752
|
+
const [sessionRestored, setSessionRestored] = (0, import_react2.useState)(false);
|
|
753
|
+
(0, import_react2.useEffect)(() => {
|
|
837
754
|
const storedSession = localStorage.getItem(SESSION_STORAGE_KEY);
|
|
838
755
|
if (storedSession) {
|
|
839
756
|
try {
|
|
@@ -848,36 +765,35 @@ function SessionProvider({ children }) {
|
|
|
848
765
|
}
|
|
849
766
|
setSessionRestored(true);
|
|
850
767
|
}, []);
|
|
851
|
-
const setSession = (0,
|
|
768
|
+
const setSession = (0, import_react2.useCallback)((newSession) => {
|
|
852
769
|
setSessionState(newSession);
|
|
853
770
|
localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(newSession));
|
|
854
771
|
}, []);
|
|
855
|
-
const clearSession = (0,
|
|
772
|
+
const clearSession = (0, import_react2.useCallback)(() => {
|
|
856
773
|
setSessionState(defaultSession);
|
|
857
774
|
localStorage.removeItem(SESSION_STORAGE_KEY);
|
|
858
775
|
clearSpotifyRequiredCached();
|
|
859
776
|
queryClient.clear();
|
|
860
777
|
}, []);
|
|
861
|
-
const value = (0,
|
|
778
|
+
const value = (0, import_react2.useMemo)(
|
|
862
779
|
() => ({ session, setSession, clearSession, sessionRestored }),
|
|
863
780
|
[session, setSession, clearSession, sessionRestored]
|
|
864
781
|
);
|
|
865
|
-
return /* @__PURE__ */ (0,
|
|
782
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionContext.Provider, { value, children });
|
|
866
783
|
}
|
|
867
784
|
function useSession() {
|
|
868
|
-
const context = (0,
|
|
785
|
+
const context = (0, import_react2.useContext)(SessionContext);
|
|
869
786
|
if (context === void 0) {
|
|
870
787
|
throw new Error("useSession must be used within a SessionProvider");
|
|
871
788
|
}
|
|
872
789
|
return context;
|
|
873
790
|
}
|
|
874
791
|
|
|
875
|
-
// src/transport/
|
|
876
|
-
var
|
|
877
|
-
const playback = usePlaybackContext();
|
|
792
|
+
// src/transport/lib/use-backend-request.ts
|
|
793
|
+
var useBackendRequest = (getBackendBaseUrl) => {
|
|
878
794
|
const { setConnectivityError } = useConnectivityError();
|
|
879
795
|
const { clearSession, session, sessionRestored } = useSession();
|
|
880
|
-
const handleError = (0,
|
|
796
|
+
const handleError = (0, import_react3.useCallback)((error) => {
|
|
881
797
|
if (error instanceof ConnectivityError) {
|
|
882
798
|
const authDetailErrors = [
|
|
883
799
|
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
@@ -904,53 +820,180 @@ var useFetchWrapper = (getBackendBaseUrl) => {
|
|
|
904
820
|
if (!sessionRestored) return;
|
|
905
821
|
setConnectivityError(createAppErrorFromErrorCode("SES4012" /* SESSION_REQUIRED */));
|
|
906
822
|
};
|
|
907
|
-
const
|
|
823
|
+
const request = (0, import_react3.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false, onResponse) => {
|
|
908
824
|
const baseUrl = getBackendBaseUrl().replace(/\/+$/, "");
|
|
909
825
|
const endpointPath = String(backendEndpointOrUrl);
|
|
910
826
|
if (fromBackend && endpointPath.startsWith("/")) {
|
|
911
827
|
throw new Error(`Endpoint path must be relative (no leading slash). Got: "${endpointPath}".`);
|
|
912
828
|
}
|
|
913
829
|
const url = fromBackend ? endpointPath ? `${baseUrl}/${endpointPath}` : baseUrl : backendEndpointOrUrl;
|
|
830
|
+
return fetchWrapper(
|
|
831
|
+
url,
|
|
832
|
+
requiresAuth,
|
|
833
|
+
options,
|
|
834
|
+
session?.accessToken || void 0,
|
|
835
|
+
queryParams,
|
|
836
|
+
handleMissingRequiredSession,
|
|
837
|
+
skipGlobalError ? void 0 : handleError,
|
|
838
|
+
expectBinary,
|
|
839
|
+
baseUrl,
|
|
840
|
+
onResponse
|
|
841
|
+
);
|
|
842
|
+
}, [session?.accessToken, handleError, getBackendBaseUrl, sessionRestored, setConnectivityError]);
|
|
843
|
+
return { request };
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
// src/transport/useFetchWrapper.ts
|
|
847
|
+
var useFetchWrapper = (getBackendBaseUrl) => {
|
|
848
|
+
const { request } = useBackendRequest(getBackendBaseUrl);
|
|
849
|
+
const fetch2 = (0, import_react4.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => {
|
|
850
|
+
const isRead = (options.method ?? "GET").toUpperCase() === "GET";
|
|
851
|
+
const warnOnStampedRead = isRead && fromBackend && process.env.NODE_ENV !== "production" ? (response) => {
|
|
852
|
+
if (response.headers.get("x-playback-country") !== null) {
|
|
853
|
+
console.error(
|
|
854
|
+
`GET ${backendEndpointOrUrl} is country-dependent (X-Playback-Country) but was fetched without the playback context. Use usePlaybackQuery/usePlaybackFetch.`
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
} : void 0;
|
|
858
|
+
return request(backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError, warnOnStampedRead);
|
|
859
|
+
}, [request]);
|
|
860
|
+
return { fetch: fetch2 };
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
// src/transport/usePlaybackFetch.ts
|
|
864
|
+
var import_react6 = require("react");
|
|
865
|
+
|
|
866
|
+
// src/transport/PlaybackContext.tsx
|
|
867
|
+
var import_react5 = require("react");
|
|
868
|
+
var import_zod = require("zod");
|
|
869
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
870
|
+
var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
|
|
871
|
+
var unmanaged = {
|
|
872
|
+
country: null,
|
|
873
|
+
key: null,
|
|
874
|
+
ready: true,
|
|
875
|
+
error: null,
|
|
876
|
+
isCurrent: (_key) => true,
|
|
877
|
+
snapshot: () => ({ key: null, country: null }),
|
|
878
|
+
refresh: async (_force = false) => null
|
|
879
|
+
};
|
|
880
|
+
var PlaybackContext = (0, import_react5.createContext)(unmanaged);
|
|
881
|
+
var usePlaybackContext = () => (0, import_react5.useContext)(PlaybackContext);
|
|
882
|
+
function PlaybackContextProvider({ children, loadContext }) {
|
|
883
|
+
const [state, setState] = (0, import_react5.useState)({
|
|
884
|
+
country: null,
|
|
885
|
+
ready: false,
|
|
886
|
+
revision: 0,
|
|
887
|
+
error: null
|
|
888
|
+
});
|
|
889
|
+
const current = (0, import_react5.useRef)(state);
|
|
890
|
+
const checkedAt = (0, import_react5.useRef)(0);
|
|
891
|
+
const pending = (0, import_react5.useRef)(null);
|
|
892
|
+
const refresh = (0, import_react5.useCallback)((force = false) => {
|
|
893
|
+
if (pending.current) return pending.current;
|
|
894
|
+
if (!force && current.current.ready && Date.now() - checkedAt.current < 6e4) {
|
|
895
|
+
return Promise.resolve(current.current.country);
|
|
896
|
+
}
|
|
897
|
+
pending.current = loadContext().then((raw) => {
|
|
898
|
+
const { country } = PlaybackContextSchema.parse(raw);
|
|
899
|
+
const previous = current.current;
|
|
900
|
+
const next = {
|
|
901
|
+
country,
|
|
902
|
+
ready: true,
|
|
903
|
+
error: null,
|
|
904
|
+
revision: previous.revision + (country !== previous.country ? 1 : 0)
|
|
905
|
+
};
|
|
906
|
+
current.current = next;
|
|
907
|
+
checkedAt.current = Date.now();
|
|
908
|
+
setState(next);
|
|
909
|
+
return country;
|
|
910
|
+
}).catch((error) => {
|
|
911
|
+
const next = {
|
|
912
|
+
...current.current,
|
|
913
|
+
error: error instanceof Error ? error.message : "Unable to check playback location"
|
|
914
|
+
};
|
|
915
|
+
current.current = next;
|
|
916
|
+
setState(next);
|
|
917
|
+
throw error;
|
|
918
|
+
}).finally(() => {
|
|
919
|
+
pending.current = null;
|
|
920
|
+
});
|
|
921
|
+
return pending.current;
|
|
922
|
+
}, [loadContext]);
|
|
923
|
+
(0, import_react5.useEffect)(() => {
|
|
924
|
+
const update = () => {
|
|
925
|
+
void refresh(true).catch(() => {
|
|
926
|
+
});
|
|
927
|
+
};
|
|
928
|
+
update();
|
|
929
|
+
window.addEventListener("focus", update);
|
|
930
|
+
window.addEventListener("online", update);
|
|
931
|
+
return () => {
|
|
932
|
+
window.removeEventListener("focus", update);
|
|
933
|
+
window.removeEventListener("online", update);
|
|
934
|
+
};
|
|
935
|
+
}, [refresh]);
|
|
936
|
+
const isCurrent = (0, import_react5.useCallback)(
|
|
937
|
+
(key) => key === `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
938
|
+
[]
|
|
939
|
+
);
|
|
940
|
+
const snapshot = (0, import_react5.useCallback)(() => ({
|
|
941
|
+
key: `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
942
|
+
country: current.current.country
|
|
943
|
+
}), []);
|
|
944
|
+
const value = (0, import_react5.useMemo)(() => ({
|
|
945
|
+
...state,
|
|
946
|
+
isCurrent,
|
|
947
|
+
snapshot,
|
|
948
|
+
key: `${state.country ?? "unknown"}:${state.revision}`,
|
|
949
|
+
refresh
|
|
950
|
+
}), [state, refresh, isCurrent, snapshot]);
|
|
951
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PlaybackContext.Provider, { value, children });
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// src/transport/usePlaybackFetch.ts
|
|
955
|
+
var stale = () => new DOMException("Playback context changed", "AbortError");
|
|
956
|
+
var usePlaybackFetch = (getBackendBaseUrl) => {
|
|
957
|
+
const playback = usePlaybackContext();
|
|
958
|
+
const { request } = useBackendRequest(getBackendBaseUrl);
|
|
959
|
+
const run = (0, import_react6.useCallback)((adoptRefreshed, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError) => {
|
|
914
960
|
const perform = async (retryContextChange) => {
|
|
915
|
-
const contextual = playback.key !== null && fromBackend && /^(?:me\/)?(library\/songs|genre-playlists|playlists|manual-playlists)\//.test(endpointPath);
|
|
916
961
|
let requestContext = { key: playback.key, country: playback.country };
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
if (!playback.isCurrent(requestContext.key)) throw new DOMException("Playback context changed", "AbortError");
|
|
921
|
-
}
|
|
962
|
+
await playback.refresh();
|
|
963
|
+
if (adoptRefreshed) requestContext = playback.snapshot();
|
|
964
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
922
965
|
try {
|
|
923
|
-
const result = await
|
|
924
|
-
|
|
966
|
+
const result = await request(
|
|
967
|
+
backendEndpointOrUrl,
|
|
968
|
+
fromBackend,
|
|
925
969
|
requiresAuth,
|
|
926
970
|
options,
|
|
927
|
-
session?.accessToken || void 0,
|
|
928
971
|
queryParams,
|
|
929
|
-
handleMissingRequiredSession,
|
|
930
|
-
skipGlobalError ? void 0 : handleError,
|
|
931
972
|
expectBinary,
|
|
932
|
-
|
|
933
|
-
|
|
973
|
+
skipGlobalError,
|
|
974
|
+
async (response) => {
|
|
934
975
|
const responseCountry = response.headers.get("x-playback-country");
|
|
935
|
-
if (responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
|
|
976
|
+
if (playback.key !== null && responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
|
|
936
977
|
await playback.refresh(true);
|
|
937
|
-
throw
|
|
978
|
+
throw stale();
|
|
938
979
|
}
|
|
939
|
-
if (!playback.isCurrent(requestContext.key)) throw
|
|
940
|
-
}
|
|
980
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
981
|
+
}
|
|
941
982
|
);
|
|
942
|
-
if (
|
|
983
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
943
984
|
return result;
|
|
944
985
|
} catch (error) {
|
|
945
|
-
if (retryContextChange &&
|
|
986
|
+
if (retryContextChange && error instanceof DOMException && error.name === "AbortError" && !playback.isCurrent(requestContext.key)) {
|
|
946
987
|
return perform(false);
|
|
947
988
|
}
|
|
948
989
|
throw error;
|
|
949
990
|
}
|
|
950
991
|
};
|
|
951
|
-
return perform(
|
|
952
|
-
}, [
|
|
953
|
-
|
|
992
|
+
return perform(adoptRefreshed);
|
|
993
|
+
}, [playback, request]);
|
|
994
|
+
const fetchBound = (0, import_react6.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(false, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
|
|
995
|
+
const fetchLatest = (0, import_react6.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(true, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
|
|
996
|
+
return { fetchBound, fetchLatest };
|
|
954
997
|
};
|
|
955
998
|
|
|
956
999
|
// src/transport/site-urls.ts
|
|
@@ -1017,9 +1060,32 @@ function useQueryWithParse({
|
|
|
1017
1060
|
});
|
|
1018
1061
|
}
|
|
1019
1062
|
|
|
1063
|
+
// src/transport/lib/use-playback-query.ts
|
|
1064
|
+
var import_react7 = require("react");
|
|
1065
|
+
function usePlaybackQuery({
|
|
1066
|
+
queryKey,
|
|
1067
|
+
getBackendBaseUrl,
|
|
1068
|
+
queryFn,
|
|
1069
|
+
enabled = true,
|
|
1070
|
+
retry,
|
|
1071
|
+
...options
|
|
1072
|
+
}) {
|
|
1073
|
+
const playback = usePlaybackContext();
|
|
1074
|
+
const { fetchBound } = usePlaybackFetch(getBackendBaseUrl);
|
|
1075
|
+
const run = (0, import_react7.useCallback)((context) => queryFn(fetchBound, context), [queryFn, fetchBound]);
|
|
1076
|
+
return useQueryWithParse({
|
|
1077
|
+
...options,
|
|
1078
|
+
queryKey: [...queryKey, ...playback.key ? [playback.key] : []],
|
|
1079
|
+
queryFn: run,
|
|
1080
|
+
enabled: typeof enabled === "function" ? (query) => playback.ready && enabled(query) : enabled && playback.ready,
|
|
1081
|
+
retry: (failureCount, error) => failureCount < 1 && error instanceof DOMException && error.name === "AbortError" || (retry?.(failureCount, error) ?? false),
|
|
1082
|
+
retryDelay: 0
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1020
1086
|
// src/transport/lib/use-validated-mutation.ts
|
|
1021
1087
|
var import_react_query3 = require("@tanstack/react-query");
|
|
1022
|
-
var
|
|
1088
|
+
var import_react8 = require("react");
|
|
1023
1089
|
var import_zod4 = require("zod");
|
|
1024
1090
|
function useValidatedMutation({
|
|
1025
1091
|
inputSchema,
|
|
@@ -1027,7 +1093,7 @@ function useValidatedMutation({
|
|
|
1027
1093
|
mutationFn,
|
|
1028
1094
|
...options
|
|
1029
1095
|
}) {
|
|
1030
|
-
const [formErrors, setFormErrors] = (0,
|
|
1096
|
+
const [formErrors, setFormErrors] = (0, import_react8.useState)([]);
|
|
1031
1097
|
const validatedMutation = (0, import_react_query3.useMutation)({
|
|
1032
1098
|
...options,
|
|
1033
1099
|
mutationFn: async (data) => {
|
|
@@ -1154,11 +1220,11 @@ function createLogout(clearConnectivityError, clearSession) {
|
|
|
1154
1220
|
}
|
|
1155
1221
|
|
|
1156
1222
|
// src/auth/useLogout.ts
|
|
1157
|
-
var
|
|
1223
|
+
var import_react9 = require("react");
|
|
1158
1224
|
function useLogout() {
|
|
1159
1225
|
const { clearSession } = useSession();
|
|
1160
1226
|
const { clearConnectivityError } = useConnectivityError();
|
|
1161
|
-
const logout = (0,
|
|
1227
|
+
const logout = (0, import_react9.useCallback)(
|
|
1162
1228
|
createLogout(clearConnectivityError, clearSession),
|
|
1163
1229
|
[clearConnectivityError, clearSession]
|
|
1164
1230
|
);
|
|
@@ -1166,7 +1232,7 @@ function useLogout() {
|
|
|
1166
1232
|
}
|
|
1167
1233
|
|
|
1168
1234
|
// src/auth/useAuthCallback.ts
|
|
1169
|
-
var
|
|
1235
|
+
var import_react10 = require("react");
|
|
1170
1236
|
var import_navigation = require("next/navigation");
|
|
1171
1237
|
function useAuthCallback({
|
|
1172
1238
|
googleCallbackPathname = "/auth/google/callback",
|
|
@@ -1178,10 +1244,10 @@ function useAuthCallback({
|
|
|
1178
1244
|
onSpotifyAuthError
|
|
1179
1245
|
}) {
|
|
1180
1246
|
const router = (0, import_navigation.useRouter)();
|
|
1181
|
-
const [state, setState] = (0,
|
|
1182
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
1183
|
-
const handled = (0,
|
|
1184
|
-
(0,
|
|
1247
|
+
const [state, setState] = (0, import_react10.useState)("idle");
|
|
1248
|
+
const [errorMessage, setErrorMessage] = (0, import_react10.useState)(null);
|
|
1249
|
+
const handled = (0, import_react10.useRef)(false);
|
|
1250
|
+
(0, import_react10.useEffect)(() => {
|
|
1185
1251
|
if (typeof window === "undefined" || handled.current) return;
|
|
1186
1252
|
const pathname = window.location.pathname;
|
|
1187
1253
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -1269,28 +1335,28 @@ function useAuthCallback({
|
|
|
1269
1335
|
}
|
|
1270
1336
|
|
|
1271
1337
|
// src/popup/PopupContext.tsx
|
|
1272
|
-
var
|
|
1338
|
+
var import_react11 = require("react");
|
|
1273
1339
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1274
1340
|
var AUTH_POPUP_TYPE = "auth";
|
|
1275
|
-
var PopupContext = (0,
|
|
1341
|
+
var PopupContext = (0, import_react11.createContext)(void 0);
|
|
1276
1342
|
function PopupProvider({ children }) {
|
|
1277
|
-
const [state, setState] = (0,
|
|
1343
|
+
const [state, setState] = (0, import_react11.useState)({ content: null, type: null });
|
|
1278
1344
|
const activePopup = state.content;
|
|
1279
|
-
const showPopup = (0,
|
|
1345
|
+
const showPopup = (0, import_react11.useCallback)((popup, type) => {
|
|
1280
1346
|
setState({ content: popup, type: type ?? null });
|
|
1281
1347
|
}, []);
|
|
1282
|
-
const hidePopup = (0,
|
|
1348
|
+
const hidePopup = (0, import_react11.useCallback)((options) => {
|
|
1283
1349
|
if (options?.onlyIfType !== void 0) {
|
|
1284
1350
|
setState((prev) => prev.type === options.onlyIfType ? { content: null, type: null } : prev);
|
|
1285
1351
|
} else {
|
|
1286
1352
|
setState({ content: null, type: null });
|
|
1287
1353
|
}
|
|
1288
1354
|
}, []);
|
|
1289
|
-
const value = (0,
|
|
1355
|
+
const value = (0, import_react11.useMemo)(() => ({ showPopup, hidePopup, activePopup }), [showPopup, hidePopup, activePopup]);
|
|
1290
1356
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PopupContext.Provider, { value, children });
|
|
1291
1357
|
}
|
|
1292
1358
|
function usePopup() {
|
|
1293
|
-
const context = (0,
|
|
1359
|
+
const context = (0, import_react11.useContext)(PopupContext);
|
|
1294
1360
|
if (context === void 0) {
|
|
1295
1361
|
throw new Error("usePopup must be used within a PopupProvider");
|
|
1296
1362
|
}
|
|
@@ -1298,7 +1364,7 @@ function usePopup() {
|
|
|
1298
1364
|
}
|
|
1299
1365
|
|
|
1300
1366
|
// src/popup/useConnectivityErrorPopup.ts
|
|
1301
|
-
var
|
|
1367
|
+
var import_react12 = require("react");
|
|
1302
1368
|
var ALWAYS_REDISPLAY_ON_REPEAT = [NetworkError, BackendError, ClientError, ServiceError, InvalidInputError];
|
|
1303
1369
|
function useConnectivityErrorPopup({
|
|
1304
1370
|
isAccountPage,
|
|
@@ -1308,10 +1374,10 @@ function useConnectivityErrorPopup({
|
|
|
1308
1374
|
}) {
|
|
1309
1375
|
const { showPopup, hidePopup } = usePopup();
|
|
1310
1376
|
const { connectivityError, clearConnectivityError } = useConnectivityError();
|
|
1311
|
-
const currentConnectivityErrorRef = (0,
|
|
1312
|
-
const renderersRef = (0,
|
|
1377
|
+
const currentConnectivityErrorRef = (0, import_react12.useRef)(null);
|
|
1378
|
+
const renderersRef = (0, import_react12.useRef)(renderers);
|
|
1313
1379
|
renderersRef.current = renderers;
|
|
1314
|
-
(0,
|
|
1380
|
+
(0, import_react12.useEffect)(() => {
|
|
1315
1381
|
if (connectivityError === null) {
|
|
1316
1382
|
if (currentConnectivityErrorRef.current !== null) {
|
|
1317
1383
|
currentConnectivityErrorRef.current = null;
|
|
@@ -1378,7 +1444,7 @@ function useConnectivityErrorPopup({
|
|
|
1378
1444
|
}
|
|
1379
1445
|
|
|
1380
1446
|
// src/popup/useTrackUpload.ts
|
|
1381
|
-
var
|
|
1447
|
+
var import_react13 = require("react");
|
|
1382
1448
|
function useTrackUpload({
|
|
1383
1449
|
files,
|
|
1384
1450
|
genre,
|
|
@@ -1386,15 +1452,15 @@ function useTrackUpload({
|
|
|
1386
1452
|
onComplete,
|
|
1387
1453
|
uploadTimeoutMs
|
|
1388
1454
|
}) {
|
|
1389
|
-
const [items, setItems] = (0,
|
|
1390
|
-
const [currentUploadIndex, setCurrentUploadIndex] = (0,
|
|
1391
|
-
const [isUploading, setIsUploading] = (0,
|
|
1392
|
-
const [allComplete, setAllComplete] = (0,
|
|
1393
|
-
const lastFilesKeyRef = (0,
|
|
1394
|
-
const progressIntervalRef = (0,
|
|
1395
|
-
const runRef = (0,
|
|
1396
|
-
const completedRunRef = (0,
|
|
1397
|
-
(0,
|
|
1455
|
+
const [items, setItems] = (0, import_react13.useState)([]);
|
|
1456
|
+
const [currentUploadIndex, setCurrentUploadIndex] = (0, import_react13.useState)(0);
|
|
1457
|
+
const [isUploading, setIsUploading] = (0, import_react13.useState)(false);
|
|
1458
|
+
const [allComplete, setAllComplete] = (0, import_react13.useState)(false);
|
|
1459
|
+
const lastFilesKeyRef = (0, import_react13.useRef)(null);
|
|
1460
|
+
const progressIntervalRef = (0, import_react13.useRef)(null);
|
|
1461
|
+
const runRef = (0, import_react13.useRef)(0);
|
|
1462
|
+
const completedRunRef = (0, import_react13.useRef)(null);
|
|
1463
|
+
(0, import_react13.useEffect)(() => {
|
|
1398
1464
|
const filesKey = `${files.length}-${files.map((f) => `${f.name}:${f.size}`).join("|")}-${genre ?? ""}`;
|
|
1399
1465
|
if (lastFilesKeyRef.current === filesKey) return;
|
|
1400
1466
|
lastFilesKeyRef.current = filesKey;
|
|
@@ -1416,7 +1482,7 @@ function useTrackUpload({
|
|
|
1416
1482
|
setIsUploading(false);
|
|
1417
1483
|
setAllComplete(false);
|
|
1418
1484
|
}, [files, genre]);
|
|
1419
|
-
const startNextUpload = (0,
|
|
1485
|
+
const startNextUpload = (0, import_react13.useCallback)(() => {
|
|
1420
1486
|
const currentItem = items[currentUploadIndex];
|
|
1421
1487
|
setIsUploading(true);
|
|
1422
1488
|
setItems(
|
|
@@ -1461,7 +1527,7 @@ function useTrackUpload({
|
|
|
1461
1527
|
setCurrentUploadIndex((prev) => prev + 1);
|
|
1462
1528
|
});
|
|
1463
1529
|
}, [items, currentUploadIndex, onProcessFile, uploadTimeoutMs]);
|
|
1464
|
-
(0,
|
|
1530
|
+
(0, import_react13.useEffect)(() => {
|
|
1465
1531
|
return () => {
|
|
1466
1532
|
if (progressIntervalRef.current) {
|
|
1467
1533
|
clearInterval(progressIntervalRef.current);
|
|
@@ -1469,13 +1535,13 @@ function useTrackUpload({
|
|
|
1469
1535
|
}
|
|
1470
1536
|
};
|
|
1471
1537
|
}, []);
|
|
1472
|
-
(0,
|
|
1538
|
+
(0, import_react13.useEffect)(() => {
|
|
1473
1539
|
const shouldStart = items.length > 0 && !isUploading && currentUploadIndex < items.length;
|
|
1474
1540
|
if (shouldStart) {
|
|
1475
1541
|
startNextUpload();
|
|
1476
1542
|
}
|
|
1477
1543
|
}, [items, currentUploadIndex, isUploading, startNextUpload]);
|
|
1478
|
-
(0,
|
|
1544
|
+
(0, import_react13.useEffect)(() => {
|
|
1479
1545
|
if (items.length > 0 && currentUploadIndex >= items.length && !isUploading) {
|
|
1480
1546
|
if (completedRunRef.current === runRef.current) return;
|
|
1481
1547
|
completedRunRef.current = runRef.current;
|
|
@@ -1494,15 +1560,15 @@ function useTrackUpload({
|
|
|
1494
1560
|
}
|
|
1495
1561
|
|
|
1496
1562
|
// src/track-noun/TrackNounContext.tsx
|
|
1497
|
-
var
|
|
1563
|
+
var import_react14 = require("react");
|
|
1498
1564
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1499
|
-
var TrackNounContext = (0,
|
|
1565
|
+
var TrackNounContext = (0, import_react14.createContext)(void 0);
|
|
1500
1566
|
function TrackNounProvider({ singular, plural, children }) {
|
|
1501
|
-
const value = (0,
|
|
1567
|
+
const value = (0, import_react14.useMemo)(() => ({ singular, plural }), [singular, plural]);
|
|
1502
1568
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TrackNounContext.Provider, { value, children });
|
|
1503
1569
|
}
|
|
1504
1570
|
function useTrackNoun() {
|
|
1505
|
-
const context = (0,
|
|
1571
|
+
const context = (0, import_react14.useContext)(TrackNounContext);
|
|
1506
1572
|
if (context === void 0) {
|
|
1507
1573
|
throw new Error("useTrackNoun must be used within a TrackNounProvider");
|
|
1508
1574
|
}
|
|
@@ -1522,7 +1588,7 @@ var PlayStates = /* @__PURE__ */ ((PlayStates2) => {
|
|
|
1522
1588
|
})(PlayStates || {});
|
|
1523
1589
|
|
|
1524
1590
|
// src/player/PlayerContext.tsx
|
|
1525
|
-
var
|
|
1591
|
+
var import_react15 = require("react");
|
|
1526
1592
|
|
|
1527
1593
|
// src/player/PlaybackFailures.ts
|
|
1528
1594
|
var TTL_MS = 10 * 6e4;
|
|
@@ -1639,42 +1705,42 @@ function youtubeErrorMessage(code) {
|
|
|
1639
1705
|
if (code === 101 || code === 150) return "Embedding disabled by the video owner";
|
|
1640
1706
|
return `YouTube playback error (code ${code})`;
|
|
1641
1707
|
}
|
|
1642
|
-
var PlayerContext = (0,
|
|
1708
|
+
var PlayerContext = (0, import_react15.createContext)(void 0);
|
|
1643
1709
|
function PlayerProvider({ children, loadTrack }) {
|
|
1644
1710
|
const playback = usePlaybackContext();
|
|
1645
|
-
const failures = (0,
|
|
1646
|
-
const generation = (0,
|
|
1647
|
-
const loadedPlaybackKey = (0,
|
|
1648
|
-
const terminal = (0,
|
|
1649
|
-
const hasPlaybackFailure = (0,
|
|
1650
|
-
const [playerTrackObject, setPlayerTrackObject] = (0,
|
|
1651
|
-
const [playbackConfirmedTrackId, setPlaybackConfirmedTrackId] = (0,
|
|
1652
|
-
const [isPlaying, setIsPlaying] = (0,
|
|
1653
|
-
const [duration, setDuration] = (0,
|
|
1654
|
-
const [volume, setVolumeState] = (0,
|
|
1655
|
-
const [playState, setPlayState] = (0,
|
|
1656
|
-
const [isLoading, setIsLoading] = (0,
|
|
1657
|
-
const [onTrackEnd, setOnTrackEndState] = (0,
|
|
1658
|
-
const setOnTrackEnd = (0,
|
|
1711
|
+
const failures = (0, import_react15.useRef)(new PlaybackFailures());
|
|
1712
|
+
const generation = (0, import_react15.useRef)(0);
|
|
1713
|
+
const loadedPlaybackKey = (0, import_react15.useRef)(playback.key);
|
|
1714
|
+
const terminal = (0, import_react15.useRef)(false);
|
|
1715
|
+
const hasPlaybackFailure = (0, import_react15.useCallback)((videoId) => failures.current.has(videoId, playback.key), [playback.key]);
|
|
1716
|
+
const [playerTrackObject, setPlayerTrackObject] = (0, import_react15.useState)(null);
|
|
1717
|
+
const [playbackConfirmedTrackId, setPlaybackConfirmedTrackId] = (0, import_react15.useState)(null);
|
|
1718
|
+
const [isPlaying, setIsPlaying] = (0, import_react15.useState)(false);
|
|
1719
|
+
const [duration, setDuration] = (0, import_react15.useState)(0);
|
|
1720
|
+
const [volume, setVolumeState] = (0, import_react15.useState)(50);
|
|
1721
|
+
const [playState, setPlayState] = (0, import_react15.useState)("STOPPED" /* STOPPED */);
|
|
1722
|
+
const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
|
|
1723
|
+
const [onTrackEnd, setOnTrackEndState] = (0, import_react15.useState)(null);
|
|
1724
|
+
const setOnTrackEnd = (0, import_react15.useCallback)((callback) => {
|
|
1659
1725
|
setOnTrackEndState(() => callback);
|
|
1660
1726
|
}, []);
|
|
1661
|
-
const audioElementRef = (0,
|
|
1662
|
-
const youtubePlayerRef = (0,
|
|
1663
|
-
const videoContainerRef = (0,
|
|
1664
|
-
const currentTimeRef = (0,
|
|
1665
|
-
const currentTrackIdRef = (0,
|
|
1666
|
-
const onTrackEndRef = (0,
|
|
1667
|
-
(0,
|
|
1727
|
+
const audioElementRef = (0, import_react15.useRef)(null);
|
|
1728
|
+
const youtubePlayerRef = (0, import_react15.useRef)(null);
|
|
1729
|
+
const videoContainerRef = (0, import_react15.useRef)(null);
|
|
1730
|
+
const currentTimeRef = (0, import_react15.useRef)(0);
|
|
1731
|
+
const currentTrackIdRef = (0, import_react15.useRef)(null);
|
|
1732
|
+
const onTrackEndRef = (0, import_react15.useRef)(onTrackEnd);
|
|
1733
|
+
(0, import_react15.useEffect)(() => {
|
|
1668
1734
|
onTrackEndRef.current = onTrackEnd;
|
|
1669
1735
|
}, [onTrackEnd]);
|
|
1670
|
-
const setVolume = (0,
|
|
1736
|
+
const setVolume = (0, import_react15.useCallback)((nextVolume) => {
|
|
1671
1737
|
if (!Number.isFinite(nextVolume)) return;
|
|
1672
1738
|
setVolumeState(Math.max(0, Math.min(100, nextVolume)));
|
|
1673
1739
|
}, []);
|
|
1674
|
-
(0,
|
|
1740
|
+
(0, import_react15.useEffect)(() => {
|
|
1675
1741
|
if (playerTrackObject?.isReady) playerTrackObject.mediaController?.setVolume(volume);
|
|
1676
1742
|
}, [playerTrackObject?.isReady, playerTrackObject?.mediaController, volume]);
|
|
1677
|
-
const seekTo = (0,
|
|
1743
|
+
const seekTo = (0, import_react15.useCallback)(
|
|
1678
1744
|
(time) => {
|
|
1679
1745
|
const mediaController = playerTrackObject?.isReady ? playerTrackObject.mediaController : void 0;
|
|
1680
1746
|
if (!mediaController || !Number.isFinite(time)) return;
|
|
@@ -1684,11 +1750,11 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1684
1750
|
},
|
|
1685
1751
|
[duration, playerTrackObject?.isReady, playerTrackObject?.mediaController]
|
|
1686
1752
|
);
|
|
1687
|
-
(0,
|
|
1753
|
+
(0, import_react15.useEffect)(() => {
|
|
1688
1754
|
loadYoutubeIframeApi().catch(() => {
|
|
1689
1755
|
});
|
|
1690
1756
|
}, []);
|
|
1691
|
-
(0,
|
|
1757
|
+
(0, import_react15.useEffect)(() => {
|
|
1692
1758
|
const interval = setInterval(() => {
|
|
1693
1759
|
const player = youtubePlayerRef.current;
|
|
1694
1760
|
if (player) {
|
|
@@ -1698,7 +1764,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1698
1764
|
}, 250);
|
|
1699
1765
|
return () => clearInterval(interval);
|
|
1700
1766
|
}, []);
|
|
1701
|
-
const handleYoutubeStateChange = (0,
|
|
1767
|
+
const handleYoutubeStateChange = (0, import_react15.useCallback)((event) => {
|
|
1702
1768
|
if (event.data === window.YT.PlayerState.PLAYING) {
|
|
1703
1769
|
const trackId = currentTrackIdRef.current;
|
|
1704
1770
|
if (trackId) setPlaybackConfirmedTrackId(trackId);
|
|
@@ -1711,7 +1777,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1711
1777
|
if (trackId) onTrackEndRef.current?.({ trackId });
|
|
1712
1778
|
}
|
|
1713
1779
|
}, []);
|
|
1714
|
-
const loadAudioTrack = (0,
|
|
1780
|
+
const loadAudioTrack = (0, import_react15.useCallback)(
|
|
1715
1781
|
(track) => {
|
|
1716
1782
|
const audio = new Audio(track.streamUrl);
|
|
1717
1783
|
audio.volume = volume / 100;
|
|
@@ -1747,7 +1813,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1747
1813
|
},
|
|
1748
1814
|
[volume]
|
|
1749
1815
|
);
|
|
1750
|
-
const loadYoutubeTrack = (0,
|
|
1816
|
+
const loadYoutubeTrack = (0, import_react15.useCallback)(
|
|
1751
1817
|
async (track) => {
|
|
1752
1818
|
const request = generation.current;
|
|
1753
1819
|
youtubePlayerRef.current?.destroy();
|
|
@@ -1803,7 +1869,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1803
1869
|
},
|
|
1804
1870
|
[handleYoutubeStateChange, playback.key]
|
|
1805
1871
|
);
|
|
1806
|
-
const loadTrackForPlayer = (0,
|
|
1872
|
+
const loadTrackForPlayer = (0, import_react15.useCallback)(
|
|
1807
1873
|
(trackId) => {
|
|
1808
1874
|
const request = ++generation.current;
|
|
1809
1875
|
loadedPlaybackKey.current = playback.key;
|
|
@@ -1844,8 +1910,8 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1844
1910
|
},
|
|
1845
1911
|
[loadTrack, loadAudioTrack, loadYoutubeTrack, playback.key]
|
|
1846
1912
|
);
|
|
1847
|
-
const previousPlaybackKey = (0,
|
|
1848
|
-
(0,
|
|
1913
|
+
const previousPlaybackKey = (0, import_react15.useRef)(playback.key);
|
|
1914
|
+
(0, import_react15.useEffect)(() => {
|
|
1849
1915
|
if (previousPlaybackKey.current === playback.key) return;
|
|
1850
1916
|
previousPlaybackKey.current = playback.key;
|
|
1851
1917
|
failures.current.clear();
|
|
@@ -1853,13 +1919,13 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1853
1919
|
loadTrackForPlayer(currentTrackIdRef.current);
|
|
1854
1920
|
}
|
|
1855
1921
|
}, [playback.key, loadTrackForPlayer, playerTrackObject]);
|
|
1856
|
-
const [retryTrackId, setRetryTrackId] = (0,
|
|
1857
|
-
(0,
|
|
1922
|
+
const [retryTrackId, setRetryTrackId] = (0, import_react15.useState)(null);
|
|
1923
|
+
(0, import_react15.useEffect)(() => {
|
|
1858
1924
|
if (!retryTrackId) return;
|
|
1859
1925
|
setRetryTrackId(null);
|
|
1860
1926
|
loadTrackForPlayer(retryTrackId);
|
|
1861
1927
|
}, [retryTrackId, loadTrackForPlayer]);
|
|
1862
|
-
const retryPlayback = (0,
|
|
1928
|
+
const retryPlayback = (0, import_react15.useCallback)(async () => {
|
|
1863
1929
|
try {
|
|
1864
1930
|
await playback.refresh(true);
|
|
1865
1931
|
failures.current.clear();
|
|
@@ -1871,7 +1937,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1871
1937
|
});
|
|
1872
1938
|
}
|
|
1873
1939
|
}, [playback]);
|
|
1874
|
-
const handleNextTrack = (0,
|
|
1940
|
+
const handleNextTrack = (0, import_react15.useCallback)(
|
|
1875
1941
|
(trackList, currentTrack, onTrackChange) => {
|
|
1876
1942
|
if (!trackList || !currentTrack) return;
|
|
1877
1943
|
const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);
|
|
@@ -1884,7 +1950,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1884
1950
|
},
|
|
1885
1951
|
[loadTrackForPlayer, hasPlaybackFailure]
|
|
1886
1952
|
);
|
|
1887
|
-
const handlePreviousTrack = (0,
|
|
1953
|
+
const handlePreviousTrack = (0, import_react15.useCallback)(
|
|
1888
1954
|
(trackList, currentTrack, onTrackChange) => {
|
|
1889
1955
|
if (!trackList || !currentTrack) return;
|
|
1890
1956
|
const currentIndex = trackList.findIndex((track) => track.id === currentTrack.id);
|
|
@@ -1897,7 +1963,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1897
1963
|
},
|
|
1898
1964
|
[loadTrackForPlayer, hasPlaybackFailure]
|
|
1899
1965
|
);
|
|
1900
|
-
(0,
|
|
1966
|
+
(0, import_react15.useEffect)(() => {
|
|
1901
1967
|
return () => {
|
|
1902
1968
|
if (audioElementRef.current) {
|
|
1903
1969
|
audioElementRef.current.pause();
|
|
@@ -1909,7 +1975,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1909
1975
|
}
|
|
1910
1976
|
};
|
|
1911
1977
|
}, []);
|
|
1912
|
-
const handlePlayPauseAction = (0,
|
|
1978
|
+
const handlePlayPauseAction = (0, import_react15.useCallback)(() => {
|
|
1913
1979
|
if (playState === "LOADING" /* LOADING */) return;
|
|
1914
1980
|
if (!playerTrackObject?.isReady) return;
|
|
1915
1981
|
const mediaController = playerTrackObject.mediaController;
|
|
@@ -1925,7 +1991,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1925
1991
|
setIsPlaying(true);
|
|
1926
1992
|
}
|
|
1927
1993
|
}, [playerTrackObject?.isReady, playerTrackObject?.mediaController, playState]);
|
|
1928
|
-
const contextValue = (0,
|
|
1994
|
+
const contextValue = (0, import_react15.useMemo)(
|
|
1929
1995
|
() => ({
|
|
1930
1996
|
playerTrackObject,
|
|
1931
1997
|
hasPlaybackFailure,
|
|
@@ -1973,7 +2039,7 @@ function PlayerProvider({ children, loadTrack }) {
|
|
|
1973
2039
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PlayerContext.Provider, { value: contextValue, children });
|
|
1974
2040
|
}
|
|
1975
2041
|
function usePlayer() {
|
|
1976
|
-
const context = (0,
|
|
2042
|
+
const context = (0, import_react15.useContext)(PlayerContext);
|
|
1977
2043
|
if (context === void 0) {
|
|
1978
2044
|
throw new Error("usePlayer must be used within a PlayerProvider");
|
|
1979
2045
|
}
|
|
@@ -1985,8 +2051,8 @@ function PlayerVideoSurface({ className }) {
|
|
|
1985
2051
|
}
|
|
1986
2052
|
function useCurrentTime() {
|
|
1987
2053
|
const { currentTimeRef } = usePlayer();
|
|
1988
|
-
const [currentTime, setCurrentTime] = (0,
|
|
1989
|
-
(0,
|
|
2054
|
+
const [currentTime, setCurrentTime] = (0, import_react15.useState)(0);
|
|
2055
|
+
(0, import_react15.useEffect)(() => {
|
|
1990
2056
|
const interval = setInterval(() => {
|
|
1991
2057
|
setCurrentTime(currentTimeRef.current);
|
|
1992
2058
|
}, 100);
|
|
@@ -2189,7 +2255,7 @@ var ReferenceGenrePlaylistSchema = CriteriaPlaylistSimpleSchema.extend({
|
|
|
2189
2255
|
|
|
2190
2256
|
// src/genre-tree/useGenre.ts
|
|
2191
2257
|
var import_react_query5 = require("@tanstack/react-query");
|
|
2192
|
-
var
|
|
2258
|
+
var import_react16 = require("react");
|
|
2193
2259
|
|
|
2194
2260
|
// src/genre-tree/useGenrePlaylist.ts
|
|
2195
2261
|
var import_zod18 = require("zod");
|
|
@@ -2475,7 +2541,7 @@ function useListGenres(page = 1, pageSize = 50, scope, getBackendBaseUrl) {
|
|
|
2475
2541
|
}
|
|
2476
2542
|
function useFetchGenre(scope, getBackendBaseUrl) {
|
|
2477
2543
|
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2478
|
-
return (0,
|
|
2544
|
+
return (0, import_react16.useCallback)(
|
|
2479
2545
|
async (id) => {
|
|
2480
2546
|
const endpoint = scope === "reference" ? genreEndpoints.reference.detail(id) : genreEndpoints.me.detail(id);
|
|
2481
2547
|
const response = await fetch2(endpoint, true, scope === "me");
|
|
@@ -2514,7 +2580,7 @@ function useGenreByWikidataId(qid, scope, getBackendBaseUrl) {
|
|
|
2514
2580
|
var GENRE_OVERVIEW_STALE_TIME_MS = 6e4;
|
|
2515
2581
|
function useGenreOverviewQueryOptions(scope, getBackendBaseUrl, schema) {
|
|
2516
2582
|
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2517
|
-
return (0,
|
|
2583
|
+
return (0, import_react16.useCallback)(
|
|
2518
2584
|
(id) => {
|
|
2519
2585
|
const queryKeys = scope === "reference" ? genreQueryKeys.reference : genreQueryKeys.me;
|
|
2520
2586
|
const endpoints = scope === "reference" ? genreEndpoints.reference : genreEndpoints.me;
|
|
@@ -2534,7 +2600,7 @@ function useFetchGenreOverview(id, scope, getBackendBaseUrl, schema = CriteriaOv
|
|
|
2534
2600
|
function usePrefetchGenreOverview(scope, getBackendBaseUrl, schema = CriteriaOverviewSchema) {
|
|
2535
2601
|
const queryClient2 = (0, import_react_query5.useQueryClient)();
|
|
2536
2602
|
const queryOptions = useGenreOverviewQueryOptions(scope, getBackendBaseUrl, schema);
|
|
2537
|
-
return (0,
|
|
2603
|
+
return (0, import_react16.useCallback)((id) => queryClient2.prefetchQuery(queryOptions(id)), [queryClient2, queryOptions]);
|
|
2538
2604
|
}
|
|
2539
2605
|
function useRefreshGenreTree(scope) {
|
|
2540
2606
|
const queryClient2 = (0, import_react_query5.useQueryClient)();
|
|
@@ -2721,18 +2787,19 @@ var ArtistSearchResultsSchema = import_zod27.z.array(ArtistSearchResultSchema);
|
|
|
2721
2787
|
|
|
2722
2788
|
// src/genre-tree/useRemoteSearch.ts
|
|
2723
2789
|
var import_react_query6 = require("@tanstack/react-query");
|
|
2724
|
-
var
|
|
2790
|
+
var import_react17 = require("react");
|
|
2725
2791
|
var SEARCH_DEBOUNCE_MS = 250;
|
|
2726
2792
|
var SEARCH_QUERY_MIN_LENGTH = 2;
|
|
2727
|
-
function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "" }) {
|
|
2728
|
-
const { fetch:
|
|
2793
|
+
function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema, context, text, enabled: extraEnabled = true, scope = "", fetch: fetchOverride }) {
|
|
2794
|
+
const { fetch: plainFetch } = useFetchWrapper(getBackendBaseUrl);
|
|
2795
|
+
const fetch2 = fetchOverride ?? plainFetch;
|
|
2729
2796
|
const trimmed = text.trim();
|
|
2730
|
-
const [query, setQuery] = (0,
|
|
2731
|
-
(0,
|
|
2797
|
+
const [query, setQuery] = (0, import_react17.useState)("");
|
|
2798
|
+
(0, import_react17.useEffect)(() => {
|
|
2732
2799
|
const timer = setTimeout(() => setQuery(trimmed), SEARCH_DEBOUNCE_MS);
|
|
2733
2800
|
return () => clearTimeout(timer);
|
|
2734
2801
|
}, [trimmed]);
|
|
2735
|
-
const dataScope = (0,
|
|
2802
|
+
const dataScope = (0, import_react17.useRef)(null);
|
|
2736
2803
|
const enabled = query.length >= SEARCH_QUERY_MIN_LENGTH && extraEnabled;
|
|
2737
2804
|
const { data, isFetching, isError, isPlaceholderData } = useQueryWithParse({
|
|
2738
2805
|
queryKey: queryKey(query),
|
|
@@ -2742,7 +2809,7 @@ function useRemoteSearch(getBackendBaseUrl, { queryKey, endpoint, params, schema
|
|
|
2742
2809
|
enabled,
|
|
2743
2810
|
placeholderData: (previous) => dataScope.current === scope ? (0, import_react_query6.keepPreviousData)(previous) : void 0
|
|
2744
2811
|
});
|
|
2745
|
-
(0,
|
|
2812
|
+
(0, import_react17.useEffect)(() => {
|
|
2746
2813
|
if (data !== void 0 && !isPlaceholderData) dataScope.current = scope;
|
|
2747
2814
|
}, [data, isPlaceholderData, scope]);
|
|
2748
2815
|
const settled = enabled && !isFetching && query === trimmed;
|
|
@@ -2818,15 +2885,14 @@ function musicBrainzRecordingUrl(song) {
|
|
|
2818
2885
|
// src/genre-tree/useSong.ts
|
|
2819
2886
|
var isNotFound2 = (error) => error instanceof AppError && error.code === "BAC4040" /* BACKEND_NOT_FOUND */;
|
|
2820
2887
|
function useSong(uuid, getBackendBaseUrl) {
|
|
2821
|
-
const playback = usePlaybackContext();
|
|
2822
|
-
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2823
2888
|
const isUuid = uuid !== null && import_zod29.z.string().uuid().safeParse(uuid).success;
|
|
2824
|
-
const { data, isPending, error } =
|
|
2825
|
-
|
|
2889
|
+
const { data, isPending, error } = usePlaybackQuery({
|
|
2890
|
+
getBackendBaseUrl,
|
|
2891
|
+
queryKey: libraryQueryKeys.reference.songs.detail(uuid),
|
|
2826
2892
|
// A missing song is shown in the panel, not raised as an app-wide connectivity error.
|
|
2827
|
-
queryFn: ({ signal }) =>
|
|
2893
|
+
queryFn: (fetchBound, { signal }) => fetchBound(libraryEndpoints.reference.songs.detail(uuid), true, false, { signal }, void 0, false, true),
|
|
2828
2894
|
schema: SongDetailedSchema,
|
|
2829
|
-
enabled: isUuid
|
|
2895
|
+
enabled: isUuid,
|
|
2830
2896
|
retry: (failureCount, retryError) => !isNotFound2(retryError) && failureCount < 3,
|
|
2831
2897
|
context: "useSong"
|
|
2832
2898
|
});
|
|
@@ -2851,11 +2917,11 @@ var SongHistorySchema = import_zod30.z.array(SongHistoryEntrySchema);
|
|
|
2851
2917
|
|
|
2852
2918
|
// src/genre-tree/useSongHistory.ts
|
|
2853
2919
|
function useSongHistory(uuid, getBackendBaseUrl, enabled) {
|
|
2854
|
-
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
2855
2920
|
const active = enabled && uuid !== null;
|
|
2856
|
-
const { data, isPending, error } =
|
|
2921
|
+
const { data, isPending, error } = usePlaybackQuery({
|
|
2922
|
+
getBackendBaseUrl,
|
|
2857
2923
|
queryKey: libraryQueryKeys.reference.songs.history(uuid),
|
|
2858
|
-
queryFn: ({ signal }) =>
|
|
2924
|
+
queryFn: (fetchBound, { signal }) => fetchBound(libraryEndpoints.reference.songs.history(uuid), true, false, { signal }, void 0, false, true),
|
|
2859
2925
|
schema: SongHistorySchema,
|
|
2860
2926
|
enabled: active,
|
|
2861
2927
|
context: "useSongHistory"
|
|
@@ -2889,10 +2955,12 @@ function isSongSearchResultPlayable(result) {
|
|
|
2889
2955
|
var DEFAULT_RESULT_LIMIT = 8;
|
|
2890
2956
|
function useSongSearch(getBackendBaseUrl, text, options = {}) {
|
|
2891
2957
|
const playback = usePlaybackContext();
|
|
2958
|
+
const { fetchBound } = usePlaybackFetch(getBackendBaseUrl);
|
|
2892
2959
|
const { limit = DEFAULT_RESULT_LIMIT, genre, playable } = options;
|
|
2893
2960
|
const params = (q) => ({ q, limit, ...genre && { genre }, ...playable !== void 0 && { playable } });
|
|
2894
2961
|
const { results, isError, settled, pending } = useRemoteSearch(getBackendBaseUrl, {
|
|
2895
2962
|
queryKey: (q) => [...libraryQueryKeys.reference.songs.search(params(q)), ...playback.key ? [playback.key] : []],
|
|
2963
|
+
fetch: fetchBound,
|
|
2896
2964
|
endpoint: libraryEndpoints.reference.songs.search(),
|
|
2897
2965
|
params,
|
|
2898
2966
|
schema: SongSearchResultsSchema,
|
|
@@ -2944,7 +3012,7 @@ function useArtistGenreCounts(artistUuid, getBackendBaseUrl) {
|
|
|
2944
3012
|
}
|
|
2945
3013
|
|
|
2946
3014
|
// src/genre-tree/useGenreSearch.ts
|
|
2947
|
-
var
|
|
3015
|
+
var import_react19 = require("react");
|
|
2948
3016
|
|
|
2949
3017
|
// src/genre-tree/lib/search-text.ts
|
|
2950
3018
|
var foldSearchText = (text) => text.normalize("NFD").replace(/\p{M}+/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
@@ -3041,10 +3109,10 @@ function rankNameIndex(index, query, limit = Infinity) {
|
|
|
3041
3109
|
}
|
|
3042
3110
|
|
|
3043
3111
|
// src/genre-tree/useSearchQueryState.ts
|
|
3044
|
-
var
|
|
3112
|
+
var import_react18 = require("react");
|
|
3045
3113
|
function useSearchQueryState({ selectedName = null, onClear } = {}) {
|
|
3046
|
-
const [query, setQuery] = (0,
|
|
3047
|
-
const [prevSelectedName, setPrevSelectedName] = (0,
|
|
3114
|
+
const [query, setQuery] = (0, import_react18.useState)(selectedName ?? "");
|
|
3115
|
+
const [prevSelectedName, setPrevSelectedName] = (0, import_react18.useState)(selectedName);
|
|
3048
3116
|
if (selectedName !== prevSelectedName) {
|
|
3049
3117
|
setPrevSelectedName(selectedName);
|
|
3050
3118
|
setQuery(selectedName ?? "");
|
|
@@ -3072,12 +3140,12 @@ function useGenreSearch({
|
|
|
3072
3140
|
onClear
|
|
3073
3141
|
}) {
|
|
3074
3142
|
const { query, setQuery, isTyping, canClear, clear, notifyPick } = useSearchQueryState({ selectedName, onClear });
|
|
3075
|
-
const index = (0,
|
|
3143
|
+
const index = (0, import_react19.useMemo)(
|
|
3076
3144
|
() => createNameIndex(genrePlaylists, (playlist) => playlist.name, (playlist) => playlist.viewsCount ?? 0),
|
|
3077
3145
|
[genrePlaylists]
|
|
3078
3146
|
);
|
|
3079
|
-
const deferredQuery = (0,
|
|
3080
|
-
const results = (0,
|
|
3147
|
+
const deferredQuery = (0, import_react19.useDeferredValue)(query);
|
|
3148
|
+
const results = (0, import_react19.useMemo)(
|
|
3081
3149
|
() => isTyping ? rankNameIndex(index, deferredQuery) : [],
|
|
3082
3150
|
[index, deferredQuery, isTyping]
|
|
3083
3151
|
);
|
|
@@ -3155,10 +3223,10 @@ function useRegionGenreLexicon(getBackendBaseUrl, enabled) {
|
|
|
3155
3223
|
}
|
|
3156
3224
|
|
|
3157
3225
|
// src/genre-tree/useGenreTreeViewState.ts
|
|
3158
|
-
var
|
|
3226
|
+
var import_react21 = require("react");
|
|
3159
3227
|
|
|
3160
3228
|
// src/genre-tree/useVisibleGenrePlaylists.ts
|
|
3161
|
-
var
|
|
3229
|
+
var import_react20 = require("react");
|
|
3162
3230
|
|
|
3163
3231
|
// src/genre-tree/lib/prune-genre-playlists-for-artist.ts
|
|
3164
3232
|
var POP_ROOT_NAME = "Mainstream Pop";
|
|
@@ -3196,15 +3264,22 @@ var pruneGenrePlaylistsForArtist = (playlists, counts) => {
|
|
|
3196
3264
|
|
|
3197
3265
|
// src/genre-tree/useVisibleGenrePlaylists.ts
|
|
3198
3266
|
function useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid = null }) {
|
|
3199
|
-
const { data: tree, isPending: isTreePending, isFetching: isTreeFetching } = useListFullGenrePlaylists(scope, getBackendBaseUrl);
|
|
3267
|
+
const { data: tree, isPending: isTreePending, isFetching: isTreeFetching, isError: isTreeError, refetch } = useListFullGenrePlaylists(scope, getBackendBaseUrl);
|
|
3200
3268
|
const counts = useArtistGenreCounts(artistUuid, getBackendBaseUrl);
|
|
3201
3269
|
const artistCounts = artistUuid !== null ? counts.data : void 0;
|
|
3202
3270
|
const isCountsLoading = artistUuid !== null && (counts.isPending || counts.isPlaceholderData);
|
|
3203
|
-
const genrePlaylists = (0,
|
|
3271
|
+
const genrePlaylists = (0, import_react20.useMemo)(() => {
|
|
3204
3272
|
if (!tree) return [];
|
|
3205
3273
|
return artistCounts ? pruneGenrePlaylistsForArtist(tree, artistCounts) : tree;
|
|
3206
3274
|
}, [tree, artistCounts]);
|
|
3207
|
-
return {
|
|
3275
|
+
return {
|
|
3276
|
+
isLoading: isTreePending,
|
|
3277
|
+
// The tree failed with nothing cached to show; the host must say so rather than render an empty tree.
|
|
3278
|
+
isError: isTreeError && !tree,
|
|
3279
|
+
refetch,
|
|
3280
|
+
isFetching: isCountsLoading || !isTreePending && isTreeFetching,
|
|
3281
|
+
genrePlaylists
|
|
3282
|
+
};
|
|
3208
3283
|
}
|
|
3209
3284
|
|
|
3210
3285
|
// src/genre-tree/lib/genre-playlist-helpers.ts
|
|
@@ -3228,45 +3303,45 @@ function useGenreTreeViewState({
|
|
|
3228
3303
|
onSelectedGenreUuidChange,
|
|
3229
3304
|
criteriaOverviewSchema
|
|
3230
3305
|
}) {
|
|
3231
|
-
const [internalViewMode, setInternalViewMode] = (0,
|
|
3232
|
-
const [allowWheelRotation, setAllowWheelRotation] = (0,
|
|
3233
|
-
const [internalSelectedGenreUuid, setInternalSelectedGenreUuid] = (0,
|
|
3306
|
+
const [internalViewMode, setInternalViewMode] = (0, import_react21.useState)("pop-core");
|
|
3307
|
+
const [allowWheelRotation, setAllowWheelRotation] = (0, import_react21.useState)(false);
|
|
3308
|
+
const [internalSelectedGenreUuid, setInternalSelectedGenreUuid] = (0, import_react21.useState)(null);
|
|
3234
3309
|
const isSelectionControlled = controlledSelectedGenreUuid !== void 0;
|
|
3235
3310
|
const selectedGenreUuid = isSelectionControlled ? controlledSelectedGenreUuid : internalSelectedGenreUuid;
|
|
3236
|
-
const selectGenre = (0,
|
|
3311
|
+
const selectGenre = (0, import_react21.useCallback)(
|
|
3237
3312
|
(nodeId) => {
|
|
3238
3313
|
if (!isSelectionControlled) setInternalSelectedGenreUuid(nodeId);
|
|
3239
3314
|
onSelectedGenreUuidChange?.(nodeId);
|
|
3240
3315
|
},
|
|
3241
3316
|
[isSelectionControlled, onSelectedGenreUuidChange]
|
|
3242
3317
|
);
|
|
3243
|
-
const { isLoading, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
|
|
3244
|
-
const genrePlaylistByNodeId = (0,
|
|
3245
|
-
const selectedGenrePlaylist = (0,
|
|
3318
|
+
const { isLoading, isError, refetch, isFetching, genrePlaylists } = useVisibleGenrePlaylists({ scope, getBackendBaseUrl, artistUuid });
|
|
3319
|
+
const genrePlaylistByNodeId = (0, import_react21.useMemo)(() => new Map(genrePlaylists.map((gp) => [gp.uuid, gp])), [genrePlaylists]);
|
|
3320
|
+
const selectedGenrePlaylist = (0, import_react21.useMemo)(
|
|
3246
3321
|
() => genrePlaylists.find((gp) => gp.criteria?.uuid === selectedGenreUuid),
|
|
3247
3322
|
[genrePlaylists, selectedGenreUuid]
|
|
3248
3323
|
);
|
|
3249
3324
|
const selectedNodeId = selectedGenrePlaylist?.uuid ?? null;
|
|
3250
|
-
const selectNode = (0,
|
|
3325
|
+
const selectNode = (0, import_react21.useCallback)((node) => {
|
|
3251
3326
|
if (!node) selectGenre(null);
|
|
3252
3327
|
else {
|
|
3253
3328
|
const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
|
|
3254
3329
|
if (genreUuid) selectGenre(genreUuid);
|
|
3255
3330
|
}
|
|
3256
3331
|
}, [selectGenre, genrePlaylistByNodeId]);
|
|
3257
|
-
const clearSelection = (0,
|
|
3258
|
-
const selectGenrePlaylist = (0,
|
|
3332
|
+
const clearSelection = (0, import_react21.useCallback)(() => selectGenre(null), [selectGenre]);
|
|
3333
|
+
const selectGenrePlaylist = (0, import_react21.useCallback)((playlist) => {
|
|
3259
3334
|
if (playlist.criteria) selectGenre(playlist.criteria.uuid);
|
|
3260
3335
|
}, [selectGenre]);
|
|
3261
3336
|
const prefetchGenreOverview = usePrefetchGenreOverview(scope, getBackendBaseUrl, criteriaOverviewSchema);
|
|
3262
|
-
const hoverPrefetchTimerRef = (0,
|
|
3263
|
-
(0,
|
|
3337
|
+
const hoverPrefetchTimerRef = (0, import_react21.useRef)(null);
|
|
3338
|
+
(0, import_react21.useEffect)(
|
|
3264
3339
|
() => () => {
|
|
3265
3340
|
if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
|
|
3266
3341
|
},
|
|
3267
3342
|
[]
|
|
3268
3343
|
);
|
|
3269
|
-
const onNodeHover = (0,
|
|
3344
|
+
const onNodeHover = (0, import_react21.useCallback)(
|
|
3270
3345
|
(node) => {
|
|
3271
3346
|
if (hoverPrefetchTimerRef.current) clearTimeout(hoverPrefetchTimerRef.current);
|
|
3272
3347
|
const genreUuid = genrePlaylistByNodeId.get(node.id)?.criteria?.uuid;
|
|
@@ -3277,8 +3352,8 @@ function useGenreTreeViewState({
|
|
|
3277
3352
|
},
|
|
3278
3353
|
[genrePlaylistByNodeId, prefetchGenreOverview]
|
|
3279
3354
|
);
|
|
3280
|
-
const groupedGenrePlaylistsByRoot = (0,
|
|
3281
|
-
const canShowPopCore = (0,
|
|
3355
|
+
const groupedGenrePlaylistsByRoot = (0, import_react21.useMemo)(() => getGenrePlaylistsGroupedByRoot(genrePlaylists), [genrePlaylists]);
|
|
3356
|
+
const canShowPopCore = (0, import_react21.useMemo)(
|
|
3282
3357
|
() => hasMainstreamPopRoot(
|
|
3283
3358
|
genrePlaylists.map((genrePlaylist) => ({
|
|
3284
3359
|
parentId: genrePlaylist.parent?.uuid ?? null,
|
|
@@ -3287,14 +3362,14 @@ function useGenreTreeViewState({
|
|
|
3287
3362
|
),
|
|
3288
3363
|
[genrePlaylists]
|
|
3289
3364
|
);
|
|
3290
|
-
(0,
|
|
3291
|
-
if (!isLoading && needsPopCore(internalViewMode) && !canShowPopCore) {
|
|
3365
|
+
(0, import_react21.useEffect)(() => {
|
|
3366
|
+
if (!isLoading && !isError && needsPopCore(internalViewMode) && !canShowPopCore) {
|
|
3292
3367
|
setInternalViewMode("wheel");
|
|
3293
3368
|
}
|
|
3294
|
-
}, [isLoading, canShowPopCore, internalViewMode]);
|
|
3369
|
+
}, [isLoading, isError, canShowPopCore, internalViewMode]);
|
|
3295
3370
|
const selectedViewMode = controlledViewMode ?? internalViewMode;
|
|
3296
3371
|
const viewMode = needsPopCore(selectedViewMode) && !canShowPopCore ? "wheel" : selectedViewMode;
|
|
3297
|
-
const visibleGenrePlaylists = (0,
|
|
3372
|
+
const visibleGenrePlaylists = (0, import_react21.useMemo)(() => {
|
|
3298
3373
|
if (viewMode === "stacked") return genrePlaylists;
|
|
3299
3374
|
const unacceptedRootUuids = new Set(genrePlaylists.filter((gp) => gp.isUnacceptedRoot).map((gp) => gp.uuid));
|
|
3300
3375
|
const accepted = genrePlaylists.filter((gp) => !gp.isUnacceptedRoot && !unacceptedRootUuids.has(gp.root.uuid));
|
|
@@ -3302,6 +3377,8 @@ function useGenreTreeViewState({
|
|
|
3302
3377
|
}, [genrePlaylists, viewMode]);
|
|
3303
3378
|
return {
|
|
3304
3379
|
isLoading,
|
|
3380
|
+
isError,
|
|
3381
|
+
refetch: () => void refetch(),
|
|
3305
3382
|
isFetching,
|
|
3306
3383
|
genrePlaylists,
|
|
3307
3384
|
genrePlaylistByNodeId,
|
|
@@ -3325,7 +3402,7 @@ function useGenreTreeViewState({
|
|
|
3325
3402
|
}
|
|
3326
3403
|
|
|
3327
3404
|
// src/genre-tree/TrackListContext.tsx
|
|
3328
|
-
var
|
|
3405
|
+
var import_react23 = require("react");
|
|
3329
3406
|
|
|
3330
3407
|
// src/genre-tree/schemas/track-playlist-rel/without-playlist.ts
|
|
3331
3408
|
var import_zod35 = require("zod");
|
|
@@ -3457,21 +3534,21 @@ var TrackListOriginFromGenreCatalogue = class extends TrackListOrigin {
|
|
|
3457
3534
|
};
|
|
3458
3535
|
|
|
3459
3536
|
// src/genre-tree/TrackListSidebarVisibilityContext.tsx
|
|
3460
|
-
var
|
|
3537
|
+
var import_react22 = require("react");
|
|
3461
3538
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
3462
|
-
var TrackListSidebarVisibilityContext = (0,
|
|
3539
|
+
var TrackListSidebarVisibilityContext = (0, import_react22.createContext)(void 0);
|
|
3463
3540
|
function TrackListSidebarVisibilityProvider({ children }) {
|
|
3464
|
-
const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0,
|
|
3465
|
-
const toggleTrackListSidebar = (0,
|
|
3541
|
+
const [isTrackListSidebarVisible, setIsTrackListSidebarVisible] = (0, import_react22.useState)(false);
|
|
3542
|
+
const toggleTrackListSidebar = (0, import_react22.useCallback)(() => {
|
|
3466
3543
|
setIsTrackListSidebarVisible((prev) => !prev);
|
|
3467
3544
|
}, []);
|
|
3468
|
-
const showTrackListSidebar = (0,
|
|
3545
|
+
const showTrackListSidebar = (0, import_react22.useCallback)(() => {
|
|
3469
3546
|
setIsTrackListSidebarVisible(true);
|
|
3470
3547
|
}, []);
|
|
3471
|
-
const hideTrackListSidebar = (0,
|
|
3548
|
+
const hideTrackListSidebar = (0, import_react22.useCallback)(() => {
|
|
3472
3549
|
setIsTrackListSidebarVisible(false);
|
|
3473
3550
|
}, []);
|
|
3474
|
-
const value = (0,
|
|
3551
|
+
const value = (0, import_react22.useMemo)(
|
|
3475
3552
|
() => ({
|
|
3476
3553
|
isTrackListSidebarVisible,
|
|
3477
3554
|
toggleTrackListSidebar,
|
|
@@ -3483,7 +3560,7 @@ function TrackListSidebarVisibilityProvider({ children }) {
|
|
|
3483
3560
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TrackListSidebarVisibilityContext.Provider, { value, children });
|
|
3484
3561
|
}
|
|
3485
3562
|
function useTrackListSidebarVisibility() {
|
|
3486
|
-
const context = (0,
|
|
3563
|
+
const context = (0, import_react22.useContext)(TrackListSidebarVisibilityContext);
|
|
3487
3564
|
if (context === void 0) {
|
|
3488
3565
|
throw new Error("useTrackListSidebarVisibility must be used within a TrackListSidebarVisibilityProvider");
|
|
3489
3566
|
}
|
|
@@ -3499,59 +3576,58 @@ function isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure) {
|
|
|
3499
3576
|
return !runtimeUnplayableTrackIds.has(track.uuid) && (!isSong(track) || songUnplayableReason(track) === null && (!track.youtubeVideo || !hasPlaybackFailure(track.youtubeVideo.id)));
|
|
3500
3577
|
}
|
|
3501
3578
|
function useListTracks(scope, getBackendBaseUrl, schema, listEndpoint, listQueryKey, page = 1, pageSize = 50) {
|
|
3502
|
-
const playback = usePlaybackContext();
|
|
3503
|
-
const { fetch: fetch2 } = useFetchWrapper(getBackendBaseUrl);
|
|
3504
3579
|
const { session, sessionRestored } = useSession();
|
|
3505
|
-
return
|
|
3506
|
-
|
|
3507
|
-
|
|
3580
|
+
return usePlaybackQuery({
|
|
3581
|
+
getBackendBaseUrl,
|
|
3582
|
+
queryKey: listQueryKey(page),
|
|
3583
|
+
queryFn: async (fetchBound) => {
|
|
3508
3584
|
if (scope == null) return null;
|
|
3509
|
-
return
|
|
3585
|
+
return fetchBound(listEndpoint(page), true, scope === "me", {}, { page, pageSize });
|
|
3510
3586
|
},
|
|
3511
3587
|
schema: PaginatedResponseSchema(schema),
|
|
3512
3588
|
context: "useListTracks",
|
|
3513
|
-
enabled:
|
|
3589
|
+
enabled: scope != null && (scope === "reference" || sessionRestored && !!session?.accessToken)
|
|
3514
3590
|
});
|
|
3515
3591
|
}
|
|
3516
|
-
var TrackListContext = (0,
|
|
3592
|
+
var TrackListContext = (0, import_react23.createContext)(void 0);
|
|
3517
3593
|
function TrackListProvider({
|
|
3518
3594
|
children,
|
|
3519
3595
|
getBackendBaseUrl,
|
|
3520
3596
|
schema
|
|
3521
3597
|
}) {
|
|
3522
|
-
const [trackList, setTrackList] = (0,
|
|
3523
|
-
const [selectedTrack, setSelectedTrack] = (0,
|
|
3524
|
-
const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0,
|
|
3598
|
+
const [trackList, setTrackList] = (0, import_react23.useState)(null);
|
|
3599
|
+
const [selectedTrack, setSelectedTrack] = (0, import_react23.useState)(null);
|
|
3600
|
+
const [autoAdvanceScrollRequest, setAutoAdvanceScrollRequest] = (0, import_react23.useState)(null);
|
|
3525
3601
|
const { loadTrackForPlayer, setOnTrackEnd, hasPlaybackFailure, playerTrackObject } = usePlayer();
|
|
3526
|
-
const [failureClock, setFailureClock] = (0,
|
|
3527
|
-
(0,
|
|
3602
|
+
const [failureClock, setFailureClock] = (0, import_react23.useState)(0);
|
|
3603
|
+
(0, import_react23.useEffect)(() => {
|
|
3528
3604
|
const timer = setInterval(() => setFailureClock((tick) => tick + 1), 3e4);
|
|
3529
3605
|
return () => clearInterval(timer);
|
|
3530
3606
|
}, []);
|
|
3531
|
-
const runtimeUnplayableTrackIds = (0,
|
|
3607
|
+
const runtimeUnplayableTrackIds = (0, import_react23.useMemo)(() => new Set(
|
|
3532
3608
|
(trackList?.tracks ?? []).filter((track) => isSong(track) && track.youtubeVideo && hasPlaybackFailure(track.youtubeVideo.id)).map((track) => track.uuid)
|
|
3533
3609
|
), [trackList, hasPlaybackFailure, playerTrackObject, failureClock]);
|
|
3534
3610
|
const { showTrackListSidebar } = useTrackListSidebarVisibility();
|
|
3535
3611
|
const playback = usePlaybackContext();
|
|
3536
|
-
const {
|
|
3537
|
-
const pageSchema = (0,
|
|
3538
|
-
const latestPlayRequestRef = (0,
|
|
3539
|
-
const startingPlaybackRef = (0,
|
|
3540
|
-
const loadedContextRef = (0,
|
|
3541
|
-
const autoAdvanceScrollRequestIdRef = (0,
|
|
3542
|
-
const delayedTrackLoadRef = (0,
|
|
3543
|
-
const loadingOriginRef = (0,
|
|
3544
|
-
const pendingAdvanceRef = (0,
|
|
3545
|
-
const clearDelayedTrackLoad = (0,
|
|
3612
|
+
const { fetchBound, fetchLatest } = usePlaybackFetch(getBackendBaseUrl);
|
|
3613
|
+
const pageSchema = (0, import_react23.useMemo)(() => makeTrackPlaylistRelPageSchema(schema), [schema]);
|
|
3614
|
+
const latestPlayRequestRef = (0, import_react23.useRef)(0);
|
|
3615
|
+
const startingPlaybackRef = (0, import_react23.useRef)(false);
|
|
3616
|
+
const loadedContextRef = (0, import_react23.useRef)(playback.key);
|
|
3617
|
+
const autoAdvanceScrollRequestIdRef = (0, import_react23.useRef)(0);
|
|
3618
|
+
const delayedTrackLoadRef = (0, import_react23.useRef)(null);
|
|
3619
|
+
const loadingOriginRef = (0, import_react23.useRef)(null);
|
|
3620
|
+
const pendingAdvanceRef = (0, import_react23.useRef)(null);
|
|
3621
|
+
const clearDelayedTrackLoad = (0, import_react23.useCallback)(() => {
|
|
3546
3622
|
if (delayedTrackLoadRef.current !== null) {
|
|
3547
3623
|
clearTimeout(delayedTrackLoadRef.current);
|
|
3548
3624
|
delayedTrackLoadRef.current = null;
|
|
3549
3625
|
}
|
|
3550
3626
|
}, []);
|
|
3551
|
-
const requestAutoAdvanceScroll = (0,
|
|
3627
|
+
const requestAutoAdvanceScroll = (0, import_react23.useCallback)((trackUuid) => {
|
|
3552
3628
|
setAutoAdvanceScrollRequest({ id: ++autoAdvanceScrollRequestIdRef.current, trackUuid });
|
|
3553
3629
|
}, []);
|
|
3554
|
-
const loadTrackAfterSkipDelay = (0,
|
|
3630
|
+
const loadTrackAfterSkipDelay = (0, import_react23.useCallback)(
|
|
3555
3631
|
(trackUuid) => {
|
|
3556
3632
|
clearDelayedTrackLoad();
|
|
3557
3633
|
delayedTrackLoadRef.current = setTimeout(() => {
|
|
@@ -3561,12 +3637,12 @@ function TrackListProvider({
|
|
|
3561
3637
|
},
|
|
3562
3638
|
[clearDelayedTrackLoad, loadTrackForPlayer]
|
|
3563
3639
|
);
|
|
3564
|
-
const fetchTracksPage = (0,
|
|
3640
|
+
const fetchTracksPage = (0, import_react23.useCallback)(
|
|
3565
3641
|
async (uuid, scope, page, from, selection, artistUuid) => {
|
|
3566
3642
|
const endpoint = genrePlaylistEndpoints[scope].tracks(uuid);
|
|
3567
3643
|
if (scope === "me" && (selection || artistUuid)) throw new Error("Genre selections require reference scope");
|
|
3568
3644
|
const params = { page, pageSize: TRACKS_PAGE_SIZE, ...from && { from }, ...genreMusicQueryParams(selection), ...artistUuid && { artist: artistUuid } };
|
|
3569
|
-
const response = await
|
|
3645
|
+
const response = await (page === 1 ? fetchLatest : fetchBound)(endpoint, true, scope === "me", {}, params, false, !!from);
|
|
3570
3646
|
const parsed = parseWithLog(pageSchema, response, "fetchGenrePlaylistTracksPage");
|
|
3571
3647
|
return {
|
|
3572
3648
|
tracks: parsed.results.map((rel) => rel.track),
|
|
@@ -3574,10 +3650,10 @@ function TrackListProvider({
|
|
|
3574
3650
|
nextPage: parsed.next ? parsed.page + 1 : null
|
|
3575
3651
|
};
|
|
3576
3652
|
},
|
|
3577
|
-
[
|
|
3653
|
+
[fetchBound, fetchLatest, pageSchema]
|
|
3578
3654
|
);
|
|
3579
|
-
const cataloguePageSchema = (0,
|
|
3580
|
-
const fetchCatalogueTracksPage = (0,
|
|
3655
|
+
const cataloguePageSchema = (0, import_react23.useMemo)(() => PaginatedResponseSchema(schema), [schema]);
|
|
3656
|
+
const fetchCatalogueTracksPage = (0, import_react23.useCallback)(
|
|
3581
3657
|
async (origin, page) => {
|
|
3582
3658
|
const params = {
|
|
3583
3659
|
...origin instanceof TrackListOriginFromArtist && { artist: origin.uuid },
|
|
@@ -3589,7 +3665,7 @@ function TrackListProvider({
|
|
|
3589
3665
|
...origin.genreUuid && { genre: origin.genreUuid },
|
|
3590
3666
|
...genreMusicQueryParams(origin.selection)
|
|
3591
3667
|
};
|
|
3592
|
-
const response = await
|
|
3668
|
+
const response = await (page === 1 ? fetchLatest : fetchBound)(
|
|
3593
3669
|
libraryEndpoints.reference.songs.list(),
|
|
3594
3670
|
true,
|
|
3595
3671
|
false,
|
|
@@ -3597,15 +3673,14 @@ function TrackListProvider({
|
|
|
3597
3673
|
params,
|
|
3598
3674
|
false,
|
|
3599
3675
|
// A start song that isn't playable 404s; surface it as a rejection, not the global error.
|
|
3600
|
-
page === 1 && !!origin.from
|
|
3601
|
-
page === 1
|
|
3676
|
+
page === 1 && !!origin.from
|
|
3602
3677
|
);
|
|
3603
3678
|
const parsed = parseWithLog(cataloguePageSchema, response, "fetchCatalogueTracksPage");
|
|
3604
3679
|
return { tracks: parsed.results, total: parsed.overallTotal, nextPage: parsed.next ? parsed.page + 1 : null };
|
|
3605
3680
|
},
|
|
3606
|
-
[
|
|
3681
|
+
[fetchBound, fetchLatest, cataloguePageSchema]
|
|
3607
3682
|
);
|
|
3608
|
-
const advanceAfterTrackEnd = (0,
|
|
3683
|
+
const advanceAfterTrackEnd = (0, import_react23.useCallback)(
|
|
3609
3684
|
(event) => {
|
|
3610
3685
|
const completedTrackId = event?.trackId ?? selectedTrack?.uuid;
|
|
3611
3686
|
if (!completedTrackId || !trackList) return;
|
|
@@ -3637,11 +3712,11 @@ function TrackListProvider({
|
|
|
3637
3712
|
selectedTrack
|
|
3638
3713
|
]
|
|
3639
3714
|
);
|
|
3640
|
-
(0,
|
|
3715
|
+
(0, import_react23.useEffect)(() => {
|
|
3641
3716
|
setOnTrackEnd(trackList && selectedTrack ? advanceAfterTrackEnd : null);
|
|
3642
3717
|
return () => setOnTrackEnd(null);
|
|
3643
3718
|
}, [advanceAfterTrackEnd, trackList, selectedTrack, setOnTrackEnd]);
|
|
3644
|
-
const toTrackAtPosition = (0,
|
|
3719
|
+
const toTrackAtPosition = (0, import_react23.useCallback)(
|
|
3645
3720
|
(position) => {
|
|
3646
3721
|
if (trackList && position >= 0 && position < trackList.tracks.length) {
|
|
3647
3722
|
clearDelayedTrackLoad();
|
|
@@ -3651,7 +3726,7 @@ function TrackListProvider({
|
|
|
3651
3726
|
},
|
|
3652
3727
|
[clearDelayedTrackLoad, trackList]
|
|
3653
3728
|
);
|
|
3654
|
-
const playNewTrackListFromTrackUuid = (0,
|
|
3729
|
+
const playNewTrackListFromTrackUuid = (0, import_react23.useCallback)(
|
|
3655
3730
|
(track, scope) => {
|
|
3656
3731
|
latestPlayRequestRef.current++;
|
|
3657
3732
|
startingPlaybackRef.current = false;
|
|
@@ -3667,7 +3742,7 @@ function TrackListProvider({
|
|
|
3667
3742
|
},
|
|
3668
3743
|
[clearDelayedTrackLoad, showTrackListSidebar, loadTrackForPlayer]
|
|
3669
3744
|
);
|
|
3670
|
-
const playNewTrackListFromGenrePlaylist = (0,
|
|
3745
|
+
const playNewTrackListFromGenrePlaylist = (0, import_react23.useCallback)(
|
|
3671
3746
|
async (genrePlaylist, scope, options) => {
|
|
3672
3747
|
clearDelayedTrackLoad();
|
|
3673
3748
|
const request = ++latestPlayRequestRef.current;
|
|
@@ -3701,7 +3776,7 @@ function TrackListProvider({
|
|
|
3701
3776
|
},
|
|
3702
3777
|
[clearDelayedTrackLoad, fetchTracksPage, showTrackListSidebar, loadTrackForPlayer]
|
|
3703
3778
|
);
|
|
3704
|
-
const playCatalogue = (0,
|
|
3779
|
+
const playCatalogue = (0, import_react23.useCallback)(
|
|
3705
3780
|
async (origin) => {
|
|
3706
3781
|
clearDelayedTrackLoad();
|
|
3707
3782
|
const request = ++latestPlayRequestRef.current;
|
|
@@ -3734,7 +3809,7 @@ function TrackListProvider({
|
|
|
3734
3809
|
},
|
|
3735
3810
|
[clearDelayedTrackLoad, fetchCatalogueTracksPage, showTrackListSidebar, loadTrackForPlayer]
|
|
3736
3811
|
);
|
|
3737
|
-
const playNewTrackListFromArtist = (0,
|
|
3812
|
+
const playNewTrackListFromArtist = (0, import_react23.useCallback)(
|
|
3738
3813
|
async (artist, scope, options) => {
|
|
3739
3814
|
if (scope !== "reference") throw new Error("Artist track lists only support the reference scope");
|
|
3740
3815
|
if (options.selection && !options.genreUuid) throw new Error("A genre selection requires a genre");
|
|
@@ -3742,15 +3817,15 @@ function TrackListProvider({
|
|
|
3742
3817
|
},
|
|
3743
3818
|
[playCatalogue]
|
|
3744
3819
|
);
|
|
3745
|
-
const playNewTrackListFromGenreCatalogue = (0,
|
|
3820
|
+
const playNewTrackListFromGenreCatalogue = (0, import_react23.useCallback)(
|
|
3746
3821
|
async (genre, scope, options) => {
|
|
3747
3822
|
if (scope !== "reference") throw new Error("Genre catalogues only support the reference scope");
|
|
3748
3823
|
return playCatalogue(new TrackListOriginFromGenreCatalogue(genre, scope, options?.startSongUuid, options?.selection));
|
|
3749
3824
|
},
|
|
3750
3825
|
[playCatalogue]
|
|
3751
3826
|
);
|
|
3752
|
-
const contextKeyRef = (0,
|
|
3753
|
-
(0,
|
|
3827
|
+
const contextKeyRef = (0, import_react23.useRef)(playback.key);
|
|
3828
|
+
(0, import_react23.useEffect)(() => {
|
|
3754
3829
|
if (contextKeyRef.current === playback.key) return;
|
|
3755
3830
|
contextKeyRef.current = playback.key;
|
|
3756
3831
|
if (loadedContextRef.current === playback.key) return;
|
|
@@ -3794,15 +3869,15 @@ function TrackListProvider({
|
|
|
3794
3869
|
} else if (origin instanceof TrackListOriginFromTrack && selected) {
|
|
3795
3870
|
const request = latestPlayRequestRef.current;
|
|
3796
3871
|
void (async () => {
|
|
3797
|
-
const track = isSong(selected) && origin.scope === "reference" ? parseWithLog(schema, await
|
|
3872
|
+
const track = isSong(selected) && origin.scope === "reference" ? parseWithLog(schema, await fetchBound(libraryEndpoints.reference.songs.detail(selected.uuid), true, false), "refreshSelectedTrack") : selected;
|
|
3798
3873
|
if (request !== latestPlayRequestRef.current) return;
|
|
3799
3874
|
setTrackList(new TrackListFromTrack([track], new TrackListOriginFromTrack(track, origin.scope)));
|
|
3800
3875
|
setSelectedTrack(track);
|
|
3801
3876
|
})().catch(() => {
|
|
3802
3877
|
});
|
|
3803
3878
|
}
|
|
3804
|
-
}, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema,
|
|
3805
|
-
const updateTrack = (0,
|
|
3879
|
+
}, [playback.key, trackList, selectedTrack, clearDelayedTrackLoad, playNewTrackListFromGenrePlaylist, playNewTrackListFromArtist, playNewTrackListFromGenreCatalogue, schema, fetchBound]);
|
|
3880
|
+
const updateTrack = (0, import_react23.useCallback)((track) => {
|
|
3806
3881
|
setTrackList((prev) => {
|
|
3807
3882
|
if (!prev || !prev.tracks.some((listed) => listed.uuid === track.uuid)) return prev;
|
|
3808
3883
|
const tracks = prev.tracks.map((listed) => listed.uuid === track.uuid ? track : listed);
|
|
@@ -3810,7 +3885,7 @@ function TrackListProvider({
|
|
|
3810
3885
|
});
|
|
3811
3886
|
setSelectedTrack((prev) => prev?.uuid === track.uuid ? track : prev);
|
|
3812
3887
|
}, []);
|
|
3813
|
-
const loadMore = (0,
|
|
3888
|
+
const loadMore = (0, import_react23.useCallback)(async () => {
|
|
3814
3889
|
if (!trackList || trackList.nextPage === null) return;
|
|
3815
3890
|
const origin = trackList.origin;
|
|
3816
3891
|
if (!(origin instanceof TrackListOriginFromCriteriaPlaylist || origin instanceof TrackListOriginFromArtist || origin instanceof TrackListOriginFromGenreCatalogue)) return;
|
|
@@ -3834,7 +3909,7 @@ function TrackListProvider({
|
|
|
3834
3909
|
const previousTrack = trackList && selectedTrackIndex > 0 ? trackList.tracks.slice(0, selectedTrackIndex).reverse().find((track) => isTrackPlayable(track, runtimeUnplayableTrackIds, hasPlaybackFailure)) ?? null : null;
|
|
3835
3910
|
const hasNextTrack = nextTrack !== null || selectedTrackIndex >= 0 && trackList?.nextPage != null;
|
|
3836
3911
|
const hasPreviousTrack = previousTrack !== null;
|
|
3837
|
-
const playNextTrack = (0,
|
|
3912
|
+
const playNextTrack = (0, import_react23.useCallback)(() => {
|
|
3838
3913
|
if (!trackList || !selectedTrack || selectedTrackIndex < 0) return;
|
|
3839
3914
|
clearDelayedTrackLoad();
|
|
3840
3915
|
if (nextTrack) {
|
|
@@ -3851,7 +3926,7 @@ function TrackListProvider({
|
|
|
3851
3926
|
console.error("Failed to load more tracks:", error);
|
|
3852
3927
|
});
|
|
3853
3928
|
}, [clearDelayedTrackLoad, trackList, loadMore, loadTrackForPlayer, nextTrack, selectedTrack, selectedTrackIndex]);
|
|
3854
|
-
const playPreviousTrack = (0,
|
|
3929
|
+
const playPreviousTrack = (0, import_react23.useCallback)(() => {
|
|
3855
3930
|
if (!previousTrack) return;
|
|
3856
3931
|
clearDelayedTrackLoad();
|
|
3857
3932
|
pendingAdvanceRef.current = null;
|
|
@@ -3859,7 +3934,7 @@ function TrackListProvider({
|
|
|
3859
3934
|
setSelectedTrack(previousTrack);
|
|
3860
3935
|
loadTrackForPlayer(previousTrack.uuid);
|
|
3861
3936
|
}, [clearDelayedTrackLoad, loadTrackForPlayer, previousTrack, requestAutoAdvanceScroll]);
|
|
3862
|
-
(0,
|
|
3937
|
+
(0, import_react23.useEffect)(() => {
|
|
3863
3938
|
const pending = pendingAdvanceRef.current;
|
|
3864
3939
|
if (!pending) return;
|
|
3865
3940
|
if (!trackList || trackList.origin !== pending.origin || selectedTrack?.uuid !== pending.trackId) {
|
|
@@ -3893,15 +3968,15 @@ function TrackListProvider({
|
|
|
3893
3968
|
hasPlaybackFailure,
|
|
3894
3969
|
selectedTrack
|
|
3895
3970
|
]);
|
|
3896
|
-
(0,
|
|
3897
|
-
(0,
|
|
3971
|
+
(0, import_react23.useEffect)(() => clearDelayedTrackLoad, [clearDelayedTrackLoad]);
|
|
3972
|
+
(0, import_react23.useEffect)(() => {
|
|
3898
3973
|
if (!trackList || trackList.nextPage === null || !selectedTrack) return;
|
|
3899
3974
|
const index = trackList.tracks.findIndex((track) => track.uuid === selectedTrack.uuid);
|
|
3900
3975
|
if (index !== -1 && trackList.tracks.length - index <= AUTO_LOAD_REMAINING_TRACKS) {
|
|
3901
3976
|
loadMore().catch((error) => console.error("Failed to load more tracks:", error));
|
|
3902
3977
|
}
|
|
3903
3978
|
}, [trackList, selectedTrack, loadMore]);
|
|
3904
|
-
const value = (0,
|
|
3979
|
+
const value = (0, import_react23.useMemo)(
|
|
3905
3980
|
() => ({
|
|
3906
3981
|
trackList,
|
|
3907
3982
|
selectedTrack,
|
|
@@ -3943,7 +4018,7 @@ function TrackListProvider({
|
|
|
3943
4018
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TrackListContext.Provider, { value, children });
|
|
3944
4019
|
}
|
|
3945
4020
|
function useTrackList() {
|
|
3946
|
-
const context = (0,
|
|
4021
|
+
const context = (0, import_react23.useContext)(TrackListContext);
|
|
3947
4022
|
if (!context) {
|
|
3948
4023
|
throw new Error("useTrackList must be used within a TrackListProvider");
|
|
3949
4024
|
}
|
|
@@ -3951,14 +4026,14 @@ function useTrackList() {
|
|
|
3951
4026
|
}
|
|
3952
4027
|
|
|
3953
4028
|
// src/genre-tree/ArtistNames.tsx
|
|
3954
|
-
var
|
|
4029
|
+
var import_react24 = require("react");
|
|
3955
4030
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
3956
4031
|
function ArtistNames({
|
|
3957
4032
|
artists,
|
|
3958
4033
|
renderArtistLink
|
|
3959
4034
|
}) {
|
|
3960
4035
|
if (!renderArtistLink) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist) => artist.name).join(", ") });
|
|
3961
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
4036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: artists.map((artist, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_react24.Fragment, { children: [
|
|
3962
4037
|
index > 0 && ", ",
|
|
3963
4038
|
renderArtistLink(artist)
|
|
3964
4039
|
] }, artist.uuid)) });
|
|
@@ -4221,6 +4296,8 @@ function editGenreSongPages(data, edit) {
|
|
|
4221
4296
|
useListTracks,
|
|
4222
4297
|
useLogout,
|
|
4223
4298
|
usePlaybackContext,
|
|
4299
|
+
usePlaybackFetch,
|
|
4300
|
+
usePlaybackQuery,
|
|
4224
4301
|
usePlayer,
|
|
4225
4302
|
usePopup,
|
|
4226
4303
|
usePrefetchGenreOverview,
|