From 42362ba14b45f5116017ce43b200adcfe04f18fb Mon Sep 17 00:00:00 2001 From: Sean Norwood Date: Sat, 23 Apr 2022 18:10:12 +0000 Subject: [PATCH] chore: fix some misc syntax bugs --- src/lib/getPlaylists.ts | 25 +++++++++++++++---------- src/lib/utils.ts | 4 ++-- src/pages/channel.tsx | 20 ++++++++++++++++---- src/pages/playlist.tsx | 6 ++++-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/lib/getPlaylists.ts b/src/lib/getPlaylists.ts index edb6f9c..1b76077 100644 --- a/src/lib/getPlaylists.ts +++ b/src/lib/getPlaylists.ts @@ -1,13 +1,15 @@ import { Playlist } from "../types/playlist"; import { Playlists } from "../types/playlists"; -import { TA_BASE_URL } from "./constants"; +import { getTAUrl } from "./constants"; + +const TA_BASE_URL = getTAUrl(); export const getPlaylists = async (token: string): Promise => { if (!token) { throw new Error(`No token provided when fetching a playlists`); } - const response = await fetch(`${TA_BASE_URL}/api/playlist/`, { + const response = await fetch(`${TA_BASE_URL.server}/api/playlist/`, { headers: { Accept: "application/json", "Content-Type": "application/json", @@ -33,14 +35,17 @@ export const getPlaylist = async ( ); } - const response = await fetch(`${TA_BASE_URL}/api/playlist/${playlistId}`, { - headers: { - Accept: "application/json", - "Content-Type": "application/json", - Authorization: `Token ${token}`, - mode: "no-cors", - }, - }); + const response = await fetch( + `${TA_BASE_URL.server}/api/playlist/${playlistId}`, + { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Token ${token}`, + mode: "no-cors", + }, + } + ); if (!response.ok) { throw new Error( `Error getting playlists information: ${response.statusText}` diff --git a/src/lib/utils.ts b/src/lib/utils.ts index a00c48a..d17bbbb 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -3,8 +3,8 @@ * @param number A number or string number * @returns A number string with an appropriate letter appended */ -export function formatNumbers(number: string): string { - var numberUnformatted = parseFloat(number); +export function formatNumbers(number: string | number): string | number { + var numberUnformatted = parseFloat(number as string); if (numberUnformatted > 999999999) { var numberFormatted = (numberUnformatted / 1000000000).toFixed(1).toString() + "B"; diff --git a/src/pages/channel.tsx b/src/pages/channel.tsx index 14a6151..646b697 100644 --- a/src/pages/channel.tsx +++ b/src/pages/channel.tsx @@ -171,7 +171,9 @@ const Channel: NextPage = () => { {/* {% if channel.source.channel_subs >= 1000000 %} */} -

Subscribers: {formatNumbers(channel?.channel_subs)}

+

+ Subscribers: {formatNumbers(channel?.channel_subs)}{" "} +

{/* {% else %} */} @@ -185,10 +187,20 @@ const Channel: NextPage = () => { className="unsubscribe" type="button" id="{{ channel.source.channel_id }}" - onClick={() => console.log("unsubscribe(this.id) -> toggleSubscribe()")} - title={`${channel?.channel_subscribed ? "Unsubscribe from" : "Subscribe to"} ${channel?.channel_name}`} + onClick={() => + console.log( + "unsubscribe(this.id) -> toggleSubscribe()" + ) + } + title={`${ + channel?.channel_subscribed + ? "Unsubscribe from" + : "Subscribe to" + } ${channel?.channel_name}`} > - {channel?.channel_subscribed ? "Unsubscribe" : "Subscribe"} + {channel?.channel_subscribed + ? "Unsubscribe" + : "Subscribe"} {/* {% else %} */} {/*