refactor: handle edge cases correctly

This commit is contained in:
Timothy Z. 2024-10-22 10:25:29 +03:00
parent d12766ecad
commit 14d5fc3da7
3 changed files with 15 additions and 7 deletions

View file

@ -1,6 +1,7 @@
// Copyright (C) 2017-2023 Smart code 203358507
const CHROMECAST_RECEIVER_APP_ID = '1634F54B';
const DEFAULT_STREAMING_SERVER_URL = 'http://127.0.0.1:11470/';
const SUBTITLES_SIZES = [75, 100, 125, 150, 175, 200, 250];
const SUBTITLES_FONTS = ['PlusJakartaSans', 'Arial', 'Halvetica', 'Times New Roman', 'Verdana', 'Courier', 'Lucida Console', 'sans-serif', 'serif', 'monospace'];
const SEEK_TIME_DURATIONS = [3000, 5000, 10000, 15000, 20000, 30000];
@ -97,6 +98,7 @@ const WHITELISTED_HOSTS = ['stremio.com', 'strem.io', 'stremio.zendesk.com', 'go
module.exports = {
CHROMECAST_RECEIVER_APP_ID,
DEFAULT_STREAMING_SERVER_URL,
SUBTITLES_SIZES,
SUBTITLES_FONTS,
SEEK_TIME_DURATIONS,

View file

@ -70,12 +70,11 @@
.checkbox-disabled {
cursor: not-allowed;
opacity: 0.6;
}
.checkbox-disabled .checkbox-container {
background-color: var(--overlay-color);
border-color: var(--overlay-color);
cursor: not-allowed;
}
.checkbox-disabled .checkbox-label {

View file

@ -2,13 +2,14 @@
import React, { useState, useCallback, ChangeEvent } from 'react';
import { useProfile } from 'stremio/common';
import { DEFAULT_STREAMING_SERVER_URL } from 'stremio/common/CONSTANTS';
import { useTranslation } from 'react-i18next';
import Button from 'stremio/common/Button';
import useStreamingServer from 'stremio/common/useStreamingServer';
import TextInput from 'stremio/common/TextInput';
import Icon from '@stremio/stremio-icons/react';
import styles from './Item.less';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import Checkbox from 'stremio/common/Checkbox';
type ViewModeProps = {
@ -22,9 +23,11 @@ const ViewMode = ({ url, onDelete, onSelect }: ViewModeProps) => {
const streamingServer = useStreamingServer();
const profile = useProfile();
const selected = profile.settings.streamingServerUrl === url;
const defaultUrl = url === DEFAULT_STREAMING_SERVER_URL;
const handleDelete = () => {
onDelete?.(url);
onSelect?.(DEFAULT_STREAMING_SERVER_URL);
};
const handleSelect = () => {
@ -34,7 +37,7 @@ const ViewMode = ({ url, onDelete, onSelect }: ViewModeProps) => {
return (
<>
<div className={styles['content']}>
<Checkbox value={selected} onChange={handleSelect} />
<Checkbox value={selected} onChange={handleSelect} disabled={selected} />
<div className={styles['label']}>{url}</div>
</div>
<div className={styles['actions']}>
@ -59,9 +62,13 @@ const ViewMode = ({ url, onDelete, onSelect }: ViewModeProps) => {
</div>
: null
}
<Button className={styles['delete']} onClick={handleDelete}>
<Icon name={'close'} className={styles['icon']} />
</Button>
{
!defaultUrl ?
<Button className={styles['delete']} onClick={handleDelete}>
<Icon name={'close'} className={styles['icon']} />
</Button>
: null
}
</div>
</>
);