Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/argo-archive-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export class ArgoArchiveList extends LitElement {
return this.pages.filter((p) => this.selectedPages.has(p.ts));
}

public getAllPages() {
return this.pages;
}

async connectedCallback() {
super.connectedCallback();
this.collId = (await getLocalOption("defaultCollId")) || "";
Expand Down
67 changes: 58 additions & 9 deletions src/sidepanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ class ArgoViewer extends LitElement {
color: #000;
}

.status-divider {
width: 100%;
margin: 0.5rem 0;
border: none;
border-top: 1px solid #e0e0e0;
}

img.favicon {
width: var(--md-icon-size) !important;
height: var(--md-icon-size) !important;
Expand Down Expand Up @@ -226,6 +233,23 @@ class ArgoViewer extends LitElement {
return "";
}

private getCurrentPage() {
const sameUrls = this.archiveList
?.getAllPages()
// @ts-expect-error - TS2339 - Property 'pageUrl' does not exist on type 'ArgoViewer'.
.filter((p) => p.url === this.pageUrl);
if (!sameUrls || !sameUrls.length) {
return null;
}

// Sort by timestamp (newest first)
return sameUrls.sort((a, b) => {
const tsA = parseInt(a.ts, 10);
const tsB = parseInt(b.ts, 10);
return tsB - tsA; // Descending order (newest first)
})[0];
}
Comment on lines +236 to +251

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add null check for this.archiveList before accessing getAllPages() to prevent potential runtime errors when archiveList is null or undefined. [possible issue, importance: 8]

Suggested change
private getCurrentPage() {
const sameUrls = this.archiveList
?.getAllPages()
// @ts-expect-error - TS2339 - Property 'pageUrl' does not exist on type 'ArgoViewer'.
.filter((p) => p.url === this.pageUrl);
if (!sameUrls || !sameUrls.length) {
return null;
}
// Sort by timestamp (newest first)
return sameUrls.sort((a, b) => {
const tsA = parseInt(a.ts, 10);
const tsB = parseInt(b.ts, 10);
return tsB - tsA; // Descending order (newest first)
})[0];
}
private getCurrentPage() {
if (!this.archiveList) {
return null;
}
const sameUrls = this.archiveList
.getAllPages()
// @ts-expect-error - TS2339 - Property 'pageUrl' does not exist on type 'ArgoViewer'.
.filter((p) => p.url === this.pageUrl);
if (!sameUrls || !sameUrls.length) {
return null;
}
// Sort by timestamp (newest first)
return sameUrls.sort((a, b) => {
const tsA = parseInt(a.ts, 10);
const tsB = parseInt(b.ts, 10);
return tsB - tsA; // Descending order (newest first)
})[0];
}


private async onDownload() {
const selectedPages = this.archiveList?.getSelectedPages?.() || [];
if (!selectedPages.length) {
Expand Down Expand Up @@ -276,19 +300,33 @@ class ArgoViewer extends LitElement {
console.log("WACZ file downloaded:", filename);
}

private async onShare() {
private async onShareSelected() {
const selectedPages = this.archiveList?.getSelectedPages?.() || [];
if (!selectedPages.length) {
alert("Please select some pages to share.");
return;
}

console.log("Selected pages to share:", selectedPages);
await this.onShare(selectedPages);
}

private async onShareCurrent() {
const currentPage = this.getCurrentPage?.() || null;
if (!currentPage) {
alert("No current page to share.");
return;
}
console.log("Current page to share:", currentPage);
await this.onShare([currentPage]);
}
Comment on lines +313 to +321

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the optional chaining operator (?.) when calling this.getCurrentPage() since it's a defined method in the class and not an optional property. [general, importance: 6]

Suggested change
private async onShareCurrent() {
const currentPage = this.getCurrentPage?.() || null;
if (!currentPage) {
alert("No current page to share.");
return;
}
console.log("Current page to share:", currentPage);
await this.onShare([currentPage]);
}
private async onShareCurrent() {
const currentPage = this.getCurrentPage() || null;
if (!currentPage) {
alert("No current page to share.");
return;
}
console.log("Current page to share:", currentPage);
await this.onShare([currentPage]);
}


// @ts-expect-error - TS7006 - Parameter 'pages' implicitly has an 'any' type.
private async onShare(pages) {
const defaultCollId = (await getLocalOption("defaultCollId")) || "";
const coll = await collLoader.loadColl(defaultCollId);

const pageTsList = selectedPages.map((p) => p.id);
// @ts-expect-error - TS7006 - Parameter 'p' implicitly has an 'any' type.
const pageTsList = pages.map((p) => p.id);
const format = "wacz";
const filename = `archive-${Date.now()}.wacz`;

Expand Down Expand Up @@ -654,13 +692,21 @@ class ArgoViewer extends LitElement {
}
${
// @ts-expect-error - TS2339 - Property 'status' does not exist on type 'ArgoViewer'. | TS2339 - Property 'status' does not exist on type 'ArgoViewer'.
!this.status?.numPending
!this.status?.numPending && this.pageUrl
? html`<div class="status-container">
<md-icon filled style="color: var(--md-sys-color-primary);"
>check_circle</md-icon
<md-icon filled style="color: var(--md-sys-color-primary);"
>check_circle</md-icon
>
<span class="status-content">All resources archived</span>
</div>
<hr class="status-divider" />
<md-filled-button
style="color: white; border-radius: 9999px; align-self: flex-end;"
@click=${this.onShareCurrent}
>
<span class="status-content">All resources archived</span>
</div>`
<md-icon slot="icon" style="color:white">share</md-icon>
Share Current Page
</md-filled-button> `
: ""
}
</div>`;
Expand Down Expand Up @@ -828,7 +874,10 @@ class ArgoViewer extends LitElement {
<md-icon style="color: gray;">download</md-icon>
</md-icon-button>

<md-icon-button aria-label="Share" @click=${this.onShare}>
<md-icon-button
aria-label="Share"
@click=${this.onShareSelected}
>
<md-icon style="color: gray;">share</md-icon>
</md-icon-button>
`
Expand Down
Loading