Skip to content

Commit

Permalink
Break up ResultRow #2 - SectionOptionsResultRow
Browse files Browse the repository at this point in the history
  • Loading branch information
danrahn committed Mar 10, 2024
1 parent 22deb02 commit 326493e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 67 deletions.
3 changes: 2 additions & 1 deletion Client/Script/PlexUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { $, $$, buildNode, clearEle, clickOnEnterCallback } from './Common.js';
import { ContextualLog } from '../../Shared/ConsoleLog.js';

import { FilterSettings, SortConditions, SortOrder } from './FilterDialog.js';
import { MovieResultRow, ResultRow, SectionOptionsResultRow, ShowResultRow } from './ResultRow.js';
import { MovieResultRow, ResultRow, ShowResultRow } from './ResultRow.js';
import { UISection, UISections } from './ResultSections.js';
import { ClientSettings } from './ClientSettings.js';
import { CustomEvents } from './CustomEvents.js';
import Overlay from './Overlay.js';
import { PlexClientState } from './PlexClientState.js';
import { PurgedMarkers } from './PurgedMarkerManager.js';
import { SectionOptionsResultRow } from './SectionOptionsResultRow.js';
import { SectionType } from '../../Shared/PlexTypes.js';

/** @typedef {!import('../../Shared/PlexTypes').LibrarySection} LibrarySection */
Expand Down
67 changes: 1 addition & 66 deletions Client/Script/ResultRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Overlay from './Overlay.js';
import { PlexClientState } from './PlexClientState.js';
import { PurgedMarkers } from './PurgedMarkerManager.js';
import { SeasonData } from '../../Shared/PlexTypes.js';
import SectionOptionsOverlay from './SectionOptionsOverlay.js';
import SectionOptionsResultRow from './SectionOptionsResultRow.js';
import { ServerCommands } from './Commands.js';
import { ThemeColors } from './ThemeColors.js';
import Tooltip from './Tooltip.js';
Expand Down Expand Up @@ -318,71 +318,6 @@ class ResultRow {
}
}

/**
* A section-wide header that is displayed no matter what the current view state is (beside the blank state).
* Currently only contains the Filter entrypoint.
*/
class SectionOptionsResultRow extends ResultRow {
/** @type {HTMLElement} */
#filterButton;
/** @type {HTMLElement} */
#moreOptionsButton;
constructor() {
super(null, 'topLevelResult sectionOptions');
}

/**
* Build the section-wide header. */
buildRow() {
if (this.html()) {
Log.warn(`buildRow has already been called for this SectionOptionsResultRow, that shouldn't happen!`);
return this.html();
}

if (!ClientSettings.showExtendedMarkerInfo()) {
Log.error(`SectionOptionsResultRow requires extended marker info`);
return buildNode('div');
}

const titleNode = buildNode('div', { class : 'bulkActionTitle' }, 'Section Options');
const row = buildNode('div', { class : 'sectionOptionsResultRow' });
this.#filterButton = ButtonCreator.fullButton('Sort/Filter',
Icons.Filter,
ThemeColors.Primary,
function(_e, self) { new FilterDialog(PlexClientState.activeSectionType()).show(self); },
{ class : 'filterBtn', style : 'margin-right: 10px' });
Tooltip.setTooltip(this.#filterButton, 'No Active Filter'); // Need to seed the setTooltip, then use setText for everything else.
this.updateFilterTooltip();

this.#moreOptionsButton = ButtonCreator.fullButton(
'More...',
Icons.Settings,
ThemeColors.Primary,
function(_e, self) { new SectionOptionsOverlay().show(self); },
{ class : 'moreSectionOptionsBtn' });

appendChildren(row,
titleNode,
appendChildren(row.appendChild(buildNode('div', { class : 'goBack' })),
this.#filterButton,
this.#moreOptionsButton));
this.setHtml(row);
return row;
}

/**
* Update the filter button's style and tooltip based on whether a filter is currently active. */
updateFilterTooltip() {
if (FilterSettings.hasFilter()) {
this.#filterButton.classList.add('filterActive');
Tooltip.setText(this.#filterButton, FilterSettings.filterTooltipText());
} else {
this.#filterButton.classList.remove('filterActive');
Tooltip.setText(this.#filterButton, 'No Active Filter');
}
}
}

/**
* A result row for a single show in the library.
*/
Expand Down
78 changes: 78 additions & 0 deletions Client/Script/SectionOptionsResultRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { appendChildren, buildNode } from './Common.js';
import { FilterDialog, FilterSettings } from './FilterDialog.js';
import ButtonCreator from './ButtonCreator.js';
import { ClientSettings } from './ClientSettings.js';
import { ContextualLog } from '../../Shared/ConsoleLog.js';
import Icons from './Icons.js';
import { PlexClientState } from './PlexClientState.js';
import { ResultRow } from './ResultRow.js';
import SectionOptionsOverlay from './SectionOptionsOverlay.js';
import { ThemeColors } from './ThemeColors.js';
import Tooltip from './Tooltip.js';

const Log = new ContextualLog('SectionOptionsRow');

/**
* A section-wide header that is displayed no matter what the current view state is (beside the blank state).
* Currently only contains the Filter entrypoint.
*/
export default class SectionOptionsResultRow extends ResultRow {
/** @type {HTMLElement} */
#filterButton;
/** @type {HTMLElement} */
#moreOptionsButton;
constructor() {
super(null, 'topLevelResult sectionOptions');
}

/**
* Build the section-wide header. */
buildRow() {
if (this.html()) {
Log.warn(`buildRow has already been called for this SectionOptionsResultRow, that shouldn't happen!`);
return this.html();
}

if (!ClientSettings.showExtendedMarkerInfo()) {
Log.error(`SectionOptionsResultRow requires extended marker info`);
return buildNode('div');
}

const titleNode = buildNode('div', { class : 'bulkActionTitle' }, 'Section Options');
const row = buildNode('div', { class : 'sectionOptionsResultRow' });
this.#filterButton = ButtonCreator.fullButton('Sort/Filter',
Icons.Filter,
ThemeColors.Primary,
function (_e, self) { new FilterDialog(PlexClientState.activeSectionType()).show(self); },
{ class : 'filterBtn', style : 'margin-right: 10px' });
Tooltip.setTooltip(this.#filterButton, 'No Active Filter'); // Need to seed the setTooltip, then use setText for everything else.
this.updateFilterTooltip();

this.#moreOptionsButton = ButtonCreator.fullButton(
'More...',
Icons.Settings,
ThemeColors.Primary,
function (_e, self) { new SectionOptionsOverlay().show(self); },
{ class : 'moreSectionOptionsBtn' });

appendChildren(row,
titleNode,
appendChildren(row.appendChild(buildNode('div', { class : 'goBack' })),
this.#filterButton,
this.#moreOptionsButton));
this.setHtml(row);
return row;
}

/**
* Update the filter button's style and tooltip based on whether a filter is currently active. */
updateFilterTooltip() {
if (FilterSettings.hasFilter()) {
this.#filterButton.classList.add('filterActive');
Tooltip.setText(this.#filterButton, FilterSettings.filterTooltipText());
} else {
this.#filterButton.classList.remove('filterActive');
Tooltip.setText(this.#filterButton, 'No Active Filter');
}
}
}

0 comments on commit 326493e

Please sign in to comment.