],
CMD_ADD_NEXT = "inject",
CMD_ADD_PLAY = "injectplay",
+ CMD_PAUSE = "pause",
+ CMD_PLAY = "play",
+ CMD_PREV = "prev",
+ CMD_NEXT = "next",
CMD_RM = "rm",
IDX_PATH_ID = 2,
IDX_START = 0,
);
playerDiv.innerHTML = "";
addPlayerBtnToDiv(
- "prev",
- "prev"
+ CMD_PREV,
+ CMD_PREV,
);
addPlayerBtnToDiv(
- "next",
- "next"
+ CMD_NEXT,
+ CMD_NEXT,
);
addPlayerBtnToDiv(
- data.is_playing ? "pause" : "play",
- "play"
+ data.is_playing ? CMD_PAUSE : CMD_PLAY,
+ CMD_PLAY
);
addSeparator();
addTextToDiv(
],
"max-lines-per-function": [
"error",
- 51
+ 53
],
"max-statements": [
"error",
- 12
+ 13
+],
+"multiline-ternary": [
+ "error",
+ "always-multiline"
],
"newline-after-var": "off",
"no-inline-comments": "off",
+"no-nested-ternary": "off",
"no-multi-spaces": [
"error",
{ "ignoreEOLComments": true }
],
+"no-ternary": "off",
"padded-blocks": [
"error",
"never"
*/
import {
BUTTONS_UP_DOWN,
+ CMD_PLAY,
CMD_RM,
PATH_PREFIX_FILE,
SYMBOL_RM,
} from "./_base.js";
const
+ BTN_PAUSE = "||",
+ BTN_PLAY = ">",
BUTTONS_ENTRY = [
[
- ">",
+ BTN_PLAY,
"jump"
]
].concat(BUTTONS_UP_DOWN).concat([
"rebuild"
],
CLS_ENTRY_CTL = "entry_control",
+ CLS_PLAYING_ROW = "playing",
CLS_PLAYLIST_ROW = "playlist_row",
ID_TABLE = `${CLS_PLAYLIST_ROW}s`,
PARAM_PLAYLIST = "playlist",
);
const tdEntryControl = addTdTo(tr);
tdEntryControl.classList.add(CLS_ENTRY_CTL);
+ for (
+ const [
+ symbol,
+ prefix
+ ] of BUTTONS_ENTRY
+ ) {
+ const isBtnPlaying = symbol === BTN_PLAY && idx === update.idx;
+ addPlayerBtnTo(
+ tdEntryControl,
+ isBtnPlaying
+ ? update.is_playing ? BTN_PAUSE : BTN_PLAY
+ : symbol,
+ isBtnPlaying ? CMD_PLAY : `${prefix}_${idx}`
+ );
+ }
addATdTo(
tr,
file.rel_path,
`${PATH_PREFIX_FILE}${file.digest}`
);
if (idx === update.idx) { // currently playing
- tdEntryControl.textContent = TOK_PLAYING;
+ tr.classList.add(CLS_PLAYING_ROW);
tdEntryControl.id = TOK_PLAYING;
if (firstLoad) { // replace anchor jump to #playing
firstLoad = false; // (initially un-built, won"t work)
tdEntryControl.scrollIntoView({"block": "center"});
}
- } else { // only non-playing items get playlist manip. buttons
- for (
- const [
- symbol,
- prefix
- ] of BUTTONS_ENTRY
- ) {
- addPlayerBtnTo(
- tdEntryControl,
- symbol,
- `${prefix}_${idx}`
- );
- }
}
}
);
'playlist_files': [
{'rel_path': str(f.rel_path),
'digest': f.digest.b64}
- for f in self.server.player.playlist]
+ for f in self.server.player.playlist],
+ 'is_playing': self.server.player.is_playing,
}
if 'download' in subscriptions:
yt_id = YoutubeId(download_id)
def move_entry(self, start_idx: int, upwards: bool = True) -> None:
"""Move playlist entry at start_idx up or down one step."""
+ if start_idx == self._idx:
+ start_idx += -1 if upwards else 1
+ upwards = not upwards
i0, i1 = start_idx, start_idx + (-1 if upwards else 1)
if i1 < 0 or i1 >= len(self.playlist):
return