Refactoring theme files

This commit is contained in:
Sean Edmunds
2025-07-28 19:57:06 -05:00
parent 8fcf9a19f2
commit b4e4f14310
33 changed files with 211 additions and 288 deletions

View File

@@ -15,29 +15,35 @@ function Applications({ contentType }: { contentType: string[] }) {
useEffect(() => {
if (applicationData && !isApplicationDataFetching) {
setApplications(
applicationData.sort((a: Application, b: Application) => {
switch (appSort) {
case 'A>Z':
return a.name > b.name ? 1 : -1;
case 'Z>A':
return a.name < b.name ? 1 : -1;
case 'Newest':
if (a.id && b.id) {
return a.id < b.id ? 1 : -1;
}
return -1;
case 'Oldest':
if (a.id && b.id) {
return a.id > b.id ? 1 : -1;
}
return -1;
case 'Custom':
return a.index > b.index ? 1 : -1;
}
}),
applicationData
.sort((a: Application, b: Application) => {
switch (appSort) {
case 'A>Z':
return a.name > b.name ? 1 : -1;
case 'Z>A':
return a.name < b.name ? 1 : -1;
case 'Newest':
if (a.id && b.id) {
return a.id < b.id ? 1 : -1;
}
return -1;
case 'Oldest':
if (a.id && b.id) {
return a.id > b.id ? 1 : -1;
}
return -1;
case 'Custom':
return a.index > b.index ? 1 : -1;
}
})
?.filter(
(application: Application) =>
contentType.includes(application.filterName) || contentType.includes('All'),
),
);
}
}, [applicationData, isApplicationDataFetching, appSort]);
}, [applicationData, isApplicationDataFetching, appSort, contentType]);
return (
<>
{applications.length > 0 && contentType.length > 0 && (
@@ -60,25 +66,19 @@ function Applications({ contentType }: { contentType: string[] }) {
gridTemplateColumns: `repeat(${appDensity}, 1fr)`,
}}
>
{applications
?.filter(
(application: Application) =>
contentType.includes(application.filterName) ||
contentType.includes('All'),
)
.map((application: Application) => {
return (
<AppItem
key={application.name}
name={application.name}
url={application.url}
icon={application.icon}
enabled={application.enabled}
scale={appScale}
linksActive
/>
);
})}
{applications.map((application: Application) => {
return (
<AppItem
key={application.name}
name={application.name}
url={application.url}
icon={application.icon}
enabled={application.enabled}
scale={appScale}
linksActive
/>
);
})}
</Stack>
</Stack>
)}

View File

@@ -28,29 +28,34 @@ function Bookmarks({ contentType }: { contentType: string[] }) {
return category;
});
setGroups(
groupList.sort((a: BookmarkGroup, b: BookmarkGroup) => {
switch (bookmarkSort) {
case 'A>Z':
return a.categoryName > b.categoryName ? 1 : -1;
case 'Z>A':
return a.categoryName < b.categoryName ? 1 : -1;
case 'Newest':
if (a.id && b.id) {
return a.id < b.id ? 1 : -1;
}
return -1;
case 'Oldest':
if (a.id && b.id) {
return a.id > b.id ? 1 : -1;
}
return -1;
case 'Custom':
return a.categoryIndex > b.categoryIndex ? 1 : -1;
}
}),
groupList
.sort((a: BookmarkGroup, b: BookmarkGroup) => {
switch (bookmarkSort) {
case 'A>Z':
return a.categoryName > b.categoryName ? 1 : -1;
case 'Z>A':
return a.categoryName < b.categoryName ? 1 : -1;
case 'Newest':
if (a.id && b.id) {
return a.id < b.id ? 1 : -1;
}
return -1;
case 'Oldest':
if (a.id && b.id) {
return a.id > b.id ? 1 : -1;
}
return -1;
case 'Custom':
return a.categoryIndex > b.categoryIndex ? 1 : -1;
}
})
?.filter(
(category: BookmarkGroup) =>
contentType.includes(category.filterName) || contentType.includes('All'),
),
);
}
}, [groupData, groupsIsFetched, bookmarkSort]);
}, [groupData, groupsIsFetched, bookmarkSort, contentType]);
return (
<>
@@ -79,26 +84,18 @@ function Bookmarks({ contentType }: { contentType: string[] }) {
gridTemplateColumns: `repeat(${bookmarkDensity}, 1fr)`,
}}
>
{groups
?.filter(
(category: BookmarkGroup) =>
contentType.includes(category.filterName) ||
contentType.includes('All'),
)
.map((category: BookmarkGroup) => {
return (
<BookmarkGroups
key={category.categoryName}
category={category.categoryName}
bookmarks={bookmarks.filter(
(bookmark: Bookmark) =>
bookmark.category === category.categoryName,
)}
bookmarkScale={bookmarkScale}
/>
);
})}
{groups.map((category: BookmarkGroup) => {
return (
<BookmarkGroups
key={category.categoryName}
category={category.categoryName}
bookmarks={bookmarks.filter(
(bookmark: Bookmark) => bookmark.category === category.categoryName,
)}
bookmarkScale={bookmarkScale}
/>
);
})}
</Stack>
</Stack>
)}

View File

@@ -8,17 +8,11 @@ function Header({
greet,
date,
current,
setCurrent,
weather,
basicWeather,
openWeatherModal,
}: {
greet: string | undefined;
date: string;
current: CurrentWeather;
setCurrent: (current: CurrentWeather) => void;
weather: any;
basicWeather: any;
openWeatherModal: () => void;
}) {
const [time, setTime] = useState(new Date());
@@ -30,43 +24,6 @@ function Header({
setTime(newDate);
}, 1000);
}, []);
useEffect(() => {
if (weather !== undefined && basicWeather !== undefined) {
setCurrent({
icon: weather.features[0]?.properties.icon?.replace('medium', 'large') ?? '',
textDescription: weather.features[0]?.properties.textDescription,
temperature: Math.round(
(weather.features[0]?.properties.temperature.value * 9) / 5 + 32,
),
highTemp: Math.round(
(basicWeather.properties.maxTemperature.values[0].value * 9) / 5 + 32,
),
lowTemp: Math.round(
(basicWeather.properties.minTemperature.values[0].value * 9) / 5 + 32,
),
precipitation:
weather.features[0]?.properties.precipitationLastHour.value ?? 'N/A',
humidity: Math.round(weather.features[0]?.properties.relativeHumidity.value),
heatIndex:
basicWeather.properties.heatIndex?.values[0].value === null
? null
: Math.round(
(basicWeather.properties.heatIndex.values[0].value * 9) / 5 + 32,
),
windChill:
basicWeather.properties.windChill?.values[0].value === null
? null
: Math.round(
(basicWeather.properties.windChill.values[0].value * 9) / 5 + 32,
),
windSpeed: Math.round(weather.features[0]?.properties.windSpeed.value / 1.60934),
windDirection: weather.features[0]?.properties.windDirection.value,
pressure: Math.round(
weather.features[0]?.properties.barometricPressure.value / 3386.38,
),
});
}
}, [weather, basicWeather]);
return (
<Stack

View File

@@ -2,21 +2,8 @@ import { Stack, Text } from '@mantine/core';
import { useCommonHooks } from 'hooks';
import { useEffect, useState } from 'react';
import { textClasses } from 'styles';
import type { CurrentWeather as CW } from 'types';
function LargeHeader({
greet,
date,
setCurrent,
weather,
basicWeather,
}: {
greet: string | undefined;
date: string;
weather: any;
basicWeather: any;
setCurrent: (current: CW) => void;
}) {
function LargeHeader({ greet, date }: { greet: string | undefined; date: string }) {
const [time, setTime] = useState(new Date());
const { isMobile, currentUser, fixDigits, theme } = useCommonHooks();
@@ -27,44 +14,6 @@ function LargeHeader({
}, 1000);
}, []);
useEffect(() => {
if (weather !== undefined && basicWeather !== undefined) {
setCurrent({
icon: weather.features[0]?.properties.icon?.replace('medium', 'large') ?? '',
textDescription: weather.features[0]?.properties.textDescription,
temperature: Math.round(
(weather.features[0]?.properties.temperature.value * 9) / 5 + 32,
),
highTemp: Math.round(
(basicWeather.properties.maxTemperature.values[0].value * 9) / 5 + 32,
),
lowTemp: Math.round(
(basicWeather.properties.minTemperature.values[0].value * 9) / 5 + 32,
),
precipitation:
weather.features[0]?.properties.precipitationLastHour.value ?? 'N/A',
humidity: Math.round(weather.features[0]?.properties.relativeHumidity.value),
heatIndex:
basicWeather.properties.heatIndex?.values[0].value === null
? null
: Math.round(
(basicWeather.properties.heatIndex.values[0].value * 9) / 5 + 32,
),
windChill:
basicWeather.properties.windChill?.values[0].value === null
? null
: Math.round(
(basicWeather.properties.windChill.values[0].value * 9) / 5 + 32,
),
windSpeed: Math.round(weather.features[0]?.properties.windSpeed.value / 1.60934),
windDirection: weather.features[0]?.properties.windDirection.value,
pressure: Math.round(
weather.features[0]?.properties.barometricPressure.value / 3386.38,
),
});
}
}, [weather, basicWeather]);
return (
<Stack gap={0} pos={'absolute'} align='center' justify='center' top={0}>
<Text