chore: run prettier format

This commit is contained in:
Julian Tölle 2021-05-25 16:01:55 +02:00
parent b6c7c9e16d
commit f56548e432
12 changed files with 95 additions and 95 deletions

View file

@ -17,9 +17,8 @@ export const RecentListens: React.FC = () => {
const options = useMemo(() => ({ page, limit: LISTENS_PER_PAGE }), [page]); const options = useMemo(() => ({ page, limit: LISTENS_PER_PAGE }), [page]);
const { recentListens, paginationMeta, isLoading, reload } = useRecentListens( const { recentListens, paginationMeta, isLoading, reload } =
options useRecentListens(options);
);
useEffect(() => { useEffect(() => {
if (paginationMeta && totalPages !== paginationMeta.totalPages) { if (paginationMeta && totalPages !== paginationMeta.totalPages) {

View file

@ -22,9 +22,8 @@ import { ReportTimeOptions } from "./ReportTimeOptions";
export const ReportListens: React.FC = () => { export const ReportListens: React.FC = () => {
const { user } = useAuth(); const { user } = useAuth();
const [timeFrame, setTimeFrame] = useState<"day" | "week" | "month" | "year">( const [timeFrame, setTimeFrame] =
"day" useState<"day" | "week" | "month" | "year">("day");
);
const [timeOptions, setTimeOptions] = useState<TimeOptions>({ const [timeOptions, setTimeOptions] = useState<TimeOptions>({
timePreset: TimePreset.LAST_7_DAYS, timePreset: TimePreset.LAST_7_DAYS,
@ -32,10 +31,10 @@ export const ReportListens: React.FC = () => {
customTimeEnd: new Date(), customTimeEnd: new Date(),
}); });
const reportOptions = useMemo(() => ({ timeFrame, time: timeOptions }), [ const reportOptions = useMemo(
timeFrame, () => ({ timeFrame, time: timeOptions }),
timeOptions, [timeFrame, timeOptions]
]); );
const { report, isLoading } = useListensReport(reportOptions); const { report, isLoading } = useListensReport(reportOptions);

View file

@ -13,7 +13,7 @@ interface ApiClientContext {
} }
const apiClientContext = createContext<ApiClientContext>( const apiClientContext = createContext<ApiClientContext>(
(undefined as any) as ApiClientContext undefined as any as ApiClientContext
); );
export const ProvideApiClient: React.FC = ({ children }) => { export const ProvideApiClient: React.FC = ({ children }) => {

View file

@ -20,16 +20,18 @@ Object.freeze(INITIAL_EMPTY_ARRAY);
export const useRecentListens = (options: PaginationOptions) => { export const useRecentListens = (options: PaginationOptions) => {
const { client } = useApiClient(); const { client } = useApiClient();
const fetchData = useMemo(() => () => getRecentListens(options, client), [ const fetchData = useMemo(
options, () => () => getRecentListens(options, client),
client, [options, client]
]);
const { value, pending: isLoading, error, reload } = useAsync(
fetchData,
undefined
); );
const {
value,
pending: isLoading,
error,
reload,
} = useAsync(fetchData, undefined);
const recentListens = value ? value.items : []; const recentListens = value ? value.items : [];
const paginationMeta = value ? value.meta : undefined; const paginationMeta = value ? value.meta : undefined;
@ -39,63 +41,67 @@ export const useRecentListens = (options: PaginationOptions) => {
export const useListensReport = (options: ListenReportOptions) => { export const useListensReport = (options: ListenReportOptions) => {
const { client } = useApiClient(); const { client } = useApiClient();
const fetchData = useMemo(() => () => getListensReport(options, client), [ const fetchData = useMemo(
options, () => () => getListensReport(options, client),
client, [options, client]
]);
const { value: report, pending: isLoading, error } = useAsync(
fetchData,
INITIAL_EMPTY_ARRAY
); );
const {
value: report,
pending: isLoading,
error,
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
return { report, isLoading, error }; return { report, isLoading, error };
}; };
export const useTopArtists = (options: TopArtistsOptions) => { export const useTopArtists = (options: TopArtistsOptions) => {
const { client } = useApiClient(); const { client } = useApiClient();
const fetchData = useMemo(() => () => getTopArtists(options, client), [ const fetchData = useMemo(
options, () => () => getTopArtists(options, client),
client, [options, client]
]);
const { value: topArtists, pending: isLoading, error } = useAsync(
fetchData,
INITIAL_EMPTY_ARRAY
); );
const {
value: topArtists,
pending: isLoading,
error,
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
return { topArtists, isLoading, error }; return { topArtists, isLoading, error };
}; };
export const useTopAlbums = (options: TopAlbumsOptions) => { export const useTopAlbums = (options: TopAlbumsOptions) => {
const { client } = useApiClient(); const { client } = useApiClient();
const fetchData = useMemo(() => () => getTopAlbums(options, client), [ const fetchData = useMemo(
options, () => () => getTopAlbums(options, client),
client, [options, client]
]);
const { value: topAlbums, pending: isLoading, error } = useAsync(
fetchData,
INITIAL_EMPTY_ARRAY
); );
const {
value: topAlbums,
pending: isLoading,
error,
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
return { topAlbums, isLoading, error }; return { topAlbums, isLoading, error };
}; };
export const useTopTracks = (options: TopTracksOptions) => { export const useTopTracks = (options: TopTracksOptions) => {
const { client } = useApiClient(); const { client } = useApiClient();
const fetchData = useMemo(() => () => getTopTracks(options, client), [ const fetchData = useMemo(
options, () => () => getTopTracks(options, client),
client, [options, client]
]);
const { value: topTracks, pending: isLoading, error } = useAsync(
fetchData,
INITIAL_EMPTY_ARRAY
); );
const {
value: topTracks,
pending: isLoading,
error,
} = useAsync(fetchData, INITIAL_EMPTY_ARRAY);
return { topTracks, isLoading, error }; return { topTracks, isLoading, error };
}; };

View file

@ -17,9 +17,7 @@ interface AuthContext {
loginWithSpotifyProps: () => { href: string }; loginWithSpotifyProps: () => { href: string };
} }
const authContext = createContext<AuthContext>( const authContext = createContext<AuthContext>(undefined as any as AuthContext);
(undefined as any) as AuthContext
);
export const ProvideAuth: React.FC = ({ children }) => { export const ProvideAuth: React.FC = ({ children }) => {
const auth = useProvideAuth(); const auth = useProvideAuth();

View file

@ -11,9 +11,9 @@
// opt-in, read https://bit.ly/CRA-PWA // opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean( const isLocalhost = Boolean(
window.location.hostname === 'localhost' || window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address. // [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' || window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4. // 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match( window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ /^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) { 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. // The URL constructor is available in all browsers that support SW.
const publicUrl = new URL( const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
process.env.PUBLIC_URL,
window.location.href
);
if (publicUrl.origin !== window.location.origin) { if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different 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 // 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; return;
} }
window.addEventListener('load', () => { window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) { if (isLocalhost) {
@ -50,8 +47,8 @@ export function register(config?: Config) {
// service worker/PWA documentation. // service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => { navigator.serviceWorker.ready.then(() => {
console.log( console.log(
'This web app is being served cache-first by a service ' + "This web app is being served cache-first by a service " +
'worker. To learn more, visit https://bit.ly/CRA-PWA' "worker. To learn more, visit https://bit.ly/CRA-PWA"
); );
}); });
} else { } else {
@ -65,21 +62,21 @@ export function register(config?: Config) {
function registerValidSW(swUrl: string, config?: Config) { function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker navigator.serviceWorker
.register(swUrl) .register(swUrl)
.then(registration => { .then((registration) => {
registration.onupdatefound = () => { registration.onupdatefound = () => {
const installingWorker = registration.installing; const installingWorker = registration.installing;
if (installingWorker == null) { if (installingWorker == null) {
return; return;
} }
installingWorker.onstatechange = () => { installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') { if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) { if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched, // At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older // but the previous service worker will still serve the older
// content until all client tabs are closed. // content until all client tabs are closed.
console.log( console.log(
'New content is available and will be used when all ' + "New content is available and will be used when all " +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.' "tabs for this page are closed. See https://bit.ly/CRA-PWA."
); );
// Execute callback // Execute callback
@ -90,7 +87,7 @@ function registerValidSW(swUrl: string, config?: Config) {
// At this point, everything has been precached. // At this point, everything has been precached.
// It's the perfect time to display a // It's the perfect time to display a
// "Content is cached for offline use." message. // "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 // Execute callback
if (config && config.onSuccess) { if (config && config.onSuccess) {
@ -101,25 +98,25 @@ function registerValidSW(swUrl: string, config?: Config) {
}; };
}; };
}) })
.catch(error => { .catch((error) => {
console.error('Error during service worker registration:', error); console.error("Error during service worker registration:", error);
}); });
} }
function checkValidServiceWorker(swUrl: string, config?: Config) { function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page. // Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, { 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. // 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 ( if (
response.status === 404 || 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. // No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => { navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => { registration.unregister().then(() => {
window.location.reload(); window.location.reload();
}); });
@ -131,18 +128,18 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
}) })
.catch(() => { .catch(() => {
console.log( 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() { export function unregister() {
if ('serviceWorker' in navigator) { if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready navigator.serviceWorker.ready
.then(registration => { .then((registration) => {
registration.unregister(); registration.unregister();
}) })
.catch(error => { .catch((error) => {
console.error(error.message); console.error(error.message);
}); });
} }

View file

@ -46,9 +46,7 @@ export class AuthService {
return user; return user;
} }
async createSession( async createSession(user: User): Promise<{
user: User
): Promise<{
session: AuthSession; session: AuthSession;
refreshToken: string; refreshToken: string;
}> { }> {

View file

@ -16,7 +16,8 @@ const primaryUUIDColumn: TableColumnOptions = {
}; };
export class CreateAuthSessionsTable0000000000004 export class CreateAuthSessionsTable0000000000004
implements MigrationInterface { implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> { async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({

View file

@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from "@nestjs/testing";
import { ReportsController } from './reports.controller'; import { ReportsController } from "./reports.controller";
describe('Reports Controller', () => { describe("Reports Controller", () => {
let controller: ReportsController; let controller: ReportsController;
beforeEach(async () => { beforeEach(async () => {
@ -12,7 +12,7 @@ describe('Reports Controller', () => {
controller = module.get<ReportsController>(ReportsController); controller = module.get<ReportsController>(ReportsController);
}); });
it('should be defined', () => { it("should be defined", () => {
expect(controller).toBeDefined(); expect(controller).toBeDefined();
}); });
}); });

View file

@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from "@nestjs/testing";
import { ReportsService } from './reports.service'; import { ReportsService } from "./reports.service";
describe('ReportsService', () => { describe("ReportsService", () => {
let service: ReportsService; let service: ReportsService;
beforeEach(async () => { beforeEach(async () => {
@ -12,7 +12,7 @@ describe('ReportsService', () => {
service = module.get<ReportsService>(ReportsService); service = module.get<ReportsService>(ReportsService);
}); });
it('should be defined', () => { it("should be defined", () => {
expect(service).toBeDefined(); expect(service).toBeDefined();
}); });
}); });

View file

@ -79,8 +79,9 @@ export class ReportsService {
const { eachOfInterval, isSame } = timeframeToDateFns[timeFrame]; const { eachOfInterval, isSame } = timeframeToDateFns[timeFrame];
const reportItems = eachOfInterval(interval).map((date) => { const reportItems = eachOfInterval(interval).map((date) => {
const count = listens.filter((listen) => isSame(date, listen.playedAt)) const count = listens.filter((listen) =>
.length; isSame(date, listen.playedAt)
).length;
return { date: formatISO(date), count }; return { date: formatISO(date), count };
}); });

View file

@ -263,7 +263,8 @@ export class SpotifyService {
this.logger.debug("refreshing spotify app access token"); this.logger.debug("refreshing spotify app access token");
this.appAccessTokenInProgress = new Promise(async (resolve, reject) => { this.appAccessTokenInProgress = new Promise(async (resolve, reject) => {
try { try {
const newAccessToken = await this.spotifyAuth.clientCredentialsGrant(); const newAccessToken =
await this.spotifyAuth.clientCredentialsGrant();
this.appAccessToken = newAccessToken; this.appAccessToken = newAccessToken;
this.logger.debug("spotify app access token refreshed"); this.logger.debug("spotify app access token refreshed");