Spaces:
Build error
Build error
File size: 59,107 Bytes
0bfe2e3 |
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 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 |
'use client';
import React, { useState, useMemo, useEffect } from 'react';
import { PageWrapper } from '../shared/page-wrapper';
import { useStatus } from '@/context/status';
import { useUserData } from '@/context/userData';
import { SettingsCard } from '../shared/settings-card';
import { Button, IconButton } from '../ui/button';
import { Modal } from '../ui/modal';
import { Switch } from '../ui/switch';
import {
DndContext,
useSensor,
useSensors,
PointerSensor,
TouchSensor,
} from '@dnd-kit/core';
import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
import {
arrayMove,
SortableContext,
verticalListSortingStrategy,
useSortable,
} from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import { PlusIcon, SearchIcon, FilterIcon } from 'lucide-react';
import TemplateOption from '../shared/template-option';
import * as constants from '../../../../core/src/utils/constants';
import { TextInput } from '../ui/text-input';
import { Popover } from '../ui/popover';
import { BiEdit, BiTrash } from 'react-icons/bi';
import { Option, Resource } from '@aiostreams/core';
import { toast } from 'sonner';
import { Tooltip } from '../ui/tooltip';
import { StaticTabs } from '../ui/tabs';
import {
LuDownload,
LuGlobe,
LuChevronsUp,
LuChevronsDown,
LuShuffle,
} from 'react-icons/lu';
import { TbSmartHome, TbSmartHomeOff } from 'react-icons/tb';
import { AnimatePresence } from 'framer-motion';
import { PageControls } from '../shared/page-controls';
import Image from 'next/image';
import { Combobox } from '../ui/combobox';
import { FaPlus, FaRegTrashAlt } from 'react-icons/fa';
import { UserConfigAPI } from '../../services/api';
import {
ConfirmationDialog,
useConfirmationDialog,
} from '../shared/confirmation-dialog';
import { MdRefresh } from 'react-icons/md';
import { Alert } from '../ui/alert';
import MarkdownLite from '../shared/markdown-lite';
import {
Accordion,
AccordionTrigger,
AccordionContent,
AccordionItem,
} from '../ui/accordion';
import { FaArrowRightLong, FaRankingStar, FaShuffle } from 'react-icons/fa6';
import { PiStarFill, PiStarBold } from 'react-icons/pi';
import { IoExtensionPuzzle } from 'react-icons/io5';
import { NumberInput } from '../ui/number-input';
interface CatalogModification {
id: string;
type: string;
name?: string;
overrideType?: string;
enabled?: boolean;
shuffle?: boolean;
persistShuffleFor?: number;
rpdb?: boolean;
onlyOnDiscover?: boolean;
hideable?: boolean;
addonName?: string;
}
export function AddonsMenu() {
return (
<PageWrapper className="space-y-4 p-4 sm:p-8">
<Content />
</PageWrapper>
);
}
function Content() {
const { status } = useStatus();
const { userData, setUserData } = useUserData();
const [page, setPage] = useState<'installed' | 'marketplace'>('installed');
const [search, setSearch] = useState('');
// Filter states
const [serviceFilters, setServiceFilters] = useState<string[]>([]);
const [streamTypeFilters, setStreamTypeFilters] = useState<
constants.StreamType[]
>([]);
const [resourceFilters, setResourceFilters] = useState<string[]>([]);
// Modal states
const [modalOpen, setModalOpen] = useState(false);
const [modalMode, setModalMode] = useState<'add' | 'edit'>('add');
const [modalPreset, setModalPreset] = useState<any | null>(null);
const [modalInitialValues, setModalInitialValues] = useState<
Record<string, any>
>({});
const [editingAddonId, setEditingAddonId] = useState<string | null>(null);
const [isDragging, setIsDragging] = useState(false);
// Filtering and search for marketplace
const filteredPresets = useMemo(() => {
if (!status?.settings?.presets) return [];
return status.settings.presets.filter((preset) => {
if (preset.ID === 'custom') return true;
const matchesService =
serviceFilters.length === 0 ||
(preset.SUPPORTED_SERVICES &&
serviceFilters.every((s) => preset.SUPPORTED_SERVICES.includes(s)));
const matchesStreamType =
streamTypeFilters.length === 0 ||
(preset.SUPPORTED_STREAM_TYPES &&
streamTypeFilters.every((t) =>
preset.SUPPORTED_STREAM_TYPES.includes(t)
));
const matchesResource =
resourceFilters.length === 0 ||
(preset.SUPPORTED_RESOURCES &&
resourceFilters.every((r) =>
preset.SUPPORTED_RESOURCES.includes(r as Resource)
));
const matchesSearch =
!search ||
preset.NAME.toLowerCase().includes(search.toLowerCase()) ||
preset.DESCRIPTION.toLowerCase().includes(search.toLowerCase());
return (
matchesService && matchesStreamType && matchesResource && matchesSearch
);
});
}, [status, search, serviceFilters, streamTypeFilters, resourceFilters]);
// My Addons (user's enabled/added presets)
// AddonModal handlers
function handleAddPreset(preset: any) {
setModalPreset(preset);
setModalInitialValues({
options: Object.fromEntries(
(preset.OPTIONS || []).map((opt: any) => [
opt.id,
opt.default ?? undefined,
])
),
});
setModalMode('add');
setEditingAddonId(null);
setModalOpen(true);
}
function getUniqueId() {
// generate a 3 character long hex string, ensuring it doesn't already exist in the user's presets
const id = Math.floor(Math.random() * 0xfff)
.toString(16)
.padStart(3, '0');
if (userData.presets.some((a) => a.instanceId === id)) {
return getUniqueId();
}
return id;
}
function handleModalSubmit(values: Record<string, any>) {
if (modalMode === 'add' && modalPreset) {
// Always add a new preset with default values, never edit
const newPreset = {
type: modalPreset.ID,
instanceId: getUniqueId(),
enabled: true,
options: values.options,
};
const newKey = getPresetUniqueKey(newPreset);
// Prevent adding if a preset with the same unique key already exists
// dont use instanceId here, as that will always be unique
// only prevent adding the same preset type with the same options
// so we use getPresetUniqueKey here.
if (userData.presets.some((a) => getPresetUniqueKey(a) === newKey)) {
toast.error('You already have an addon with the same options added.');
setModalOpen(false);
return;
}
setUserData((prev) => ({
...prev,
presets: [...prev.presets, newPreset],
}));
toast.info('Addon installed successfully!');
setModalOpen(false);
} else if (modalMode === 'edit' && editingAddonId) {
// Edit existing preset (should not be triggered from marketplace)
setUserData((prev) => ({
...prev,
presets: prev.presets.map((a) =>
a.instanceId === editingAddonId
? { ...a, options: values.options }
: a
),
}));
toast.info('Addon updated successfully!');
setModalOpen(false);
}
}
// DND for My Addons
function handleDragEnd(event: any) {
const { active, over } = event;
if (!over) return;
if (active.id !== over.id) {
const oldIndex = userData.presets.findIndex(
(a) => a.instanceId === active.id
);
const newIndex = userData.presets.findIndex(
(a) => a.instanceId === over.id
);
const newPresets = arrayMove(userData.presets, oldIndex, newIndex);
setUserData((prev) => ({
...prev,
presets: newPresets,
}));
}
setIsDragging(false);
}
function handleDragStart(event: any) {
setIsDragging(true);
}
// Service, stream type, and resource options
const serviceOptions = Object.values(constants.SERVICE_DETAILS).map(
(service) => ({ label: service.name, value: service.id })
);
const streamTypeOptions = (constants.STREAM_TYPES || [])
.filter((type) => type !== 'error')
.map((type: string) => ({ label: type, value: type }));
const resourceOptions = (constants.RESOURCES || []).map((res: string) => ({
label: res,
value: res,
}));
const activeFilterCount =
serviceFilters.length + streamTypeFilters.length + resourceFilters.length;
// DND-kit setup
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(TouchSensor, {
activationConstraint: {
delay: 150,
tolerance: 8,
},
})
);
useEffect(() => {
function preventTouchMove(e: TouchEvent) {
if (isDragging) {
e.preventDefault();
}
}
function handleDragEnd() {
setIsDragging(false);
}
if (isDragging) {
document.body.addEventListener('touchmove', preventTouchMove, {
passive: false,
});
// Add listeners for when drag ends outside context
document.addEventListener('pointerup', handleDragEnd);
document.addEventListener('touchend', handleDragEnd);
} else {
document.body.removeEventListener('touchmove', preventTouchMove);
}
return () => {
document.body.removeEventListener('touchmove', preventTouchMove);
document.removeEventListener('pointerup', handleDragEnd);
document.removeEventListener('touchend', handleDragEnd);
};
}, [isDragging]);
return (
<>
{/* <div className="flex items-center w-full">
<div>
<h2>Addons</h2>
<p className="text-[--muted]">Manage your installed addons or</p>
</div>
<div className="flex flex-1"></div>
</div> */}
<div className="flex items-center justify-between">
<StaticTabs
className="h-10 w-fit border rounded-full"
triggerClass="px-4 py-1 text-md"
items={[
{
name: 'Installed',
isCurrent: page === 'installed',
onClick: () => setPage('installed'),
iconType: LuDownload,
},
{
name: 'Marketplace',
isCurrent: page === 'marketplace',
onClick: () => setPage('marketplace'),
iconType: LuGlobe,
},
]}
/>
<div className="hidden lg:block lg:ml-auto">
<PageControls />
</div>
</div>
<AnimatePresence mode="wait">
{page === 'installed' && (
<PageWrapper
{...{
initial: { opacity: 0, y: 60 },
animate: { opacity: 1, y: 0 },
exit: { opacity: 0, scale: 0.99 },
transition: {
duration: 0.35,
},
}}
key="installed"
className="pt-0 space-y-8 relative z-[4]"
>
<div>
<h2>Installed Addons</h2>
<p className="text-[--muted] text-sm">
Manage your installed addons.
</p>
</div>
<SettingsCard
title="My Addons"
description="Edit, remove, and reorder your installed addons. If you reorder your addons, you will have to refresh the catalogs if you have made any changes, and also reinstall the addon."
>
<DndContext
modifiers={[restrictToVerticalAxis]}
onDragEnd={handleDragEnd}
onDragStart={handleDragStart}
sensors={sensors}
>
<SortableContext
items={userData.presets.map((a) => a.instanceId)}
strategy={verticalListSortingStrategy}
>
<div className="space-y-2">
<ul className="space-y-2">
{userData.presets.length === 0 ? (
<li>
<div className="flex flex-col items-center justify-center py-12">
<span className="text-lg text-muted-foreground font-semibold text-center">
Looks like you don't have any addons...
<br />
Add some from the marketplace!
</span>
</div>
</li>
) : (
userData.presets.map((preset) => {
const presetMetadata = status?.settings?.presets.find(
(p: any) => p.ID === preset.type
);
return (
<SortableAddonItem
key={getPresetUniqueKey(preset)}
preset={preset}
presetMetadata={presetMetadata}
onEdit={() => {
setModalPreset(presetMetadata);
setModalInitialValues({
options: { ...preset.options },
});
setModalMode('edit');
setEditingAddonId(preset.instanceId);
setModalOpen(true);
}}
onRemove={() => {
setUserData((prev) => ({
...prev,
presets: prev.presets.filter(
(a) => a.instanceId !== preset.instanceId
),
}));
}}
onToggleEnabled={(v: boolean) => {
setUserData((prev) => ({
...prev,
presets: prev.presets.map((p) =>
p.instanceId === preset.instanceId
? { ...p, enabled: v }
: p
),
}));
}}
/>
);
})
)}
</ul>
</div>
</SortableContext>
</DndContext>
</SettingsCard>
{userData.presets.length > 0 && <CatalogSettingsCard />}
{userData.presets.length > 0 && <AddonGroupCard />}
</PageWrapper>
)}
{page === 'marketplace' && (
<PageWrapper
{...{
initial: { opacity: 0, y: 60 },
animate: { opacity: 1, y: 0 },
exit: { opacity: 0, scale: 0.99 },
transition: {
duration: 0.35,
},
}}
key="marketplace"
className="pt-0 space-y-8 relative z-[4]"
>
<div>
<h2>Marketplace</h2>
<p className="text-[--muted] text-sm">
Browse and install addons from the marketplace.
</p>
</div>
<div className="bg-[--card] border border-[--border] rounded-xl p-4 mb-6 shadow-sm">
<div className="flex justify-center mb-4">
<div className="w-full sm:w-[500px] flex gap-2">
<TextInput
value={search}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearch(e.target.value)
}
placeholder="Search addons..."
className="flex-1"
leftIcon={<SearchIcon className="w-4 h-4" />}
/>
<AddonFilterPopover
serviceOptions={serviceOptions}
streamTypeOptions={streamTypeOptions}
resourceOptions={resourceOptions}
serviceFilters={serviceFilters}
setServiceFilters={setServiceFilters}
streamTypeFilters={streamTypeFilters}
setStreamTypeFilters={setStreamTypeFilters}
resourceFilters={resourceFilters}
setResourceFilters={setResourceFilters}
>
<IconButton
icon={<FilterIcon className="w-5 h-5" />}
intent={
activeFilterCount > 0 ? 'primary' : 'primary-outline'
}
aria-label="Filters"
/>
</AddonFilterPopover>
</div>
</div>
{/* Scrollable Addon Cards Grid */}
<div className="h-[calc(100vh-300px)] overflow-y-auto pr-1">
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
{filteredPresets.map((preset: any) => {
// Always allow adding, never show edit
return (
<AddonCard
key={preset.ID}
preset={preset}
isAdded={false}
onAdd={() => handleAddPreset(preset)}
/>
);
})}
</div>
</div>
</div>
</PageWrapper>
)}
{/* Add/Edit Addon Modal (ensure both tabs can use it)*/}
<AddonModal
open={modalOpen}
onOpenChange={setModalOpen}
mode={modalMode}
presetMetadata={modalPreset}
initialValues={modalInitialValues as any}
onSubmit={handleModalSubmit}
/>
</AnimatePresence>
</>
);
}
// Helper to generate a key based on an addons id and options
function getPresetUniqueKey(preset: {
type: string;
instanceId: string;
enabled: boolean;
options: Record<string, any>;
}) {
// dont include the unique instanceId
return JSON.stringify({
type: preset.type,
enabled: preset.enabled,
options: preset.options,
});
}
// Sortable Addon Item for DND (handles both preset and custom addon)
function SortableAddonItem({
preset,
presetMetadata,
onEdit,
onRemove,
onToggleEnabled,
}: {
preset: any;
presetMetadata: any;
onEdit: () => void;
onRemove: () => void;
onToggleEnabled: (v: boolean) => void;
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({
id: preset.instanceId,
});
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.5 : 1,
};
return (
<li ref={setNodeRef} style={style}>
<div className="px-2.5 py-2 bg-[var(--background)] rounded-[--radius-md] border flex gap-2 sm:gap-3 relative">
<div
className="rounded-full w-6 h-auto bg-[--muted] md:bg-[--subtle] md:hover:bg-[--subtle-highlight] cursor-move flex-shrink-0"
{...attributes}
{...listeners}
/>
<div className="flex items-center gap-2 sm:gap-3 flex-1 min-w-0">
<div className="relative flex-shrink-0 h-8 w-8 hidden sm:block">
{presetMetadata.ID === 'custom' ? (
<PlusIcon className="w-full h-full object-contain" />
) : (
<Image
src={presetMetadata.LOGO}
alt={presetMetadata.NAME}
fill
className="w-full h-full object-contain rounded-md"
/>
)}
</div>
<p className="text-base line-clamp-1 truncate block">
{preset.options.name}
</p>
</div>
<div className="flex items-center gap-1 sm:gap-2">
<Switch
value={!!preset.enabled}
onValueChange={onToggleEnabled}
size="sm"
/>
<IconButton
className="rounded-full h-8 w-8 md:h-10 md:w-10"
icon={<BiEdit />}
intent="primary-subtle"
onClick={onEdit}
/>
<IconButton
className="rounded-full h-8 w-8 md:h-10 md:w-10"
icon={<BiTrash />}
intent="alert-subtle"
onClick={onRemove}
/>
</div>
</div>
</li>
);
}
// AddonCard component
function AddonCard({
preset,
isAdded,
onAdd,
}: {
preset: any;
isAdded: boolean;
onAdd: () => void;
}) {
return (
<div className="flex flex-col min-h-72 h-auto bg-[--background] border border-[--border] rounded-lg shadow-sm p-4 relative">
{/* Top: Logo + Name/Description */}
<div className="flex gap-4 items-start">
{preset.ID === 'custom' ? (
<div className="w-28 h-28 min-w-[7rem] min-h-[7rem] flex items-center justify-center rounded-lg bg-gray-900 text-[--brand] text-4xl">
<PlusIcon className="w-12 h-12" />
</div>
) : preset.LOGO ? (
<img
src={preset.LOGO}
alt={preset.NAME}
className="w-28 h-28 min-w-[7rem] min-h-[7rem] object-contain rounded-lg bg-gray-800"
/>
) : (
<div className="w-28 h-28 min-w-[7rem] min-h-[7rem] flex items-center justify-center rounded-lg bg-gray-900 text-[--brand] text-4xl">
<IoExtensionPuzzle className="w-15 h-15" />
</div>
)}
<div className="flex flex-col min-w-0 flex-1">
<div className="font-bold text-lg mb-1 truncate">{preset.NAME}</div>
<div className="text-sm text-muted-foreground mb-2 line-clamp-3 whitespace-pre-line">
<MarkdownLite>{preset.DESCRIPTION}</MarkdownLite>
</div>
</div>
</div>
{/* Tags Section */}
<div className="flex flex-col gap-1 mt-2">
<div className="flex flex-wrap gap-1 items-center min-h-[1.5rem]">
{preset.SUPPORTED_SERVICES?.length > 0 && (
<span className="font-semibold text-xs text-[--muted] mr-1">
Services:
</span>
)}
{preset.SUPPORTED_SERVICES?.map((sid: string) => {
const service =
constants.SERVICE_DETAILS[
sid as keyof typeof constants.SERVICE_DETAILS
];
return (
<Tooltip
key={sid}
side="top"
trigger={
<span className="bg-gray-800 text-xs px-2 py-0.5 rounded text-[--brand] font-mono">
{service?.shortName || sid}
</span>
}
>
<span className="bg-gray-800 text-xs px-2 py-0.5 rounded text-[--brand] font-mono">
{service?.name || sid}
</span>
</Tooltip>
);
})}
</div>
<div className="flex flex-wrap gap-1 items-center min-h-[1.5rem]">
{preset.SUPPORTED_RESOURCES?.length > 0 && (
<span className="font-semibold text-xs text-[--muted] mr-1">
Resources:
</span>
)}
{preset.SUPPORTED_RESOURCES?.map((res: string) => (
<span
key={res}
className="bg-gray-800 text-xs px-2 py-0.5 rounded text-blue-400 font-mono"
>
{res}
</span>
))}
</div>
<div className="flex flex-wrap gap-1 items-center min-h-[1.5rem]">
{preset.SUPPORTED_STREAM_TYPES?.length > 0 && (
<span className="font-semibold text-xs text-[--muted] mr-1">
Stream Types:
</span>
)}
{preset.SUPPORTED_STREAM_TYPES?.map((type: string) => (
<span
key={type}
className="bg-gray-800 text-xs px-2 py-0.5 rounded text-green-400 font-mono"
>
{type}
</span>
))}
</div>
</div>
{preset.DISABLED ? (
<div className="mt-auto pt-3 flex items-end">
<Alert
intent="alert"
className="w-full overflow-x-auto whitespace-nowrap"
description={<MarkdownLite>{preset.DISABLED.reason}</MarkdownLite>}
/>
</div>
) : (
<div className="mt-auto pt-3 flex items-end">
<Button size="md" className="w-full" onClick={onAdd}>
Configure
</Button>
</div>
)}
</div>
);
}
function AddonModal({
open,
onOpenChange,
mode,
presetMetadata,
initialValues = {},
onSubmit,
}: {
open: boolean;
onOpenChange: (v: boolean) => void;
mode: 'add' | 'edit';
presetMetadata?: any;
initialValues?: Record<string, any>;
onSubmit: (values: Record<string, any>) => void;
}) {
const [values, setValues] = useState<Record<string, any>>(initialValues);
useEffect(() => {
if (open) {
setValues(initialValues);
} else {
// when closing, delay the reset to allow the animation to finish
// so that the user doesn't see the values being reset
setTimeout(() => {
setValues(initialValues);
}, 150);
}
}, [open, initialValues]);
const dynamicOptions: Option[] = presetMetadata?.OPTIONS || [];
// Check if all required fields are filled
const allRequiredFilled = dynamicOptions.every((opt: any) => {
if (!opt.required) return true;
const val = values.options?.[opt.id];
// For booleans, false is valid; for others, check for empty string/null/undefined
if (opt.type === 'boolean') return typeof val === 'boolean';
return val !== undefined && val !== null && val !== '';
});
function handleFormSubmit(e: React.FormEvent) {
e.preventDefault();
for (const opt of dynamicOptions) {
if (opt.constraints) {
const val = values.options?.[opt.id];
if (typeof val === 'string') {
if (opt.constraints.min && val.length < opt.constraints.min) {
toast.error(
`${opt.name} must be at least ${opt.constraints.min} characters`
);
return false;
}
if (opt.constraints.max && val.length > opt.constraints.max) {
toast.error(
`${opt.name} must be at most ${opt.constraints.max} characters`
);
return false;
}
} else if (typeof val === 'number') {
if (opt.constraints.min && val < opt.constraints.min) {
toast.error(`${opt.name} must be at least ${opt.constraints.min}`);
return false;
}
if (opt.constraints.max && val > opt.constraints.max) {
toast.error(`${opt.name} must be at most ${opt.constraints.max}`);
return false;
}
}
}
}
if (allRequiredFilled) {
onSubmit(values);
} else {
toast.error('Please fill in all required fields');
}
}
return (
<Modal
open={open}
onOpenChange={onOpenChange}
title={
mode === 'add'
? `Install ${presetMetadata?.NAME}`
: `Edit ${presetMetadata?.NAME}`
}
>
<form className="space-y-4" onSubmit={handleFormSubmit}>
{dynamicOptions.map((opt: any) => (
<div key={opt.id} className="mb-2">
<TemplateOption
option={opt}
value={values.options?.[opt.id]}
onChange={(v: any) =>
setValues((val) => ({
...val,
options: { ...val.options, [opt.id]: v },
}))
}
disabled={false}
/>
</div>
))}
<Button
className="w-full mt-2"
type="submit"
disabled={!allRequiredFilled}
>
{mode === 'add' ? 'Install' : 'Update'}
</Button>
</form>
</Modal>
);
}
function AddonFilterPopover({
serviceOptions,
streamTypeOptions,
resourceOptions,
serviceFilters,
setServiceFilters,
streamTypeFilters,
setStreamTypeFilters,
resourceFilters,
setResourceFilters,
children,
}: any) {
const [open, setOpen] = useState(false);
return (
<Popover
open={open}
onOpenChange={setOpen}
trigger={children}
modal={false}
className="p-4 max-w-full w-full"
>
<div className="flex flex-col gap-3">
<div className="grid grid-cols-2 sm:grid-cols-3 gap-4">
<div className="flex flex-col max-h-60 overflow-y-auto">
<div className="mb-2 font-semibold text-sm text-muted-foreground">
Services
</div>
{serviceOptions.map((opt: any) => (
<div
key={opt.value}
className="flex items-center gap-2 mb-2 last:mb-0"
>
<Switch
value={serviceFilters.includes(opt.value)}
onValueChange={(checked: boolean) => {
setServiceFilters((prev: string[]) =>
checked
? [...prev, opt.value]
: prev.filter((v) => v !== opt.value)
);
}}
size="sm"
/>
<span className="text-xs">{opt.label}</span>
</div>
))}
</div>
<div className="flex flex-col max-h-60 overflow-y-auto">
<div className="mb-2 font-semibold text-sm text-muted-foreground">
Stream Types
</div>
{streamTypeOptions.map((opt: any) => (
<div
key={opt.value}
className="flex items-center gap-2 mb-2 last:mb-0"
>
<Switch
value={streamTypeFilters.includes(opt.value)}
onValueChange={(checked: boolean) => {
setStreamTypeFilters((prev: string[]) =>
checked
? [...prev, opt.value]
: prev.filter((v) => v !== opt.value)
);
}}
size="sm"
/>
<span className="text-xs">{opt.label}</span>
</div>
))}
</div>
<div className="flex flex-col max-h-60 overflow-y-auto">
<div className="mb-2 font-semibold text-sm text-muted-foreground">
Resources
</div>
{resourceOptions.map((opt: any) => (
<div
key={opt.value}
className="flex items-center gap-2 mb-2 last:mb-0"
>
<Switch
value={resourceFilters.includes(opt.value)}
onValueChange={(checked: boolean) => {
setResourceFilters((prev: string[]) =>
checked
? [...prev, opt.value]
: prev.filter((v) => v !== opt.value)
);
}}
size="sm"
/>
<span className="text-xs">{opt.label}</span>
</div>
))}
</div>
</div>
<Button className="w-full mt-2" onClick={() => setOpen(false)}>
Done
</Button>
</div>
</Popover>
);
}
function AddonGroupCard() {
const { userData, setUserData } = useUserData();
// Helper function to get presets that are not in any group except the current one
const getAvailablePresets = (currentGroupIndex: number) => {
const presetsInOtherGroups = new Set(
userData.groups?.flatMap((group, idx) =>
idx !== currentGroupIndex ? group.addons : []
) || []
);
return userData.presets
.filter((preset) => {
return !presetsInOtherGroups.has(preset.instanceId);
})
.map((preset) => ({
label: preset.options.name,
value: preset.instanceId,
textValue: preset.options.name,
}));
};
const updateGroup = (
index: number,
updates: Partial<{ addons: string[]; condition: string }>
) => {
setUserData((prev) => {
// Initialize groups array if it doesn't exist
const currentGroups = prev.groups || [];
// Create a new array with all existing groups
const newGroups = [...currentGroups];
// Update the specific group with new values, preserving other fields
newGroups[index] = {
...newGroups[index],
...updates,
};
if (index === 0) {
// set condition for first group to true
newGroups[index].condition = 'true';
}
return {
...prev,
groups: newGroups,
};
});
};
return (
<SettingsCard
title="Groups"
// description="Optionally assign your addons to groups. Streams are only fetched from your first group initially,
// and only if a certain condition is met, will streams be fetched from the next group, and so on. Leaving this blank will mean streams are
// fetched from all addons. For a guide and a reference to the group system,"
>
<div className="text-sm text-[--muted] mb-2">
Optionally assign your addons to groups. Streams are only fetched from
your first group initially, and only if a certain condition is met, will
streams be fetched from the next group, and so on. Leaving this blank
will mean streams are fetched from all addons. Check the{' '}
<a
href="https://github.com/Viren070/AIOStreams/wiki/Groups"
target="_blank"
rel="noopener noreferrer"
className="text-[--brand] hover:text-[--brand]/80 hover:underline"
>
wiki
</a>
for a detailed guide to using groups.
</div>
{(userData.groups || []).map((group, index) => (
<div key={index} className="flex gap-2">
<div className="flex-1 flex gap-2">
<div className="flex-1">
<Combobox
multiple
value={group.addons}
options={getAvailablePresets(index)}
emptyMessage="You haven't installed any addons yet or they are already in a group"
label="Addons"
placeholder="Select addons"
onValueChange={(value) => {
updateGroup(index, { addons: value });
}}
/>
</div>
<div className="flex-1">
<TextInput
value={index === 0 ? 'true' : group.condition}
disabled={index === 0}
label="Condition"
placeholder="Enter condition"
onValueChange={(value) => {
updateGroup(index, { condition: value });
}}
/>
</div>
</div>
<IconButton
size="sm"
rounded
icon={<FaRegTrashAlt />}
intent="alert-subtle"
onClick={() => {
setUserData((prev) => {
const newGroups = [...(prev.groups || [])];
newGroups.splice(index, 1);
return {
...prev,
groups: newGroups,
};
});
}}
/>
</div>
))}
<div className="mt-2 flex gap-2 items-center">
<IconButton
rounded
size="sm"
intent="primary-subtle"
icon={<FaPlus />}
onClick={() => {
setUserData((prev) => {
const currentGroups = prev.groups || [];
return {
...prev,
groups: [...currentGroups, { addons: [], condition: '' }],
};
});
}}
/>
</div>
</SettingsCard>
);
}
function CatalogSettingsCard() {
const { userData, setUserData } = useUserData();
const [loading, setLoading] = useState(false);
const fetchCatalogs = async () => {
setLoading(true);
try {
const response = await UserConfigAPI.getCatalogs(userData);
if (response.success && response.data) {
setUserData((prev) => {
const existingMods = prev.catalogModifications || [];
const existingIds = new Set(
existingMods.map((mod) => `${mod.id}-${mod.type}`)
);
// first we need to handle existing modifications, to ensure that they keep their order
const modifications = existingMods.map((eMod) => {
const nMod = response.data!.find(
(c) => c.id === eMod.id && c.type === eMod.type
);
if (nMod) {
return {
// keep all the existing attributes, except addonName, type, hideable
...eMod,
addonName: nMod.addonName,
type: nMod.type,
hideable: nMod.hideable,
};
}
return eMod;
});
// Add new catalogs at the bottom
response.data!.forEach((catalog) => {
if (!existingIds.has(`${catalog.id}-${catalog.type}`)) {
modifications.push({
id: catalog.id,
name: catalog.name,
type: catalog.type,
enabled: true,
shuffle: false,
rpdb: userData.rpdbApiKey ? true : false,
hideable: catalog.hideable,
addonName: catalog.addonName,
});
}
});
// Filter out modifications for catalogs that no longer exist
const newCatalogIds = new Set(
response.data!.map((c) => `${c.id}-${c.type}`)
);
const filteredMods = modifications.filter((mod) =>
newCatalogIds.has(`${mod.id}-${mod.type}`)
);
return {
...prev,
catalogModifications: filteredMods,
};
});
toast.success('Catalogs fetched successfully');
} else {
toast.error(response.error?.message || 'Failed to fetch catalogs');
}
} catch (error) {
toast.error('Failed to fetch catalogs');
} finally {
setLoading(false);
}
};
const capitalise = (str: string | undefined) => {
if (!str) return '';
return str.charAt(0).toUpperCase() + str.slice(1);
};
// DND handlers
const sensors = useSensors(
useSensor(PointerSensor),
useSensor(TouchSensor, {
activationConstraint: {
delay: 150,
tolerance: 8,
},
})
);
const [isDragging, setIsDragging] = useState(false);
useEffect(() => {
function preventTouchMove(e: TouchEvent) {
if (isDragging) {
e.preventDefault();
}
}
function handleDragEnd() {
setIsDragging(false);
}
if (isDragging) {
document.body.addEventListener('touchmove', preventTouchMove, {
passive: false,
});
document.addEventListener('pointerup', handleDragEnd);
document.addEventListener('touchend', handleDragEnd);
} else {
document.body.removeEventListener('touchmove', preventTouchMove);
}
return () => {
document.body.removeEventListener('touchmove', preventTouchMove);
document.removeEventListener('pointerup', handleDragEnd);
document.removeEventListener('touchend', handleDragEnd);
};
}, [isDragging]);
const handleDragEnd = (event: any) => {
const { active, over } = event;
if (!over) return;
if (active.id !== over.id) {
setUserData((prev) => {
const oldIndex = prev.catalogModifications?.findIndex(
(c) => `${c.id}-${c.type}` === active.id
);
const newIndex = prev.catalogModifications?.findIndex(
(c) => `${c.id}-${c.type}` === over.id
);
if (
oldIndex === undefined ||
newIndex === undefined ||
!prev.catalogModifications
)
return prev;
return {
...prev,
catalogModifications: arrayMove(
prev.catalogModifications,
oldIndex,
newIndex
),
};
});
}
setIsDragging(false);
};
const handleDragStart = () => {
setIsDragging(true);
};
const confirmRefreshCatalogs = useConfirmationDialog({
title: 'Refresh Catalogs',
description:
'Are you sure you want to refresh the catalogs? This will remove any catalogs that are no longer available',
onConfirm: () => {
fetchCatalogs();
},
});
return (
<div className="rounded-[--radius] border bg-[--paper] shadow-sm p-4">
<div className="flex items-center justify-between mb-4">
<div>
<h3 className="font-semibold text-xl text-[--muted] transition-colors hover:text-[--brand]">
Catalogs
</h3>
<p className="text-[--muted] text-sm">
Rename, Reorder, and toggle your catalogs, and apply modifications
like RPDB posters and shuffling. If you reorder the addons, you need
to reinstall the addon
</p>
</div>
<IconButton
size="sm"
intent="warning-subtle"
icon={<MdRefresh />}
rounded
onClick={() => {
if (userData.catalogModifications?.length) {
confirmRefreshCatalogs.open();
} else {
fetchCatalogs();
}
}}
loading={loading}
/>
</div>
{!userData.catalogModifications?.length && (
<p className="text-[--muted] text-base text-center my-8">
Your addons don't have any catalogs... or you haven't fetched them yet
:/
</p>
)}
{userData.catalogModifications &&
userData.catalogModifications.length > 0 && (
<DndContext
modifiers={[restrictToVerticalAxis]}
onDragEnd={handleDragEnd}
onDragStart={handleDragStart}
sensors={sensors}
>
<SortableContext
items={(userData.catalogModifications || []).map(
(c) => `${c.id}-${c.type}`
)}
strategy={verticalListSortingStrategy}
>
<ul className="space-y-2">
{(userData.catalogModifications || []).map(
(catalog: CatalogModification) => (
<SortableCatalogItem
key={`${catalog.id}-${catalog.type}`}
catalog={catalog}
onToggleEnabled={(enabled) => {
setUserData((prev) => ({
...prev,
catalogModifications: prev.catalogModifications?.map(
(c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, enabled }
: c
),
}));
}}
capitalise={capitalise}
/>
)
)}
</ul>
</SortableContext>
</DndContext>
)}
<ConfirmationDialog {...confirmRefreshCatalogs} />
</div>
);
}
// Add the SortableCatalogItem component
function SortableCatalogItem({
catalog,
onToggleEnabled,
capitalise,
}: {
catalog: CatalogModification;
onToggleEnabled: (enabled: boolean) => void;
capitalise: (str: string | undefined) => string;
}) {
const {
attributes,
listeners,
setNodeRef,
transform,
transition,
isDragging,
} = useSortable({
id: `${catalog.id}-${catalog.type}`,
});
const { setUserData } = useUserData();
const style = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.5 : 1,
};
const moveToTop = () => {
setUserData((prev) => {
if (!prev.catalogModifications) return prev;
const index = prev.catalogModifications.findIndex(
(c) => c.id === catalog.id && c.type === catalog.type
);
if (index <= 0) return prev;
const newMods = [...prev.catalogModifications];
const [item] = newMods.splice(index, 1);
newMods.unshift(item);
return { ...prev, catalogModifications: newMods };
});
};
const moveToBottom = () => {
setUserData((prev) => {
if (!prev.catalogModifications) return prev;
const index = prev.catalogModifications.findIndex(
(c) => c.id === catalog.id && c.type === catalog.type
);
if (index === prev.catalogModifications.length - 1) return prev;
const newMods = [...prev.catalogModifications];
const [item] = newMods.splice(index, 1);
newMods.push(item);
return { ...prev, catalogModifications: newMods };
});
};
const [modalOpen, setModalOpen] = useState(false);
const [newName, setNewName] = useState(catalog.name || '');
const [newType, setNewType] = useState(
catalog.overrideType || catalog.type || ''
);
const dynamicIconSize = `text-xl h-8 w-8 lg:text-2xl lg:h-10 lg:w-10`;
const handleNameAndTypeEdit = () => {
setUserData((prev) => ({
...prev,
catalogModifications: prev.catalogModifications?.map((c) =>
c.id === catalog.id && c.type === catalog.type
? {
...c,
name: newName,
overrideType: newType,
}
: c
),
}));
setModalOpen(false);
};
return (
<li ref={setNodeRef} style={style}>
<div className="relative px-2.5 py-2 bg-[var(--background)] rounded-[--radius-md] border overflow-hidden">
{/* Full-height drag handle - rounded vertical oval with spacing */}
<div
className="absolute top-2 bottom-2 left-2 w-5 bg-[var(--muted)] md:bg-[var(--subtle)] md:hover:bg-[var(--subtle-highlight)] cursor-move flex-shrink-0 rounded-full"
{...attributes}
{...listeners}
/>
{/* Content wrapper */}
<div className="pl-8 pr-3 py-3">
{/* Header section */}
<div className="mb-4 md:mb-6 md:pr-40">
<div className="flex items-center gap-2 mb-1">
<h3 className="text-sm md:text-base font-medium line-clamp-1 truncate text-ellipsis">
{catalog.addonName} - {catalog.name ?? catalog.id}
</h3>
<IconButton
className="rounded-full h-5 w-5 md:h-6 md:w-6 flex-shrink-0"
icon={<BiEdit />}
intent="primary-subtle"
onClick={() => setModalOpen(true)}
/>
</div>
<p className="text-xs md:text-sm text-[var(--muted-foreground)] capitalize mb-2 md:mb-0">
{catalog.overrideType !== undefined &&
catalog.overrideType !== catalog.type
? `${catalog.overrideType} (${catalog.type})`
: catalog.type}
</p>
{/* Mobile Controls Row - only visible on small screens */}
<div className="flex md:hidden items-center justify-between">
{/* Position controls - aligned left */}
<div className="flex items-center gap-1">
<IconButton
rounded
className={dynamicIconSize}
icon={<LuChevronsUp />}
intent="primary-subtle"
onClick={moveToTop}
title="Move to top"
/>
<IconButton
rounded
className={dynamicIconSize}
icon={<LuChevronsDown />}
intent="primary-subtle"
onClick={moveToBottom}
title="Move to bottom"
/>
</div>
{/* Enable/disable toggle - aligned right */}
<Switch
value={catalog.enabled ?? true}
onValueChange={onToggleEnabled}
moreHelp="Enable or disable this catalog from being used"
/>
</div>
{/* Desktop Controls - only visible on medium screens and up */}
<div className="hidden md:flex items-center justify-end gap-2 absolute top-4 right-4">
<div className="flex items-center gap-1">
<IconButton
rounded
icon={<LuChevronsUp />}
intent="primary-subtle"
onClick={moveToTop}
title="Move to top"
/>
<IconButton
rounded
icon={<LuChevronsDown />}
intent="primary-subtle"
onClick={moveToBottom}
title="Move to bottom"
/>
</div>
<Switch
value={catalog.enabled ?? true}
onValueChange={onToggleEnabled}
moreHelp="Enable or disable this catalog from being used"
/>
</div>
</div>
{/* Settings section */}
<Accordion type="single" collapsible>
<AccordionItem value="settings">
<AccordionTrigger>
<div className="flex items-center justify-between w-full">
<h4 className="text-xs font-medium text-[var(--muted-foreground)] uppercase tracking-wide">
Settings
</h4>
{/* Active modifier icons */}
<div className="flex items-center gap-2 mr-2">
<Tooltip
trigger={
<IconButton
className={dynamicIconSize}
icon={
catalog.shuffle ? (
<FaShuffle />
) : (
<FaArrowRightLong />
)
}
intent="primary-subtle"
rounded
onClick={(e) => {
e.stopPropagation();
setUserData((prev) => ({
...prev,
catalogModifications:
prev.catalogModifications?.map((c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, shuffle: !c.shuffle }
: c
),
}));
}}
/>
}
>
Shuffle
</Tooltip>
<Tooltip
trigger={
<IconButton
className={dynamicIconSize}
icon={catalog.rpdb ? <PiStarFill /> : <PiStarBold />}
intent="primary-subtle"
rounded
onClick={(e) => {
e.stopPropagation();
setUserData((prev) => ({
...prev,
catalogModifications:
prev.catalogModifications?.map((c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, rpdb: !c.rpdb }
: c
),
}));
}}
/>
}
>
RPDB
</Tooltip>
{catalog.hideable && (
<Tooltip
trigger={
<IconButton
className={dynamicIconSize}
icon={
catalog.onlyOnDiscover ? (
<TbSmartHomeOff />
) : (
<TbSmartHome />
)
}
intent="primary-subtle"
rounded
onClick={(e) => {
e.stopPropagation();
setUserData((prev) => ({
...prev,
catalogModifications:
prev.catalogModifications?.map((c) =>
c.id === catalog.id &&
c.type === catalog.type
? {
...c,
onlyOnDiscover: !c.onlyOnDiscover,
}
: c
),
}));
}}
/>
}
>
Discover Only
</Tooltip>
)}
</div>
</div>
</AccordionTrigger>
<AccordionContent>
<div className="space-y-4">
{/* Large screens: horizontal layout, Medium and below: vertical layout */}
<div className="flex flex-col gap-4">
<Switch
label="Shuffle"
help="Randomize the order of catalog items on each request"
side="right"
value={catalog.shuffle ?? false}
onValueChange={(shuffle) => {
setUserData((prev) => ({
...prev,
catalogModifications: prev.catalogModifications?.map(
(c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, shuffle }
: c
),
}));
}}
/>
<div className="flex flex-col md:flex-row md:items-center gap-2 -mx-2 px-2 hover:bg-[var(--subtle-highlight)] rounded-md">
<div className="flex-1 py-2">
<label className="text-sm font-medium">
Persist Shuffle For
</label>
<p className="text-xs text-[--muted]">
The amount of hours to keep a given shuffled catalog
order before shuffling again. Defaults to 0 (Shuffle
on every request).
</p>
</div>
<div className="w-full md:w-32 py-2">
<NumberInput
value={catalog.persistShuffleFor ?? 0}
min={0}
step={1}
max={24}
onValueChange={(value) => {
setUserData((prev) => ({
...prev,
catalogModifications:
prev.catalogModifications?.map((c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, persistShuffleFor: value }
: c
),
}));
}}
/>
</div>
</div>
<Switch
label="RPDB"
help="Replace movie/show posters with RPDB posters when supported"
side="right"
value={catalog.rpdb ?? false}
onValueChange={(rpdb) => {
setUserData((prev) => ({
...prev,
catalogModifications: prev.catalogModifications?.map(
(c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, rpdb }
: c
),
}));
}}
/>
{catalog.hideable && (
<Switch
label="Discover Only"
help="Hide this catalog from the home page and only show it on the Discover page"
moreHelp="This can potentially break the catalog!"
side="right"
value={catalog.onlyOnDiscover ?? false}
onValueChange={(onlyOnDiscover) => {
setUserData((prev) => ({
...prev,
catalogModifications:
prev.catalogModifications?.map((c) =>
c.id === catalog.id && c.type === catalog.type
? { ...c, onlyOnDiscover }
: c
),
}));
}}
/>
)}
</div>
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</div>
{/* Name edit modal */}
<Modal
open={modalOpen}
onOpenChange={setModalOpen}
title="Edit Catalog Name"
>
<form
className="space-y-4"
onSubmit={(e) => {
e.preventDefault();
handleNameAndTypeEdit();
}}
>
<TextInput
label="Name"
placeholder="Enter catalog name"
value={newName}
onValueChange={setNewName}
/>
<TextInput
label="Type"
placeholder="Enter catalog type"
value={newType}
onValueChange={setNewType}
required
help="Override the type of the catalog. This can break the catalog and its behaviour."
/>
<Button className="w-full" type="submit">
Save Changes
</Button>
</form>
</Modal>
</li>
);
}
|