From f56548e432e78e92f12cf42895dda66011a3e569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Tue, 25 May 2021 16:01:55 +0200 Subject: [PATCH] chore: run prettier format --- frontend/src/components/RecentListens.tsx | 5 +- frontend/src/components/ReportListens.tsx | 13 ++- frontend/src/hooks/use-api-client.tsx | 2 +- frontend/src/hooks/use-api.tsx | 86 ++++++++++--------- frontend/src/hooks/use-auth.tsx | 4 +- frontend/src/serviceWorker.ts | 49 +++++------ src/auth/auth.service.ts | 4 +- .../migrations/04-CreateAuthSessionsTable.ts | 3 +- src/reports/reports.controller.spec.ts | 8 +- src/reports/reports.service.spec.ts | 8 +- src/reports/reports.service.ts | 5 +- src/sources/spotify/spotify.service.ts | 3 +- 12 files changed, 95 insertions(+), 95 deletions(-) diff --git a/frontend/src/components/RecentListens.tsx b/frontend/src/components/RecentListens.tsx index 54bc952..abb8ca2 100644 --- a/frontend/src/components/RecentListens.tsx +++ b/frontend/src/components/RecentListens.tsx @@ -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) { diff --git a/frontend/src/components/ReportListens.tsx b/frontend/src/components/ReportListens.tsx index 6273265..3761667 100644 --- a/frontend/src/components/ReportListens.tsx +++ b/frontend/src/components/ReportListens.tsx @@ -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({ 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); diff --git a/frontend/src/hooks/use-api-client.tsx b/frontend/src/hooks/use-api-client.tsx index 3fead67..e600899 100644 --- a/frontend/src/hooks/use-api-client.tsx +++ b/frontend/src/hooks/use-api-client.tsx @@ -13,7 +13,7 @@ interface ApiClientContext { } const apiClientContext = createContext( - (undefined as any) as ApiClientContext + undefined as any as ApiClientContext ); export const ProvideApiClient: React.FC = ({ children }) => { diff --git a/frontend/src/hooks/use-api.tsx b/frontend/src/hooks/use-api.tsx index 2272cb1..51097a5 100644 --- a/frontend/src/hooks/use-api.tsx +++ b/frontend/src/hooks/use-api.tsx @@ -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 }; }; diff --git a/frontend/src/hooks/use-auth.tsx b/frontend/src/hooks/use-auth.tsx index a27a05a..bc5c3ca 100644 --- a/frontend/src/hooks/use-auth.tsx +++ b/frontend/src/hooks/use-auth.tsx @@ -17,9 +17,7 @@ interface AuthContext { loginWithSpotifyProps: () => { href: string }; } -const authContext = createContext( - (undefined as any) as AuthContext -); +const authContext = createContext(undefined as any as AuthContext); export const ProvideAuth: React.FC = ({ children }) => { const auth = useProvideAuth(); diff --git a/frontend/src/serviceWorker.ts b/frontend/src/serviceWorker.ts index b09523f..e7b8199 100644 --- a/frontend/src/serviceWorker.ts +++ b/frontend/src/serviceWorker.ts @@ -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); }); } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index d59dc13..9fca772 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -46,9 +46,7 @@ export class AuthService { return user; } - async createSession( - user: User - ): Promise<{ + async createSession(user: User): Promise<{ session: AuthSession; refreshToken: string; }> { diff --git a/src/database/migrations/04-CreateAuthSessionsTable.ts b/src/database/migrations/04-CreateAuthSessionsTable.ts index 802cf9f..c56349d 100644 --- a/src/database/migrations/04-CreateAuthSessionsTable.ts +++ b/src/database/migrations/04-CreateAuthSessionsTable.ts @@ -16,7 +16,8 @@ const primaryUUIDColumn: TableColumnOptions = { }; export class CreateAuthSessionsTable0000000000004 - implements MigrationInterface { + implements MigrationInterface +{ async up(queryRunner: QueryRunner): Promise { await queryRunner.createTable( new Table({ diff --git a/src/reports/reports.controller.spec.ts b/src/reports/reports.controller.spec.ts index 0d0b3c7..87c69e5 100644 --- a/src/reports/reports.controller.spec.ts +++ b/src/reports/reports.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ReportsController } from './reports.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { ReportsController } from "./reports.controller"; -describe('Reports Controller', () => { +describe("Reports Controller", () => { let controller: ReportsController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('Reports Controller', () => { controller = module.get(ReportsController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); diff --git a/src/reports/reports.service.spec.ts b/src/reports/reports.service.spec.ts index 79b4fa0..3e51341 100644 --- a/src/reports/reports.service.spec.ts +++ b/src/reports/reports.service.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ReportsService } from './reports.service'; +import { Test, TestingModule } from "@nestjs/testing"; +import { ReportsService } from "./reports.service"; -describe('ReportsService', () => { +describe("ReportsService", () => { let service: ReportsService; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('ReportsService', () => { service = module.get(ReportsService); }); - it('should be defined', () => { + it("should be defined", () => { expect(service).toBeDefined(); }); }); diff --git a/src/reports/reports.service.ts b/src/reports/reports.service.ts index a8cfdd9..93c62e8 100644 --- a/src/reports/reports.service.ts +++ b/src/reports/reports.service.ts @@ -79,8 +79,9 @@ export class ReportsService { const { eachOfInterval, isSame } = timeframeToDateFns[timeFrame]; const reportItems = eachOfInterval(interval).map((date) => { - const count = listens.filter((listen) => isSame(date, listen.playedAt)) - .length; + const count = listens.filter((listen) => + isSame(date, listen.playedAt) + ).length; return { date: formatISO(date), count }; }); diff --git a/src/sources/spotify/spotify.service.ts b/src/sources/spotify/spotify.service.ts index 099c53c..2f81428 100644 --- a/src/sources/spotify/spotify.service.ts +++ b/src/sources/spotify/spotify.service.ts @@ -263,7 +263,8 @@ export class SpotifyService { this.logger.debug("refreshing spotify app access token"); this.appAccessTokenInProgress = new Promise(async (resolve, reject) => { try { - const newAccessToken = await this.spotifyAuth.clientCredentialsGrant(); + const newAccessToken = + await this.spotifyAuth.clientCredentialsGrant(); this.appAccessToken = newAccessToken; this.logger.debug("spotify app access token refreshed");