Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Add advanced source settings #1461

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 69 additions & 16 deletions client/js/templates/Source.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ function SourceEditForm({
[updateEditedSource]
);

const iconOnChange = useCallback(
(event) => updateEditedSource({ icon: event.target.value }),
[updateEditedSource]
);

const spoutOnChange = useCallback(
(event) =>
handleSpoutChange({
Expand Down Expand Up @@ -370,6 +375,22 @@ function SourceEditForm({

const _ = useContext(LocalizationContext);

const [showAdvanced, setShowAdvanced] = useState(false);
const [filterUsed, setFilterUsed] = useState(source.filter !== '');
// TODO: Remove undefined check once we implement it server side.
const [iconUsed, setIconUsed] = useState(source.icon !== '' && source.icon !== undefined);

const toggleShowAdvanced = useCallback(
() => {
setShowAdvanced((advanced) => !advanced);
console.log(source.filter);
setFilterUsed(source.filter !== '');
// TODO: Remove undefined check once we implement it server side.
setIconUsed(source.icon !== '' && source.icon !== undefined);
},
[source.filter, source.icon]
);

const sourceParamsContent = (
sourceParamsLoading ? (
<Spinner size="3x" label={_('source_params_loading')} />
Expand Down Expand Up @@ -451,22 +472,24 @@ function SourceEditForm({
</li>

{/* filter */}
<li>
<label htmlFor={`filter-${sourceId}`}>
{_('source_filter')}
</label>
<input
id={`filter-${sourceId}`}
type="text"
name="filter"
accessKey="f"
value={source.filter ?? ''}
onChange={filterOnChange}
/>
{sourceErrors['filter'] ? (
<span className="error">{sourceErrors['filter']}</span>
) : null}
</li>
{showAdvanced || filterUsed ? (
<li>
<label htmlFor={`filter-${sourceId}`}>
{_('source_filter')}
</label>
<input
id={`filter-${sourceId}`}
type="text"
name="filter"
accessKey="f"
value={source.filter ?? ''}
onChange={filterOnChange}
/>
{sourceErrors['filter'] ? (
<span className="error">{sourceErrors['filter']}</span>
) : null}
</li>
) : null}

{/* type */}
<li>
Expand Down Expand Up @@ -497,6 +520,26 @@ function SourceEditForm({
) : null}
</li>

{showAdvanced || iconUsed ? (
<li>
<label htmlFor={`icon-${sourceId}`}>
{/*_('source_icon')*/}
{'Icon:'}
</label>
<input
id={`icon-${sourceId}`}
type="text"
name="icon"
accessKey="f"
value={source.icon ?? ''}
onChange={iconOnChange}
/>
{sourceErrors['icon'] ? (
<span className="error">{sourceErrors['icon']}</span>
) : null}
</li>
) : null}

{/* settings */}
{sourceParamsContent ? (
<li className="source-params">
Expand All @@ -513,6 +556,16 @@ function SourceEditForm({

{/* save/delete */}
<li className="source-action">
<button
type="button"
className="source-toggle-advanced source-save"
accessKey="a"
onClick={toggleShowAdvanced}
>
{(showAdvanced ? 'Hide advanced' : 'Show advanced')}
{/*{_(showAdvanced ? 'source_hide_advanced' : 'source_show_advanced')}*/}
</button>
{' • '}
<button
type="submit"
className="source-save"
Expand Down