mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
chore: run prettier format
This commit is contained in:
parent
b6c7c9e16d
commit
f56548e432
12 changed files with 95 additions and 95 deletions
|
|
@ -17,9 +17,8 @@ export const RecentListens: React.FC = () => {
|
|||
|
||||
const options = useMemo(() => ({ page, limit: LISTENS_PER_PAGE }), [page]);
|
||||
|
||||
const { recentListens, paginationMeta, isLoading, reload } = useRecentListens(
|
||||
options
|
||||
);
|
||||
const { recentListens, paginationMeta, isLoading, reload } =
|
||||
useRecentListens(options);
|
||||
|
||||
useEffect(() => {
|
||||
if (paginationMeta && totalPages !== paginationMeta.totalPages) {
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ import { ReportTimeOptions } from "./ReportTimeOptions";
|
|||
export const ReportListens: React.FC = () => {
|
||||
const { user } = useAuth();
|
||||
|
||||
const [timeFrame, setTimeFrame] = useState<"day" | "week" | "month" | "year">(
|
||||
"day"
|
||||
);
|
||||
const [timeFrame, setTimeFrame] =
|
||||
useState<"day" | "week" | "month" | "year">("day");
|
||||
|
||||
const [timeOptions, setTimeOptions] = useState<TimeOptions>({
|
||||
timePreset: TimePreset.LAST_7_DAYS,
|
||||
|
|
@ -32,10 +31,10 @@ export const ReportListens: React.FC = () => {
|
|||
customTimeEnd: new Date(),
|
||||
});
|
||||
|
||||
const reportOptions = useMemo(() => ({ timeFrame, time: timeOptions }), [
|
||||
timeFrame,
|
||||
timeOptions,
|
||||
]);
|
||||
const reportOptions = useMemo(
|
||||
() => ({ timeFrame, time: timeOptions }),
|
||||
[timeFrame, timeOptions]
|
||||
);
|
||||
|
||||
const { report, isLoading } = useListensReport(reportOptions);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ interface ApiClientContext {
|
|||
}
|
||||
|
||||
const apiClientContext = createContext<ApiClientContext>(
|
||||
(undefined as any) as ApiClientContext
|
||||
undefined as any as ApiClientContext
|
||||
);
|
||||
|
||||
export const ProvideApiClient: React.FC = ({ children }) => {
|
||||
|
|
|
|||
|
|
@ -20,16 +20,18 @@ Object.freeze(INITIAL_EMPTY_ARRAY);
|
|||
export const useRecentListens = (options: PaginationOptions) => {
|
||||
const { client } = useApiClient();
|
||||
|
||||
const fetchData = useMemo(() => () => getRecentListens(options, client), [
|
||||
options,
|
||||
client,
|
||||
]);
|
||||
|
||||
const { value, pending: isLoading, error, reload } = useAsync(
|
||||
fetchData,
|
||||
undefined
|
||||
const fetchData = useMemo(
|
||||
() => () => getRecentListens(options, client),
|
||||
[options, client]
|
||||
);
|
||||
|
||||
const {
|
||||
value,
|
||||
pending: isLoading,
|
||||
error,
|
||||
reload,
|
||||
} = useAsync(fetchData, undefined);
|
||||
|
||||
const recentListens = value ? value.items : [];
|
||||
const paginationMeta = value ? value.meta : undefined;
|
||||
|
||||
|
|
@ -39,63 +41,67 @@ export const useRecentListens = (options: PaginationOptions) => {
|
|||
export const useListensReport = (options: ListenReportOptions) => {
|
||||
const { client } = useApiClient();
|
||||
|
||||
const fetchData = useMemo(() => () => getListensReport(options, client), [
|
||||
options,
|
||||
client,
|
||||
]);
|
||||
|
||||
const { value: report, pending: isLoading, error } = useAsync(
|
||||
fetchData,
|
||||
INITIAL_EMPTY_ARRAY
|
||||
const fetchData = useMemo(
|
||||
() => () => getListensReport(options, client),
|
||||
[options, client]
|
||||
);
|
||||
|
||||
const {
|
||||
value: report,
|
||||
pending: isLoading,
|
||||
error,
|
||||
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
|
||||
|
||||
return { report, isLoading, error };
|
||||
};
|
||||
|
||||
export const useTopArtists = (options: TopArtistsOptions) => {
|
||||
const { client } = useApiClient();
|
||||
|
||||
const fetchData = useMemo(() => () => getTopArtists(options, client), [
|
||||
options,
|
||||
client,
|
||||
]);
|
||||
|
||||
const { value: topArtists, pending: isLoading, error } = useAsync(
|
||||
fetchData,
|
||||
INITIAL_EMPTY_ARRAY
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopArtists(options, client),
|
||||
[options, client]
|
||||
);
|
||||
|
||||
const {
|
||||
value: topArtists,
|
||||
pending: isLoading,
|
||||
error,
|
||||
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
|
||||
|
||||
return { topArtists, isLoading, error };
|
||||
};
|
||||
|
||||
export const useTopAlbums = (options: TopAlbumsOptions) => {
|
||||
const { client } = useApiClient();
|
||||
|
||||
const fetchData = useMemo(() => () => getTopAlbums(options, client), [
|
||||
options,
|
||||
client,
|
||||
]);
|
||||
|
||||
const { value: topAlbums, pending: isLoading, error } = useAsync(
|
||||
fetchData,
|
||||
INITIAL_EMPTY_ARRAY
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopAlbums(options, client),
|
||||
[options, client]
|
||||
);
|
||||
|
||||
const {
|
||||
value: topAlbums,
|
||||
pending: isLoading,
|
||||
error,
|
||||
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
|
||||
|
||||
return { topAlbums, isLoading, error };
|
||||
};
|
||||
|
||||
export const useTopTracks = (options: TopTracksOptions) => {
|
||||
const { client } = useApiClient();
|
||||
|
||||
const fetchData = useMemo(() => () => getTopTracks(options, client), [
|
||||
options,
|
||||
client,
|
||||
]);
|
||||
|
||||
const { value: topTracks, pending: isLoading, error } = useAsync(
|
||||
fetchData,
|
||||
INITIAL_EMPTY_ARRAY
|
||||
const fetchData = useMemo(
|
||||
() => () => getTopTracks(options, client),
|
||||
[options, client]
|
||||
);
|
||||
|
||||
const {
|
||||
value: topTracks,
|
||||
pending: isLoading,
|
||||
error,
|
||||
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
|
||||
|
||||
return { topTracks, isLoading, error };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ interface AuthContext {
|
|||
loginWithSpotifyProps: () => { href: string };
|
||||
}
|
||||
|
||||
const authContext = createContext<AuthContext>(
|
||||
(undefined as any) as AuthContext
|
||||
);
|
||||
const authContext = createContext<AuthContext>(undefined as any as AuthContext);
|
||||
|
||||
export const ProvideAuth: React.FC = ({ children }) => {
|
||||
const auth = useProvideAuth();
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === "localhost" ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
window.location.hostname === "[::1]" ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
|
|
@ -26,12 +26,9 @@ type Config = {
|
|||
};
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL,
|
||||
window.location.href
|
||||
);
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
|
|
@ -39,7 +36,7 @@ export function register(config?: Config) {
|
|||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
window.addEventListener("load", () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
|
|
@ -50,8 +47,8 @@ export function register(config?: Config) {
|
|||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
"This web app is being served cache-first by a service " +
|
||||
"worker. To learn more, visit https://bit.ly/CRA-PWA"
|
||||
);
|
||||
});
|
||||
} else {
|
||||
|
|
@ -65,21 +62,21 @@ export function register(config?: Config) {
|
|||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
.then((registration) => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (installingWorker.state === "installed") {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
"New content is available and will be used when all " +
|
||||
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
|
|
@ -90,7 +87,7 @@ function registerValidSW(swUrl: string, config?: Config) {
|
|||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
console.log("Content is cached for offline use.");
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
|
|
@ -101,25 +98,25 @@ function registerValidSW(swUrl: string, config?: Config) {
|
|||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
.catch((error) => {
|
||||
console.error("Error during service worker registration:", error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' }
|
||||
headers: { "Service-Worker": "script" },
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
(contentType != null && contentType.indexOf("javascript") === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
|
|
@ -131,18 +128,18 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
|
|||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
"No internet connection found. App is running in offline mode."
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
.then((registration) => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue