Skip to content

Commit

Permalink
Merge pull request #93 from Serhii-DV/dev
Browse files Browse the repository at this point in the history
* [Feature] History widget improvement (#92)

* Set version `0.15.1`

* Make content tab wider

* Added styles for visited history widget

* `npm install @github/relative-time-element --save-dev`

* Use related time component in the latest visited widget

* Use related time component in the releases list component

* Introduced releases group list element component

* Output hostname instead of whole url

* A better format for title/year

* Update changelog

* [Feature] History widget improvement (#92)

* Set version `0.15.1`

* Make content tab wider

* Added styles for visited history widget

* `npm install @github/relative-time-element --save-dev`

* Use related time component in the latest visited widget

* Use related time component in the releases list component

* Introduced releases group list element component

* Output hostname instead of whole url

* A better format for title/year

* Update changelog

* [Feature] Bandcamp tab (#94)

* [Feature] History widget improvement (#92)

* Set version `0.15.1`

* Make content tab wider

* Added styles for visited history widget

* `npm install @github/relative-time-element --save-dev`

* Use related time component in the latest visited widget

* Use related time component in the releases list component

* Introduced releases group list element component

* Output hostname instead of whole url

* A better format for title/year

* Update changelog

* Rename dashboard to bandcamp tab

* Fix go to history tab link

* Update changelog
  • Loading branch information
Serhii-DV authored Oct 1, 2024
2 parents a7b9bb0 + 46e4f67 commit f682cd7
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 126 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change log

## 0.15.1 (2024-10-XX)

### Features

- popup: Show visited date as related time value
- popup: Improved visited releases widget
- popup: Renamed Dashboard tab to Bandcamp tab

## 0.15.0 (2024-09-30)

### Features
Expand Down
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.15.0",
"version": "0.15.1",
"devDependencies": {
"@github/relative-time-element": "^4.4.3",
"@swc/html": "^1.7.28",
"@types/chrome": "^0.0.273",
"@types/isotope-layout": "^3.0.13",
Expand Down
5 changes: 5 additions & 0 deletions src/app/release.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getUrlHostname } from '../utils/url';
import { generateKeyForUrl } from '../utils/key-generator';
import TrackTime from './trackTime.js';

Expand Down Expand Up @@ -115,6 +116,10 @@ export class Release {
return this.published.getFullYear();
}

get hostname() {
return getUrlHostname(this.releaseItem.url);
}

toStorageObject() {
return {
artist: this.releaseItem.artist,
Expand Down
79 changes: 79 additions & 0 deletions src/popup/components/releases-group-list-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Release } from 'src/app/release';
import { createElementFromHTML } from '../../utils/html';
import { VisitedDate } from '../../utils/storage';

const HTMLElement =
globalThis.HTMLElement || (null as unknown as (typeof window)['HTMLElement']);

export class ReleasesGroupListElement extends HTMLElement {
static define(tag = 'releases-group-list', registry = customElements) {
registry.define(tag, this);
return this;
}

#groupElement: Element | null = createElementFromHTML(
`<div class="list-group"></div>`
);

constructor() {
super();

const self = this;
if (self.#groupElement) {
self.appendChild(self.#groupElement);
}
}

addItem(
url: string,
content: string | Element,
title: string = '',
targetBlank: boolean = true
): Element | null {
const self = this;
const item = createElementFromHTML(
`<a href="${url}" class="list-group-item list-group-item-action" title="${title}"${targetBlank ? ' target="_blank"' : ''}></a>`
);

if (self.#groupElement === null || item === null) {
return null;
}

if (content instanceof Element) {
item.appendChild(content);
} else {
item.textContent = content;
}
self.#groupElement.appendChild(item);

return item;
}

addRelease(release: Release, visitedDate: VisitedDate) {
const self = this;
const releaseTitle = `${release.title} (${release.year})`;
const releaseContentElement = createElementFromHTML(`
<div class="d-flex justify-content-between">
<div class="flex-shrink-0">
<img src="${release.image}" alt="${releaseTitle}" class="img-fluid" style="width: 80px; height: 80px;">
</div>
<div class="flex-grow-1 ms-3">
<div class="d-flex w-100 justify-content-between">
<h6 class="release-artist mb-1">${release.artist}</h6>
<relative-time class="release-visited-date text-body-secondary" datetime="${visitedDate.date.toISOString()}">${visitedDate.date.toLocaleString()}</relative-time>
</div>
<p class="release-title mb-0">${releaseTitle}</p>
<small class="release-url text-body-secondary text-break">${release.hostname}</small>
</div>
</div>`);
if (releaseContentElement) {
self.addItem(release.url, releaseContentElement, release.url);
}

return self;
}
}

ReleasesGroupListElement.define();

export default ReleasesGroupListElement;
2 changes: 1 addition & 1 deletion src/popup/components/releases-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class ReleasesList extends HTMLElement {
setDataAttribute(row, 'visited', visitedDate.toLocaleString());

const historyDateHtml = lastHistoryDate
? `<span class="history-date" title="Visited on ${visitedDate.toLocaleString()}">${visitedDate.toLocaleDateString()}</span>`
? `<relative-time class="history-date text-body-secondary" datetime="${visitedDate.toISOString()}">${visitedDate.toLocaleString()}</relative-time>`
: '';

row.innerHTML = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
</button>
</div>
</form>
<form action="https://www.discogs.com/search" method="get" target="_blank">
<div class="input-group mb-3">
<input
type="text"
class="form-control"
placeholder="Discogs search for artist or release"
name="q"
/>
<button class="btn btn-secondary" type="submit">
<b2d-icon name="discogs-png"></b2d-icon>
</button>
</div>
</form>
</div>
<h6>Latest viewed releases</h6>
<div id="latestVisitedReleases" data-limit="10"></div>
<releases-group-list id="visitedReleases" limit="10"></releases-group-list>
9 changes: 9 additions & 0 deletions src/popup/css/releases-group-list.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.list-group-item {
padding: 5px;
}

.list-group-item .release-visited-date {
width: 30%;
font-size: 0.7em;
text-align: right;
}
2 changes: 1 addition & 1 deletion src/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body {
}

.content-text {
padding: 10px 20px;
padding: 10px;
}

.tab-pane {
Expand Down
10 changes: 5 additions & 5 deletions src/popup/popup.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<body>
<header>
<nav id="mainNav" class="btn-group d-flex" role="tablist">
<button class="btn btn-dark rounded-0" id="dashboard-tab" data-bs-toggle="tab" data-bs-target="#dashboard" role="tab" aria-controls="dashboard" aria-selected="true" type="button" title="Dashboard">
<b2d-icon name="dashboard"></b2d-icon>
<button class="btn btn-dark rounded-0" id="bandcamp-tab" data-bs-toggle="tab" data-bs-target="#bandcamp" role="tab" aria-controls="bandcamp" aria-selected="true" type="button" title="Bandcamp">
<b2d-icon name="bandcamp-png"></b2d-icon>
</button>
<button class="btn btn-dark rounded-0" id="release-tab" data-bs-toggle="tab" data-bs-target="#release" role="tab" aria-controls="release" aria-selected="true" type="button" title="Release preview">
<b2d-icon name="card-text"></b2d-icon>
Expand Down Expand Up @@ -44,9 +44,9 @@
<div id="mainContainer" class="container-fluid p-0 overflow-auto bg-image">

<div class="tab-content">
<!-- Dashboard -->
<div class="tab-pane fade content-text" id="dashboard" role="tabpanel" aria-labelledby="dashboard-tab" tabindex="0">
<%= tabContentDashboard %>
<!-- Bandcamp -->
<div class="tab-pane fade content-text" id="bandcamp" role="tabpanel" aria-labelledby="bandcamp-tab" tabindex="0">
<%= tabContentBandcamp %>
</div>
<!-- Release -->
<div class="tab-pane fade" id="release" role="tabpanel" aria-labelledby="release-tab" tabindex="0">
Expand Down
17 changes: 10 additions & 7 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import 'bootstrap';

// Popup styles
import './popup.css';
import './css/releases-group-list.css';

// Custom components
import './components/icon';
import './components/console-command.js';
import './components/releases-list.js';
import './components/releases-group-list-element.ts';
import '@github/relative-time-element';

import {
chromeSendMessageToCurrentTab,
Expand All @@ -31,9 +34,9 @@ import { isValidBandcampURL } from '../bandcamp/modules/html.js';
import { isValidDiscogsReleaseEditUrl } from '../discogs/app/utils.js';
import { logInfo } from '../utils/console';
import { createReleaseFromSchema } from '../utils/schema';
import { setupDashboardTab } from './tabs/dashboard_tab.js';
import { setupBandcampTab } from './tabs/bandcamp_tab.js';

const btnDashboardTab = document.getElementById('dashboard-tab');
const btnBandcampTab = document.getElementById('bandcamp-tab');
const btnReleaseTab = document.getElementById('release-tab');
const btnReleasesTab = document.getElementById('releases-tab');
const btnCsvDataTab = document.getElementById('csvData-tab');
Expand All @@ -50,7 +53,7 @@ async function proceedBandcampData() {
chromeSendMessageToCurrentTab(
{ type: 'B2D_BC_DATA' },
processBandcampResponse,
showDashboard
showBandcampTab
);
}

Expand All @@ -63,11 +66,11 @@ async function proceedDiscogsEditPageData() {
);
}

function showDashboard() {
function showBandcampTab() {
disable(btnReleaseTab, btnCsvDataTab);
hide(btnReleasesTab);
show(btnDownloadReleases);
click(btnDashboardTab);
click(btnBandcampTab);
}

function processBandcampResponse(response) {
Expand Down Expand Up @@ -164,7 +167,7 @@ function setupNavigation() {
setupHistoryTab(document.getElementById('history'), btnDownloadStorage);
});

setupDashboardTab(btnHistoryTab);
setupBandcampTab(btnHistoryTab);
}

function initialize(tab) {
Expand All @@ -183,7 +186,7 @@ function initialize(tab) {
} else if (isValidDiscogsReleaseEditUrl(currentTabUrl)) {
proceedDiscogsEditPageData();
} else {
showDashboard();
showBandcampTab();
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/popup/tabs/bandcamp_tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { click, getDataAttribute } from '../../utils/html';
import { log } from '../../utils/console';
import { getLatestHistoryData, getReleasesByUuids } from '../../utils/storage';
import { getOwnProperty } from '../../utils/utils';

export function setupBandcampTab(btnHistoryTab) {
log('Setup bandcamp tab');

setupLatestVisitedWidget(btnHistoryTab);
}

function setupLatestVisitedWidget(btnHistoryTab) {
const visitedReleasesWidget = document.getElementById('visitedReleases');
const limit = getDataAttribute(visitedReleasesWidget, 'limit', 10);

getLatestHistoryData(limit).then((visitedDates) => {
const uuids = visitedDates.map((visitedDate) => visitedDate.uuid);
getReleasesByUuids(uuids).then((releaseMap) => {
visitedDates.forEach((visitedDate) => {
const release = getOwnProperty(releaseMap, visitedDate.uuid);
if (release) {
visitedReleasesWidget.addRelease(release, visitedDate);
}
});

const item = visitedReleasesWidget.addItem(
'#history',
'Go to history...',
'Go to history...',
false
);
item.addEventListener('click', (event) => {
click(btnHistoryTab);
event.preventDefault();
});
});
});
}
Loading

0 comments on commit f682cd7

Please sign in to comment.