Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 14, 2023
1 parent 66627db commit a105109
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/FilterForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
class="hidden peer"
/>
<span
class="px-4 py-2 rounded-l-sm
class="px-4 py-2 rounded-l-sm
bg-zinc-50 text-black dark:text-white dark:bg-zinc-800 peer-checked:bg-green-700 peer-checked:text-white dark:peer-checked:bg-green-900/75"
>And</span
>
<span
class="px-4 py-2 rounded-r-sm
class="px-4 py-2 rounded-r-sm
bg-green-700 dark:bg-green-900/75
peer-checked:text-black peer-checked:bg-zinc-50 dark:peer-checked:bg-zinc-800 dark:peer-checked:text-white"
>Or</span
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/TagWrapper.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { lightColors, darkColors } from "$lib/resources";
export let tagColor: string | undefined = undefined;
export let tagColor: string | undefined = undefined;
export let extraClasses: string = "";
let lightTagColor: string | undefined, darkTagColor: string | undefined;
Expand Down
12 changes: 7 additions & 5 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export interface YoutubeVideo {
}

export interface FilterOption extends Tag {
count: number | string;
active: boolean;
id?: string;
count: number | string;
active: boolean;
id?: string;
}

export type FilterLogic = "and" | "or"
export type FilterLogic = "and" | "or";

export type CustomFilterEvent = {filter:{filterOptions: FilterOption[], filterLogic: FilterLogic }}
export type CustomFilterEvent = {
filter: { filterOptions: FilterOption[]; filterLogic: FilterLogic };
};
82 changes: 44 additions & 38 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,61 @@ import type { YoutubeChannel } from "./interfaces";

/**
* format subcount for user display
* @param number
* @returns
* @param number
* @returns
*/
export const semanticNumber = (number: number): string => {
// number less than 1000
if (number < 1000) {
return number.toString();
}
// number between 1k and 1M
else if (number >= 1000 && number < 1000000) {
return `${(number / 1000).toFixed(0)}k`;
}
// number between 1M and 1B
else if (number >= 1000000 && number < 1_000000000) {
return `${(number / 1000000).toFixed(1)}M`;
} else {
return ">1B";
}
}
// number less than 1000
if (number < 1000) {
return number.toString();
}
// number between 1k and 1M
else if (number >= 1000 && number < 1000000) {
return `${(number / 1000).toFixed(0)}k`;
}
// number between 1M and 1B
else if (number >= 1000000 && number < 1_000000000) {
return `${(number / 1000000).toFixed(1)}M`;
} else {
return ">1B";
}
};

/**
* channels sorted by subcount, climate town always first
* @param a YoutubeChannel
* @param b YoutubeChannel
* @returns sort number
*/
export const sortChannelBySubCount = (a: YoutubeChannel, b: YoutubeChannel): number => {
const ClimateTownChannelId = "UCuVLG9pThvBABcYCm7pkNkA";
export const sortChannelBySubCount = (
a: YoutubeChannel,
b: YoutubeChannel,
): number => {
const ClimateTownChannelId = "UCuVLG9pThvBABcYCm7pkNkA";

if (a.channelId === ClimateTownChannelId) {
return -1;
}
if (b.channelId === ClimateTownChannelId) {
return 1;
}
if (a.channelId === ClimateTownChannelId) {
return -1;
}
if (b.channelId === ClimateTownChannelId) {
return 1;
}

// Normal sort
return b.channelSubCount - a.channelSubCount;
}
// Normal sort
return b.channelSubCount - a.channelSubCount;
};

/**
* Given a channel ID, return the channel data from the array
* @param channelData YoutubeChannel[]
* @param channelId string
* @returns found channel data
*/
export const getChannelData = (channelData: YoutubeChannel[], channelId: string): YoutubeChannel | undefined => {
return channelData.find((channel) => channel.channelId === channelId);
}
export const getChannelData = (
channelData: YoutubeChannel[],
channelId: string,
): YoutubeChannel | undefined => {
return channelData.find((channel) => channel.channelId === channelId);
};

/**
* compare sets and return a new set with any found matches
Expand All @@ -59,11 +65,11 @@ export const getChannelData = (channelData: YoutubeChannel[], channelId: string)
* @returns new Set()
*/
export const setIntersection = (set1: Set<any>, set2: Set<any>) => {
let intersection = new Set();
for (let element of set2) {
if (set1.has(element)) {
intersection.add(element);
}
let intersection = new Set();
for (let element of set2) {
if (set1.has(element)) {
intersection.add(element);
}
return intersection;
}
}
return intersection;
};
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
onMount(() => twemoji.parse(document.body));
import "../app.css";
</script>

<svelte:head>
Expand Down
8 changes: 4 additions & 4 deletions src/routes/resources/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
count: tags_count[tag.name],
active: false
}
if (tag.color) tagOption['color'] = tag.color
if (tag.color) tagOption['color'] = tag.color
filterObject.push(tagOption)
}
Expand All @@ -44,7 +44,7 @@
// ! Need to refactor later to make more readable
// For Intersection filterTags.size
// For union, minCommonTags = 1
let minCommonTags = filterLogic === "and" ? filterTags.size : 1;
let minCommonTags = filterLogic === "and" ? filterTags.size : 1;
for (let resource of resources) {
// Resource tags
Expand All @@ -54,7 +54,7 @@
displayedResources.push(resource);
}
}
// Force svelte re-render
displayedResources = displayedResources;
}
Expand Down Expand Up @@ -83,4 +83,4 @@
</ol>
<p class="italic text-center m-4">Those are all the resources!</p>

<ScrollTopButton on:updateLimit={updateLimit} />
<ScrollTopButton on:updateLimit={updateLimit} />

0 comments on commit a105109

Please sign in to comment.