Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 | 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 5x 5x 5x 5x 14x 7x 7x 6x 6x 3x 3x 3x 3x 6x 3x 6x 3x 3x 3x 3x 7x 7x 6x 6x 6x 7x 5x 5x 2x 2x 5x 5x 5x 5x 5x 5x 154x 7x 1x 1x 7x 7x 7x 22x 7x 38x 38x 38x 1x 10x 3x 7x 37x 37x 5x 32x 7x 1x 6x 1x 5x 50x 50x 50x 5x 5x 25x 5x 20x 20x 20x 20x 5x 50x 50x 50x 50x 50x 50x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 25x 5x 5x 25x 35x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 4x 1x 1x 1x 5x 5x 4x 4x 12x 12x 5x 5x 5x 5x | import React, { useEffect, useMemo, useState, useCallback } from 'react';
import {
ActivityIndicator,
Dimensions,
Pressable,
ScrollView,
Text,
TouchableOpacity,
View,
LayoutChangeEvent,
} from 'react-native';
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
Easing,
} from 'react-native-reanimated';
import { favoriteStore } from '@sb/stores';
import { CountryItemProps, HighlightItems } from '@sb/types';
import { Accordion } from '../../../molecules/Accordion/mobile/Accordion.native';
import { ListGroup } from '../../../atoms/ListGroup/mobile/ListGroup.native';
import { CountryFlag } from '../../../atoms/CountryFlag/mobile/CountryFlag.native';
import { Tabs } from '../../../molecules/tabs/mobile/Tabs.native';
import { Button } from '../../../atoms/Button/mobile';
import {
Ball,
Basketball,
ChrevonDown,
ChrevonUp,
Futsal,
Handball,
IceHockey,
Star,
StarFill,
TableTennis,
Tennis,
UEFA,
Volleyball,
} from '@sb/ui/components/atoms/Icons/mobile/Icons.native';
import { Clock } from '@sb/ui/components/atoms/Icons/index.native';
import { useTheme } from '../../../Themes/ThemeProvider';
import { colors } from '@sb/styles/colors';
import { cn } from '@sb/libs';
import { iso3ToIso2 } from '@sb/constants/Shared/CountryCodes/countryCodes';
import { HomeCategoryWidgetProps } from '../HomeCategory.types';
import { useHomeCategoryState } from '@sb/hooks/pages/useHomeCategoryState';
import { useAccordion } from '../../../molecules/Accordion/mobile/Components/Context/AccordionContext';
const AnimatedView = Animated.createAnimatedComponent(View);
export const HomeCategory: React.FC<HomeCategoryWidgetProps> = ({
favorites,
highlights = HighlightItems,
categories = [],
matchCategories = [],
loading = false,
error,
className,
onSelectLeague,
onLongTimeBet,
onToggleFavorite,
onSelectMatchCategory,
activeMatchCategory: activeMatchCategoryProp,
timeFilter: timeFilterProp,
onTimeFilterChange,
handleOnAllSportsPress = () => {},
handleOnAllLongTimeBet = () => {},
}) => {
const favStore = favoriteStore();
const { theme } = useTheme();
const themeColors = colors[theme];
const [activeTab, setActiveTab] = useState(0); // 0 = LIGEN
const [showAllFilters, setShowAllFilters] = useState(false);
const SHOW_ALLE_CLOCK = activeTab === 0; // only show "Alle" clock in first tab
const LongTimeBet = activeTab === 1; // second tab is long-time bets
const { activeMatchCategory, setActiveMatchCategory, timeFilter, setTimeFilter } =
useHomeCategoryState({
activeMatchCategoryProp,
onSelectMatchCategory,
timeFilterProp,
onTimeFilterChange,
});
const currentFavorites = favorites ?? favStore.leagues;
const timeFiltersHeight = useSharedValue(0);
const timeFiltersOpacity = useSharedValue(0);
const [measuredTimeFiltersHeight, setMeasuredTimeFiltersHeight] = useState(0);
const shouldShowTimeFilters =
SHOW_ALLE_CLOCK && showAllFilters && activeMatchCategory === undefined;
useEffect(() => {
const toHeight = shouldShowTimeFilters ? measuredTimeFiltersHeight : 0;
const toOpacity = shouldShowTimeFilters ? 1 : 0;
timeFiltersHeight.value = withTiming(toHeight, {
duration: 350,
easing: Easing.inOut(Easing.sin),
});
timeFiltersOpacity.value = withTiming(toOpacity, {
duration: 300,
easing: Easing.linear,
});
}, [shouldShowTimeFilters, measuredTimeFiltersHeight, timeFiltersHeight, timeFiltersOpacity]);
// Animated styles for time filters
const timeFiltersAnimatedStyle = useAnimatedStyle(() => ({
height: timeFiltersHeight.value,
opacity: timeFiltersOpacity.value,
overflow: 'hidden',
}));
// Measure content height for animation
const onTimeFiltersLayout = useCallback(
(e: LayoutChangeEvent) => {
if (measuredTimeFiltersHeight === 0) {
const newHeight = e.nativeEvent.layout.height;
setMeasuredTimeFiltersHeight(newHeight);
// Start with collapsed state
timeFiltersHeight.value = 0;
timeFiltersOpacity.value = 0;
}
},
[measuredTimeFiltersHeight, timeFiltersHeight, timeFiltersOpacity]
);
const favoritesSectionList = useMemo(() => {
const map: Record<string, { parent?: CountryItemProps; groups: CountryItemProps[] }> = {};
currentFavorites.forEach((fav) => {
const fid = String(fav.id);
Iif (fid.includes('-group-')) {
const [parentId] = fid.split('-group-');
map[parentId] = map[parentId] ?? { parent: undefined, groups: [] };
map[parentId].groups.push(fav as CountryItemProps);
} else {
map[fid] = map[fid] ?? { parent: undefined, groups: [] };
map[fid].parent = fav as CountryItemProps;
}
});
Object.keys(map).forEach((pid) => {
Iif (!map[pid].parent) {
const found =
highlights.find((h) => String(h.id) === pid) ||
categories.find((c) => String(c.id) === pid);
if (found) map[pid].parent = found;
}
});
return Object.keys(map).map((pid) => {
const entry = map[pid];
Eif (entry.parent) {
// If groups exist, attach their league strings as in other sections
Iif (entry.groups.length > 0) {
return {
...entry.parent,
groups: entry.groups.map((g) => g.league) as CountryItemProps['groups'],
} as CountryItemProps;
}
return entry.parent as CountryItemProps;
}
const first = entry.groups[0];
return {
id: pid,
name: String(first?.name ?? ''),
iso: '',
league: first?.league ?? '',
groups: entry.groups.map((g) => g.league) as CountryItemProps['groups'],
} as CountryItemProps;
});
}, [currentFavorites, highlights, categories]);
const favoritesAccordionItems = useMemo(
() => [
{
label: (
<View
className="flex-row items-center justify-between px-[7px]"
style={{
backgroundColor: themeColors.colorPrimary,
}}
>
<Text
className="font-Bold text-[16px]"
style={{
color: themeColors.colorText_Main,
}}
>
FAVORITEN
</Text>
{allSportText()}
</View>
),
content: (
<ScrollView className="p-0">
{currentFavorites.length === 0 ? (
<Text
className="px-[14px] py-4 text-lg font-normal"
style={{ color: themeColors.colorText_Primary }}
>
Noch keine Favoriten ausgewählt.
</Text>
) : (
<ScrollView>
<ListGroup
items={favoritesSectionList}
variant="striped"
className="p-0"
stripedColors={{ even: 'bg-tertiary-background', odd: 'bg-primary' }}
itemTemplate={(item) => {
const country = item as CountryItemProps;
Iif (Array.isArray(country.groups) && country.groups.length > 0) {
return (
<Accordion
items={[
{
label: <CountryHeaderLabel country={country} />,
content: renderGroupList(country.groups, country.id),
className: '',
},
]}
headerClassName="bg-transparent border-0 px-[14px] m-0 !py-0"
icon={''}
activeIcon={''}
flush
/>
);
}
return renderCountryRow(country);
}}
/>
</ScrollView>
)}
</ScrollView>
),
},
],
[currentFavorites, favoritesSectionList, allSportText]
);
useEffect(() => {
const map: Record<string, Set<string>> = {};
currentFavorites.forEach((fav) => {
const fid = String(fav.id);
Iif (fid.includes('-group-')) {
const [parentId] = fid.split('-group-');
map[parentId] = map[parentId] ?? new Set<string>();
map[parentId].add(fid);
}
});
setFavoriteGroupSelections((prev) => {
const keys = Object.keys(map);
let changed = keys.length !== Object.keys(prev).length;
Eif (!changed) {
for (const k of keys) {
const prevSet = prev[k] ?? new Set<string>();
const newSet = map[k];
if (prevSet.size !== newSet.size) {
changed = true;
break;
}
for (const v of Array.from(newSet)) {
if (!prevSet.has(v)) {
changed = true;
break;
}
}
if (changed) break;
}
}
Eif (!changed) return prev;
return map;
});
}, [currentFavorites]);
const isFavorite = (c: CountryItemProps) => currentFavorites.some((f) => f.id === c.id);
const handleFavoritePress = (c: CountryItemProps) => {
favStore.setFavorite(c);
onToggleFavorite?.(c, !isFavorite(c));
};
// Toggle all group items for a parent country: select all if not all selected, otherwise remove all
const toggleAllGroupFavorites = (parentId: string | number, country: CountryItemProps) => {
const parentKey = String(parentId);
const groups = Array.isArray(country.groups) ? country.groups : [];
const items = groups.map((g, idx) => groupToListItem(g, parentId, idx));
const currentSet = favoriteGroupSelections[parentKey] ?? new Set<string>();
const selectedIds = new Set<string>(Array.from(currentSet));
items.forEach((it) => {
if (isFavorite(it)) selectedIds.add(String(it.id));
});
const anySelected = selectedIds.size > 0;
if (items.length === 0) return;
if (anySelected) {
// if any group is selected, clicking header star should remove all
setFavoriteGroupSelections((prev) => {
const copy: Record<string, Set<string>> = { ...prev };
copy[parentKey] = new Set<string>();
return copy;
});
// remove from global favorites only where currently favorite
items.forEach((it) => {
if (isFavorite(it)) {
handleFavoritePress(it);
}
});
} else {
// none selected -> select all
setFavoriteGroupSelections((prev) => {
const copy: Record<string, Set<string>> = { ...prev };
copy[parentKey] = new Set<string>(items.map((it) => String(it.id)));
return copy;
});
// add to global favorites only where not already favorite
items.forEach((it) => {
if (!isFavorite(it)) {
handleFavoritePress(it);
}
});
}
};
const [favoriteGroupSelections, setFavoriteGroupSelections] = useState<
Record<string, Set<string>>
>({});
const toggleGroupItemFavorite = (parentId: string | number, groupItem: CountryItemProps) => {
const p = String(parentId);
const gid = String(groupItem.id);
setFavoriteGroupSelections((prev) => {
const copy: Record<string, Set<string>> = { ...prev };
const setForParent = new Set<string>(copy[p] ? Array.from(copy[p]) : []);
if (setForParent.has(gid)) {
setForParent.delete(gid);
} else {
setForParent.add(gid);
}
copy[p] = setForParent;
return copy;
});
handleFavoritePress(groupItem);
const pid = String(parentId);
const remainingGroupFavs = favStore.leagues.filter((f) =>
String(f.id).startsWith(`${pid}-group-`)
);
const parentFavExists = favStore.leagues.some((f) => String(f.id) === pid);
if (remainingGroupFavs.length === 0 && parentFavExists) {
const parentObj =
highlights.find((h) => String(h.id) === pid) ||
categories.find((c) => String(c.id) === pid) ||
({ id: pid, name: '', iso: '', league: '' } as CountryItemProps);
handleFavoritePress(parentObj);
}
};
function allSportText() {
return (
<TouchableOpacity
onPress={() => (LongTimeBet ? handleOnAllLongTimeBet?.() : handleOnAllSportsPress?.())}
>
<Text className="text-accent text-[16px] font-normal underline">Alle Spiele</Text>
</TouchableOpacity>
);
}
const renderCountryRow = (c: CountryItemProps) => {
const active = isFavorite(c);
const isUEFA = c.iso === 'EU';
return (
<Pressable
key={c.id}
className="flex-row items-center justify-between px-[14px] py-2"
onPress={() => (LongTimeBet ? onLongTimeBet?.(c) : onSelectLeague?.(c))}
accessibilityLabel={`Selected ${c.name}`}
accessibilityHint="Opens the league details"
>
<View className="flex-1 flex-row items-center gap-2 pr-2">
{isUEFA ? (
<UEFA width={26} height={24} />
) : (
<CountryFlag countryCode={iso3ToIso2[c.iso]} size={24} className="" />
)}
<Text className="text-text-main flex-1 text-lg font-normal" numberOfLines={1}>
<Text className="font-Bold text-lg">{c.name}:</Text>{' '}
<Text className="font-normal">{String(c.league)}</Text>
</Text>
</View>
<Pressable
onPress={() => handleFavoritePress(c)}
accessibilityLabel={active ? 'Remove favorite' : 'Add favorite'}
accessibilityHint="Toggles the favorite status of this league"
hitSlop={8}
>
{active ? (
<View className="flex-1">
<StarFill
width={32}
height={30}
color={themeColors.colorAccent}
style={{
alignSelf: 'center',
justifyContent: 'center',
marginTop: Dimensions.get('window').width * 0.015,
}}
accessibilityLabel="Favorite Icon"
accessibilityHint="Indicates this league is a favorite"
/>
</View>
) : (
<Star
width={32}
height={34}
color={themeColors.colorIcon_Fill_Light}
accessibilityHint="Indicates this league is not a favorite"
accessibilityLabel="Not Favorite Icon"
/>
)}
</Pressable>
</Pressable>
);
};
function renderSectionBody(list: CountryItemProps[]) {
if (list.length === 0) {
return (
<View
accessibilityLabel="No leagues available"
style={{
backgroundColor: themeColors.colorTertiary_Background,
}}
>
<Text className="text-text-secondary px-[14px] py-4 text-lg font-normal">
Keine Ligen verfügbar.
</Text>
</View>
);
}
return (
<ListGroup
items={list}
variant="striped"
className={`p-0`}
stripedColors={{ even: 'bg-tertiary-background', odd: 'bg-primary' }}
itemTemplate={(item) => {
const country = item as CountryItemProps;
if (Array.isArray(country.groups) && country.groups.length > 0) {
return (
<Accordion
items={[
{
label: <CountryHeaderLabel country={country} />,
content: renderGroupList(country.groups, country.id),
className: '',
},
]}
headerClassName="bg-transparent border-0 px-[14px] m-0 py-0"
icon={''}
activeIcon={''}
flush
/>
);
}
return renderCountryRow(country);
}}
/>
);
}
if (loading) {
return (
<View className={cn('flex-1 items-center justify-center', className)}>
<ActivityIndicator testID="home-category-loading" color={themeColors.colorAccent} />
</View>
);
}
if (error) {
return (
<View
className={cn('flex-1 items-center justify-center px-4', className)}
accessibilityLabel="Error message"
>
<Text className="text-status-lost text-center text-sm">{error}</Text>
</View>
);
}
type GroupItem = string | { league?: string | string[] };
const groupToListItem = (g: GroupItem, parentId: string | number, idx: number) => {
const id = `${parentId}-group-${idx}`;
Eif (typeof g === 'string') {
return { id, name: g, iso: '', league: g } as CountryItemProps;
}
if (g && typeof g === 'object') {
const league = (g as { league?: string | string[] }).league ?? '';
return {
id,
name: typeof league === 'string' ? league : String(league),
iso: '',
league,
} as CountryItemProps;
}
return { id, name: String(g), iso: '', league: String(g) } as CountryItemProps;
};
const renderGroupList = (groups?: GroupItem[], parentId?: string | number) => {
Iif (!groups || groups.length === 0) return null;
let items = groups.map((g, idx) => groupToListItem(g, parentId ?? 'p', idx));
items = items.sort((a, b) => {
const aSelected =
isFavorite(a) ||
(favoriteGroupSelections[String(parentId ?? 'p')] ?? new Set()).has(String(a.id));
const bSelected =
isFavorite(b) ||
(favoriteGroupSelections[String(parentId ?? 'p')] ?? new Set()).has(String(b.id));
Iif (aSelected !== bSelected) return aSelected ? -1 : 1;
return String(a.name).localeCompare(String(b.name));
});
return (
<ListGroup
items={items}
variant="striped"
className="py-0"
stripedColors={{ odd: 'bg-tertiary-background', even: 'bg-primary' }}
itemTemplate={(item) => {
const country = item as CountryItemProps;
const parentKey = String(parentId ?? 'p');
const gid = String(country.id);
const selectedSet = favoriteGroupSelections[parentKey] ?? new Set<string>();
const isGroupSelected = selectedSet.has(gid) || isFavorite(country);
return (
<View className="flex flex-row justify-between py-1.5 pl-[8px] pr-1">
<Pressable
key={country.id}
className="flex-row items-center justify-between py-2"
onPress={() => onSelectLeague?.(country)}
>
<Text className="text-text-main font-normal">{country.name}</Text>
</Pressable>
<Pressable
onPress={() => toggleGroupItemFavorite(parentId ?? 'p', country)}
accessibilityLabel={isGroupSelected ? 'Remove favorite' : 'Add favorite'}
accessibilityHint="Toggles the favorite status of this group item"
hitSlop={8}
>
{isGroupSelected ? (
<StarFill width={32} height={30} color={themeColors.colorAccent} />
) : (
<Star width={32} height={34} color={themeColors.colorIcon_Fill_Light} />
)}
</Pressable>
</View>
);
}}
/>
);
};
const CountryHeaderLabel: React.FC<{ country: CountryItemProps }> = ({ country }) => {
const { isItemOpen, toggleItem } = useAccordion();
const isUEFA = country.iso === 'EU';
const open = isItemOpen('item-0');
const parentKey = String(country.id);
const groupSet = favoriteGroupSelections[parentKey] ?? new Set<string>();
const groupsCount = Array.isArray(country.groups) ? country.groups.length : 0;
let totalSelectedCount = 0;
let fullGroupsCount = groupsCount;
Eif (groupsCount > 0) {
const items = (country.groups ?? []).map((g, idx) => groupToListItem(g, country.id, idx));
const selectedIds = new Set<string>(Array.from(groupSet));
items.forEach((it) => {
Iif (isFavorite(it)) selectedIds.add(String(it.id));
});
const originalParent =
highlights.find((h) => String(h.id) === parentKey) ||
categories.find((c) => String(c.id) === parentKey);
Eif (originalParent && Array.isArray(originalParent.groups)) {
fullGroupsCount = originalParent.groups.length;
}
totalSelectedCount = selectedIds.size;
}
const hasGroups = fullGroupsCount > 0;
const active = hasGroups ? false : isFavorite(country);
return (
<View className="flex-row items-center justify-between py-2">
<View className="flex-1 flex-row items-center gap-2 pr-2">
{isUEFA ? (
<UEFA width={26} height={24} />
) : (
<CountryFlag countryCode={iso3ToIso2[country.iso]} size={24} />
)}
<View className="min-w-0 flex-row items-center gap-2">
<Pressable
onPress={() => (LongTimeBet ? onLongTimeBet?.(country) : onSelectLeague?.(country))}
accessibilityLabel={`Selected ${country.name}`}
>
<Text
className="font-Bold text-text-main min-w-0 shrink text-lg"
numberOfLines={1}
ellipsizeMode="tail"
>
{country.name}
</Text>
</Pressable>
<Pressable onPress={() => toggleItem('item-0')} accessibilityLabel="Toggle groups">
{open ? <ChrevonUp height={25} width={25} /> : <ChrevonDown height={25} width={25} />}
</Pressable>
</View>
</View>
<View className="mr-2">{allSportText()}</View>
<Pressable
onPress={() => {
if (Array.isArray(country.groups) && country.groups.length > 0) {
toggleAllGroupFavorites(country.id, country);
} else {
handleFavoritePress(country);
}
}}
accessibilityLabel={active ? 'Remove favorite' : 'Add favorite'}
accessibilityHint="Toggles the favorite status of this league"
hitSlop={8}
>
{(() => {
Eif (fullGroupsCount > 0) {
Iif (totalSelectedCount === fullGroupsCount) {
return <StarFill width={32} height={30} color={themeColors.colorAccent} />;
}
Iif (totalSelectedCount > 0) {
return <Star width={32} height={34} color={themeColors.colorAccent} />;
}
return <Star width={32} height={34} color={themeColors.colorIcon_Fill_Light} />;
}
// no groups: fall back to parent favorite state
return isFavorite(country) ? (
<StarFill width={32} height={30} color={themeColors.colorAccent} />
) : (
<Star width={32} height={34} color={themeColors.colorIcon_Fill_Light} />
);
})()}
</Pressable>
</View>
);
};
const tabs = [
{ label: 'LIGEN', body: null },
{ label: 'LANGZEITWETTEN', body: null },
];
const renderHighlights = (list: CountryItemProps[]) => (
<View className="mt-4" accessibilityLabel="Highlights section">
<View className="bg-primary flex-row items-center justify-between px-[14px] py-[14px]">
<Text className="text-text-main font-Bold text-[16px]">HIGHLIGHTS</Text>
{allSportText()}
</View>
{renderSectionBody(list)}
</View>
);
const renderCategories = (list: CountryItemProps[]) => (
<View className="mt-4" accessibilityLabel="Categories section">
<View className="bg-primary flex-row items-center justify-between px-[14px] py-[14px]">
<Text className="text-text-main font-Bold text-[16px]">KATEGORIEN</Text>
{allSportText()}
</View>
{renderSectionBody(list)}
</View>
);
const sportsIconMap: Record<string, JSX.Element> = {
Fußball: <Futsal />,
Basketball: <Basketball />,
Volleyball: <Volleyball />,
Tennis: <Tennis />,
Handball: <Handball />,
TableTennis: <TableTennis />,
IceHockey: <IceHockey />,
};
const renderSportsBar = () => {
return (
<View className={'flex h-[90px] flex-row'}>
{SHOW_ALLE_CLOCK && (
<View className={cn('relative items-stretch', showAllFilters && 'mr-3')}>
{showAllFilters && (
<View
pointerEvents="none"
className="bg-accent absolute bottom-[-8px] left-0 right-0 top-[-8px]"
/>
)}
<Pressable
onPress={() => {
if (activeMatchCategory !== undefined) {
setActiveMatchCategory(undefined);
setShowAllFilters(true);
} else {
setShowAllFilters((prev) => !prev);
}
}}
className={cn('items-center rounded-sm px-3 py-4')}
accessibilityLabel="Select all categories and toggle filters"
accessibilityHint="Shows all match categories and toggles the time filter options"
>
<Clock color={showAllFilters ? themeColors.colorPrimary : themeColors.colorAccent} />
<Text
className={cn(
'font-Bold pt-4 text-[14px]',
showAllFilters ? 'text-primary' : 'text-accent'
)}
>
{timeFilter === 'ALL' ? 'Alle' : timeFilter === '24H' ? '24 std.' : '3 std.'}
</Text>
{showAllFilters ? (
<ChrevonUp color={themeColors.colorPrimary} />
) : (
<ChrevonDown color={themeColors.colorAccent} />
)}
</Pressable>
</View>
)}
{SHOW_ALLE_CLOCK && !showAllFilters && (
<View className="border-text-main mb-[18px] mr-3 mt-[11px] border-r" />
)}
{!SHOW_ALLE_CLOCK && <View className="mx-1" />}
<ScrollView horizontal showsHorizontalScrollIndicator={false} className="p-0">
<View className="flex-row">
<View className="flex-row gap-x-4 pr-2">
{matchCategories.map((cat, idx) => {
const isSelected = activeMatchCategory !== undefined && activeMatchCategory === cat;
return (
<Pressable
key={idx}
onPress={() => {
const next = isSelected ? undefined : cat;
setShowAllFilters(false);
setActiveMatchCategory(next);
}}
className={cn('items-center py-4', isSelected && 'text-accent')}
accessibilityRole="button"
accessibilityLabel={`Select category ${cat}`}
accessibilityState={{ selected: isSelected }}
accessibilityHint={`${isSelected ? 'Deselects' : 'Selects'} this match category`}
>
{React.cloneElement(sportsIconMap[cat] ?? <Ball />, {
color: isSelected
? themeColors.colorAccent
: themeColors.colorIcon_Fill_Light,
})}
<Text
className={cn(
'mt-3 pt-1 text-[14px] font-normal',
isSelected ? 'text-accent font-Bold' : 'text-text-main'
)}
accessibilityHint="Indicates the sport category"
accessibilityState={{ selected: isSelected }}
>
{cat}
</Text>
</Pressable>
);
})}
</View>
</View>
</ScrollView>
</View>
);
};
const renderTimeFilters = () => {
if (!SHOW_ALLE_CLOCK || activeMatchCategory !== undefined) return null;
const buttons: { key: 'ALL' | '24H' | '3H'; label: string }[] = [
{ key: 'ALL', label: 'ALLE' },
{ key: '24H', label: '24 STUNDEN' },
{ key: '3H', label: '3 STUNDEN' },
];
return (
<>
{measuredTimeFiltersHeight === 0 && (
<View
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
opacity: 0,
zIndex: -1,
}}
onLayout={onTimeFiltersLayout}
>
<View className="bg-primary border-accent border-t px-4 py-4">
<View className="flex-row justify-between gap-4">
{buttons.map((btn) => (
<Button
key={btn.key}
className={cn('flex-1 rounded-md pb-2 pt-1.5')}
label={btn.label}
onPress={() => setTimeFilter(btn.key)}
variant={timeFilter === btn.key ? 'primary' : 'cyan'}
accessibilityLabel={`Select time filter ${btn.label}`}
/>
))}
</View>
</View>
</View>
)}
<AnimatedView style={timeFiltersAnimatedStyle}>
<View
className="bg-primary border-accent border-t px-4 py-4"
accessibilityLabel="Time range filters"
>
<View className="flex-row justify-between gap-4">
{buttons.map((btn) => (
<Button
key={btn.key}
className={cn('flex-1 rounded-md pb-2 pt-1.5')}
label={btn.label}
onPress={() => setTimeFilter(btn.key)}
variant={timeFilter === btn.key ? 'primary' : 'cyan'}
accessibilityLabel={`Select time filter ${btn.label}`}
/>
))}
</View>
</View>
</AnimatedView>
</>
);
};
const highlightsFiltered: CountryItemProps[] = highlights;
const categoriesFiltered: CountryItemProps[] = categories;
return (
<View className={'flex-1'}>
{renderSportsBar()}
<ScrollView
className={cn('flex-1', className)}
accessibilityLabel="Home Category"
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingBottom: 32 }}
>
{renderTimeFilters()}
<Tabs
id="home-category-tabs"
tabs={tabs}
activeTab={activeTab}
onTabChange={(i) => {
setActiveTab(i);
setShowAllFilters(false);
}}
variant="primary"
padding="none"
tabLabelStyle="uppercase text-lg"
/>
<View className="flex-1">
<View>
<Accordion
items={favoritesAccordionItems.map((it) => ({
label: it.label,
content: it.content,
className: 'bg-tertiary-background !p-0 ',
header: undefined,
footer: undefined,
}))}
variant="secondary"
defaultOpenIndex={0}
/>
</View>
{renderHighlights(highlightsFiltered)}
{renderCategories(categoriesFiltered)}
</View>
</ScrollView>
</View>
);
};
export default HomeCategory;
|