Skip to content

Commit

Permalink
Fix Yule log card render code and shortcut functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Clark committed Dec 4, 2024
1 parent 644b45e commit 3ca75ed
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 31 deletions.
4 changes: 2 additions & 2 deletions css/80_app_fb.css
Original file line number Diff line number Diff line change
Expand Up @@ -1057,13 +1057,13 @@ div.holiday-banner {
margin-top: -15px;
text-shadow: 0 0 80px rgba(223, 221, 170, 0.85),0 0 30px rgba(252, 249, 233, 0.85),0 0 6px DarkRed;
}
div.panel-container-yule_log {
div.card-container-yule_log {
padding-bottom: 0px;
width:400px;
height:250px;
}

div.panel-content.panel-content-yule_log {
div.card-content.card-content-yule_log {
background:url('https://media.giphy.com/media/ZHXz9MZbJI1YA/giphy.gif');
height: 100%;
}
Expand Down
95 changes: 66 additions & 29 deletions modules/ui/cards/UiYuleLogCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { select as d3_select } from 'd3-selection';
import { selection } from 'd3-selection';
import debounce from 'lodash-es/debounce';

import { AbstractUiCard } from './AbstractUiCard';
import { uiIcon } from '../icon.js';
import { utilCmd } from '../../util/cmd.js';



Expand All @@ -19,57 +21,92 @@ export class UiYuleLogCard extends AbstractUiCard {
this.id = 'yule_log';

const l10n = context.systems.l10n;
this.label = l10n.tHtml('info_panels.toggle_yule_log.title');
this.label = l10n.tHtml('info_panels.yule_log.title');
this.key = l10n.t('info_panels.yule_log.key');

this._selection = d3_select(null);
this._setupKeybinding = this._setupKeybinding.bind(this);

// Ensure methods used as callbacks always have `this` bound correctly.
// (This is also necessary when using `d3-selection.call`)
this.render = this.render.bind(this);
this._deferredRender = debounce(this.render, 250);

l10n
.on('localechange', this._setupKeybinding);

this._setupKeybinding();
}


/**
* enable
* @param `selection` A d3-selection to a `div` that the panel should render itself into
* render
* Accepts a parent selection, and renders the content under it.
* (The parent selection is required the first time, but can be inferred on subsequent renders)
* @param {d3-selection} $parent - A d3-selection to a HTMLElement that this component should render itself into
*/
enable(selection) {
if (this._enabled) return;
render($parent = this.$parent) {
if ($parent instanceof selection) {
this.$parent = $parent;
} else {
return; // no parent - called too early?
}

const context = this.context;
const l10n = context.systems.l10n;

this._enabled = true;
}
if (!this.visible) return;

// .card-container
let $wrap = $parent.selectAll('.card-container')
.data([this.id], d => d);

/**
* disable
*/
disable() {
if (!this._enabled) return;
// enter
const $$wrap = $wrap.enter()
.append('div')
.attr('class', d => `fillD2 card-container card-container-${d}`);

const $$title = $$wrap
.append('div')
.attr('class', 'fillD2 card-title');

this._selection.html(''); // empty DOM
$$title
.append('h3');

$$title
.append('button')
.attr('class', 'close')
.on('click', this.toggle)
.call(uiIcon('#rapid-icon-close'));

$$wrap
.append('div')
.attr('class', d => `card-content card-content-${d}`)
.append('ul')
.attr('class', 'yule-log');

// update
this.$wrap = $wrap = $wrap.merge($$wrap);

$wrap.selectAll('h3')
.text(l10n.t('info_panels.yule_log.title'));

this._enabled = false;
this._selection = d3_select(null);
this._currSourceID = null;
this._metadata = {};
}


/**
* render
* _setupKeybinding
* This sets up the keybinding, replacing existing if needed
*/
render() {
if (!this._enabled) return;

const selection = this._selection;
_setupKeybinding() {
const context = this.context;
const keybinding = context.keybinding();
const l10n = context.systems.l10n;

// Empty out the DOM content and rebuild from scratch..
selection.html('');
if (Array.isArray(this._keys)) {
keybinding.off(this._keys);
}

selection
.append('ul')
.attr('class', 'yule-log');
this._keys = [utilCmd('⌘⇧' + l10n.t('shortcuts.command.toggle_yule_log.key'))];
context.keybinding().on(this._keys, this.toggle);
}
}

0 comments on commit 3ca75ed

Please sign in to comment.