Skip to content

Commit bc3ac72

Browse files
Refactor Schedule related components
1 parent bbb1862 commit bc3ac72

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

src/api/profile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export const updatePersonalizedSchedule = async ({
9494
event,
9595
removeMode,
9696
});
97+
98+
throw err;
9799
});
98100
});
99101
};

src/components/molecules/ScheduleEvent/ScheduleEvent.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$grey--regular: #3f3d42;
44
$grey--hover: #4c494f;
55
$grey--users: #4c494f;
6-
$grey--ligth: #ebebeb;
6+
$grey--light: #ebebeb;
77

88
$purple--regular: #7c46fb;
99
$purple--hover: #7c46fb;
@@ -41,7 +41,7 @@ $description--margin-top: 2px;
4141

4242
&--users {
4343
color: $grey--hover;
44-
background-color: $grey--ligth;
44+
background-color: $grey--light;
4545

4646
&:hover {
4747
background-color: $white;

src/components/molecules/ScheduleVenueDescription/ScheduleVenueDescription.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useConnectRelatedVenues } from "hooks/useConnectRelatedVenues";
88

99
import "./ScheduleVenueDescription.scss";
1010

11-
const DEFAULT_VENUE_NAME = "Sparkle";
1211
export interface ScheduleVenueDescriptionProps {
1312
venueId: string;
1413
}
@@ -43,7 +42,7 @@ export const ScheduleVenueDescription: FC<ScheduleVenueDescriptionProps> = ({
4342
<div className={venuePictureClasses} />
4443
<div className="ScheduleVenueDescription__title">
4544
<h2 className="ScheduleVenueDescription__name">
46-
{scheduleVenue?.name ?? DEFAULT_VENUE_NAME}
45+
{scheduleVenue?.name ?? "Sparkle"}
4746
</h2>
4847
<h3 className="ScheduleVenueDescription__subtitle">
4948
{scheduleVenue?.config?.landingPageConfig?.subtitle}

src/components/organisms/NavBarSchedule/NavBarSchedule.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
getUnixTime,
1313
fromUnixTime,
1414
} from "date-fns";
15-
import { chain, range } from "lodash";
15+
import { groupBy, range } from "lodash";
1616
import classNames from "classnames";
1717

1818
import { SCHEDULE_SHOW_DAYS_AHEAD } from "settings";
@@ -90,11 +90,11 @@ export const NavBarSchedule: FC<NavBarScheduleProps> = ({ isVisible }) => {
9090
});
9191
}, [selectedDayIndex]);
9292

93-
const getLocaion = useCallback(
93+
const getEventLocation = useCallback(
9494
(locString: string): VenueLocation => {
9595
const [venueId, roomTitle = ""] = extractLocation(locString);
96-
const venueTitle =
97-
relatedVenues.find((venue) => venue.id === venueId)?.name || "";
96+
const venueTitle = relatedVenues.find((venue) => venue.id === venueId)
97+
?.name;
9898
return { venueId, roomTitle, venueTitle };
9999
},
100100
[relatedVenues]
@@ -106,18 +106,20 @@ export const NavBarSchedule: FC<NavBarScheduleProps> = ({ isVisible }) => {
106106
.filter(isEventWithinDate(selectedDayIndex === 0 ? Date.now() : dayStart))
107107
.map(prepareForSchedule(dayStart, userEventIds));
108108

109-
const locatedEvents: LocatedEvents[] = chain(daysEvents)
110-
.groupBy(buildLocationString)
111-
.map((value, key) => ({ location: getLocaion(key), events: value }))
112-
.value();
109+
const locatedEvents: LocatedEvents[] = Object.entries(
110+
groupBy(daysEvents, buildLocationString)
111+
).map(([group, events]) => ({
112+
events,
113+
location: getEventLocation(group),
114+
}));
113115

114116
return {
115117
locatedEvents,
116118
isToday: selectedDayIndex === 0,
117119
dayStartUtcSeconds: getUnixTime(dayStart),
118120
personalEvents: daysEvents.filter((event) => event.isSaved),
119121
};
120-
}, [relatedVenueEvents, userEventIds, selectedDayIndex, getLocaion]);
122+
}, [relatedVenueEvents, userEventIds, selectedDayIndex, getEventLocation]);
121123

122124
// if .NavBarSchedule is changed, we need to update the class name in NavBar#hideEventSchedule event handler as well
123125
const containerClasses = classNames("NavBarSchedule", {

src/pages/Admin/VenueEventDetails.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { format, getUnixTime } from "date-fns";
44
import { VenueEvent } from "types/venues";
55

66
import { WithId } from "utils/id";
7-
import { formatHourAndMinute, getTimeBeforeParty } from "utils/time";
7+
import { formatHourAndMinute } from "utils/time";
88
import { eventEndTime, eventStartTime } from "utils/event";
99

1010
export interface VenueEventDetailsProps {
@@ -25,7 +25,6 @@ const VenueEventDetails = ({
2525
const startTime = formatHourAndMinute(venueEvent.start_utc_seconds);
2626
const endTime = formatHourAndMinute(getUnixTime(eventEndTime(venueEvent)));
2727
const startDay = format(eventStartTime(venueEvent), "EEEE LLLL do");
28-
console.log("here");
2928

3029
return (
3130
<div className={className}>
@@ -43,8 +42,6 @@ const VenueEventDetails = ({
4342
</span>
4443
</div>
4544
{venueEvent.description}
46-
<br />
47-
{getTimeBeforeParty(venueEvent.start_utc_seconds)}
4845

4946
{venueEvent.descriptions?.map((description, index) => (
5047
<p key={index}>{description}</p>

src/utils/formatMeasurement.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export const formatMeasurement = (value: number, measureUnit: string) => {
22
const baseFormatted = `${value} ${measureUnit}`;
33

4-
if (value === 0) return "";
5-
if (value === 1) return baseFormatted;
6-
if (value > 1) return `${baseFormatted}s`;
4+
return value === 1 ? baseFormatted : `${baseFormatted}s`;
75
};

src/utils/time.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ import {
1414
* @deprecated in favor of using date-fns functions
1515
*/
1616
export const ONE_SECOND_IN_MILLISECONDS = 1000;
17+
1718
/**
1819
* @deprecated in favor of using date-fns functions
1920
*/
2021
export const ONE_MINUTE_IN_SECONDS = 60;
22+
2123
/**
2224
* @deprecated in favor of using date-fns functions
2325
*/
2426
export const ONE_HOUR_IN_MINUTES = 60;
27+
2528
/**
2629
* @deprecated in favor of using date-fns functions
2730
*/
2831
export const ONE_HOUR_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 60;
32+
2933
/**
3034
* @deprecated in favor of using date-fns functions
3135
*/
@@ -42,6 +46,7 @@ export const FIVE_MINUTES_MS =
4246
*/
4347
export const ONE_HOUR_IN_MILLISECONDS =
4448
ONE_SECOND_IN_MILLISECONDS * ONE_HOUR_IN_SECONDS;
49+
4550
/**
4651
* @deprecated in favor of using date-fns functions
4752
*/
@@ -96,7 +101,7 @@ export const getTimeBeforeParty = (startUtcSeconds?: number) => {
96101

97102
return formatDuration(
98103
intervalToDuration({
99-
start: Date.now(),
104+
start: now,
100105
end: eventStartDate,
101106
}),
102107
{ format: ["days", "hours", "minutes"] }
@@ -187,14 +192,13 @@ export const getCurrentTimeInUTCSeconds = () => getUnixTime(Date.now());
187192
*
188193
* @see https://date-fns.org/docs/formatRelative
189194
*/
190-
export const formatUtcSecondsRelativeToNow = (utcSeconds: number) => {
191-
return formatRelative(fromUnixTime(utcSeconds), Date.now());
192-
};
195+
export const formatUtcSecondsRelativeToNow = (utcSeconds: number) =>
196+
formatRelative(fromUnixTime(utcSeconds), Date.now());
193197

194-
// @debt get rid of ONE_SECOND_IN_MILLISECONDS and use date-fns function
195198
export const normalizeTimestampToMilliseconds = (timestamp: number) => {
196199
const isTimestampInMilliSeconds = timestamp > SECONDS_TIMESTAMP_MAX_VALUE;
197200

201+
// @debt get rid of ONE_SECOND_IN_MILLISECONDS and use date-fns function
198202
return isTimestampInMilliSeconds
199203
? timestamp
200204
: timestamp * ONE_SECOND_IN_MILLISECONDS;

0 commit comments

Comments
 (0)