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 { recentListens, paginationMeta, isLoading, reload } = useRecentListens(
options
);
const { recentListens, paginationMeta, isLoading, reload } =
useRecentListens(options);
useEffect(() => {
if (paginationMeta && totalPages !== paginationMeta.totalPages) {

View file

@ -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);

View file

@ -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 }) => {

View file

@ -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 };
};

View file

@ -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();

View file

@ -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);
});
}

View file

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

View file

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

View file

@ -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>(ReportsController);
});
it('should be defined', () => {
it("should be defined", () => {
expect(controller).toBeDefined();
});
});

View file

@ -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>(ReportsService);
});
it('should be defined', () => {
it("should be defined", () => {
expect(service).toBeDefined();
});
});

View file

@ -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 };
});

View file

@ -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");