Skip to content

Commit a7d0387

Browse files
authored
Merge pull request #24 from dctalbot/remove-dayjs
refactor: perf
2 parents 1fa85ad + ab7e8cc commit a7d0387

File tree

5 files changed

+17
-57
lines changed

5 files changed

+17
-57
lines changed

package-lock.json

Lines changed: 0 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
"expo-status-bar": "~3.0.8",
2727
"expo-system-ui": "~6.0.8",
2828
"expo-updates": "~29.0.12",
29-
"globals": "^16.4.0",
30-
"lodash-es": "^4.17.21",
3129
"react": "19.1.0",
3230
"react-native": "0.81.5",
3331
"react-native-pager-view": "6.9.1",
@@ -40,7 +38,6 @@
4038
},
4139
"devDependencies": {
4240
"@babel/core": "^7.28.4",
43-
"@types/lodash-es": "^4.17.12",
4441
"@types/react": "~19.1.10",
4542
"babel-plugin-transform-remove-console": "^6.9.4",
4643
"oxlint": "^1.26.0",

src/screens/schedule/ScheduleScreen.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { View } from "react-native";
22
import * as React from "react";
3-
import { get } from "lodash-es";
43
import { DAYS, getToday } from "../../util/time";
54
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
65
import { ScheduleTab } from "./ScheduleTab";
@@ -20,8 +19,8 @@ export function ScheduleScreen() {
2019
screenListeners={{
2120
state: (e) => {
2221
let nextTitle = "Schedule";
23-
const index = get(e, "data.state.index", null);
24-
const routeNames = get(e, "data.state.routeNames", []);
22+
const index = e?.data?.state?.index ?? null;
23+
const routeNames = e?.data?.state?.routeNames ?? [];
2524
if (index === null || routeNames.length === 0) {
2625
nextTitle = "Schedule";
2726
} else {

src/screens/schedule/ScheduleTab.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { Day, getScheduleDayRange, getTime } from "../../util/time";
1010
import { AppText } from "../../ui/AppText";
1111
import { AppSeparator } from "../../ui/AppSeparator";
1212
import { fontSize, fontWeight, spacing } from "../../theme/theme";
13-
import dayjs from "dayjs";
1413
import { getResourceID } from "@dctalbot/react-spinitron";
15-
import { get } from "lodash-es";
1614
import { usePersona } from "@dctalbot/react-spinitron";
1715
import { useTheme } from "../../theme/useTheme";
1816

@@ -24,7 +22,7 @@ function ShowListItem(props: ShowListItemProps) {
2422
const theme = useTheme();
2523
const name = props.item?.title;
2624
const at = getTime(props.item?.start);
27-
const personaIDs = get(props.item, "_links.personas", []).map(
25+
const personaIDs = (props?.item?._links?.personas ?? []).map(
2826
(
2927
x: any, // eslint-disable-line @typescript-eslint/no-explicit-any
3028
) => getResourceID(x.href),
@@ -45,7 +43,7 @@ function ShowListItem(props: ShowListItemProps) {
4543
if (personaIDs.length > 1) {
4644
host = `rotating hosts`;
4745
} else {
48-
host = get(data, "name", "");
46+
host = data?.name ?? "";
4947
}
5048
if (host.toLowerCase() === "rotating hosts") {
5149
host = "rotating hosts";
@@ -119,7 +117,7 @@ export function ScheduleTab(props: ScheduleTabProps) {
119117
});
120118

121119
const listdata = (data ?? []).filter(
122-
(i) => Boolean(i?.title && i?.start) && dayjs(i?.start) >= dayjs(start),
120+
(i) => i?.title && i?.start && Date.parse(i.start) >= Date.parse(start),
123121
);
124122

125123
if (isFetching && listdata.length === 0) {

src/util/time.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function fmtOnAt(input?: string): string {
4343
// }
4444

4545
export function getToday(): Day {
46-
return dayjs().format("dddd") as Day;
46+
return DAYS[new Date().getDay()];
4747
}
4848

4949
export function getScheduleDayRange(day: Day): [string, string] {
@@ -60,19 +60,23 @@ export function getScheduleDayRange(day: Day): [string, string] {
6060
// getTime returns 12-hour time and AM/PM.
6161
// If the input is invalid, an empty string is returned.
6262
export function getTime(input?: string): string {
63-
let result = "";
64-
6563
if (!input) {
6664
return "";
6765
}
6866

6967
try {
70-
result = dayjs(input).format("LT");
68+
const d = new Date(input);
69+
let hours = d.getHours();
70+
const minutes = d.getMinutes();
71+
const ampm = hours >= 12 ? "PM" : "AM";
72+
hours = hours % 12;
73+
if (hours === 0) {
74+
hours = 12;
75+
}
76+
const minutesStr = minutes.toString().padStart(2, "0");
77+
78+
return `${hours}:${minutesStr} ${ampm}`;
7179
} catch {
7280
return "";
7381
}
74-
if (!result) {
75-
return "";
76-
}
77-
return result;
7882
}

0 commit comments

Comments
 (0)