Skip to content

Commit 5e79634

Browse files
authored
Merge pull request #136 from WMBR-MIT/fix/highlight-current-show
fix: highlight current show on schedule page
2 parents c6cc8fb + e1e1ab6 commit 5e79634

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/app/Schedule/SchedulePage.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,29 @@ import { RecentlyPlayedService } from '@services/RecentlyPlayedService';
2323
import { WmbrRouteName } from '@customTypes/Navigation';
2424
import { COLORS, CORE_COLORS } from '@utils/Colors';
2525

26-
interface SchedulePageProps {
27-
currentShow?: string;
28-
}
29-
30-
export default function SchedulePage({ currentShow }: SchedulePageProps) {
26+
export default function SchedulePage() {
3127
const navigation =
3228
useNavigation<NavigationProp<Record<WmbrRouteName, object | undefined>>>();
3329

3430
const headerHeight = useHeaderHeight();
3531

3632
const [schedule, setSchedule] = useState<ScheduleResponse | null>(null);
33+
const [currentShowTitle, setCurrentShowTitle] = useState<string>();
3734
const [loading, setLoading] = useState(true);
3835
const [error, setError] = useState<string | null>(null);
3936
const [searchQuery, setSearchQuery] = useState('');
4037
const scrollViewRef = useRef<ScrollView>(null);
41-
const currentShowRef = useRef<View>(null);
4238

4339
const scheduleService = ScheduleService.getInstance();
40+
const recentlyPlayedService = RecentlyPlayedService.getInstance();
41+
42+
useEffect(() => {
43+
const unsubscribe = recentlyPlayedService.subscribeToCurrentShow(show => {
44+
setCurrentShowTitle(show ?? undefined);
45+
});
46+
47+
return unsubscribe;
48+
}, [recentlyPlayedService]);
4449

4550
const fetchSchedule = useCallback(async () => {
4651
setLoading(true);
@@ -81,9 +86,6 @@ export default function SchedulePage({ currentShow }: SchedulePageProps) {
8186

8287
const handleShowPress = async (show: ScheduleShow) => {
8388
try {
84-
// Fetch archives for this show from the recently played service
85-
const recentlyPlayedService = RecentlyPlayedService.getInstance();
86-
8789
// fetch show cache (xml only)
8890
await recentlyPlayedService.fetchShowsCacheOnly();
8991

@@ -118,10 +120,11 @@ export default function SchedulePage({ currentShow }: SchedulePageProps) {
118120
show: ScheduleShow,
119121
dayName: string,
120122
): boolean => {
121-
if (!currentShow) return false;
123+
if (!currentShowTitle) return false;
122124

123125
// Match by name (case insensitive)
124-
const isNameMatch = show.name.toLowerCase() === currentShow.toLowerCase();
126+
const isNameMatch =
127+
show.name.trim().toLowerCase() === currentShowTitle.trim().toLowerCase();
125128
if (!isNameMatch) return false;
126129

127130
// Get current day info
@@ -203,7 +206,7 @@ export default function SchedulePage({ currentShow }: SchedulePageProps) {
203206
style={[styles.showItem, isCurrent && styles.currentShowItem]}
204207
onPress={() => handleShowPress(show)}
205208
activeOpacity={0.7}
206-
ref={isCurrent ? currentShowRef : null}
209+
ref={null}
207210
>
208211
<View style={styles.showContent}>
209212
<View style={styles.showMainInfo}>

0 commit comments

Comments
 (0)