Skip to content

Commit

Permalink
Code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nsharma123 committed Jan 17, 2025
1 parent e296fc6 commit b464f2b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "The Internet Archive Collection Browser.",
"license": "AGPL-3.0-only",
"author": "Internet Archive",
"version": "2.7.6",
"version": "2.7.6-alpha4",
"main": "dist/index.js",
"module": "dist/index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions src/app-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export class AppRoot extends LitElement {
.modalManager=${this.modalManager}
.analyticsHandler=${this.analyticsHandler}
.pageContext=${'search'}
.activeTabId=${''}
.activeTabId=${'uploads'}
@visiblePageChanged=${this.visiblePageChanged}
@baseQueryChanged=${this.baseQueryChanged}
@searchTypeChanged=${this.searchTypeChanged}
Expand Down Expand Up @@ -710,9 +710,10 @@ export class AppRoot extends LitElement {
* Handler for item removal
*/
private handleItemRemovalRequest(e: CustomEvent) {
setTimeout(() => {
console.log('itemRemovalRequested: ', e.detail.items);
this.collectionBrowser.showRemoveItemsProcessingModal();
console.log('itemRemovalRequested: ', e.detail.items);

setTimeout(() => {
// execute item-removal-service, and response is successfully deleted
const status = false;

Expand All @@ -723,7 +724,7 @@ export class AppRoot extends LitElement {
this.modalManager?.classList.remove('remove-items');
} else {
// looking for failure?
this.collectionBrowser.hasItemsDeleted = false;
this.collectionBrowser.showRemoveItemsErrorModal();
}
}, 2000); // let's wait to see processing modal
}
Expand All @@ -743,7 +744,6 @@ export class AppRoot extends LitElement {
this.collectionBrowser.isManageView = target.checked;
this.collectionBrowser.manageViewLabel =
'Select items to remove (customizable texts)';
this.collectionBrowser.hasItemsDeleted = true;
}

/**
Expand Down
27 changes: 23 additions & 4 deletions src/collection-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { srOnlyStyle } from './styles/sr-only';
import { sha1 } from './utils/sha1';
import { log } from './utils/log';
import type { PlaceholderType } from './empty-placeholder';
import type { ManageBar } from './manage/manage-bar';

import './empty-placeholder';
import './tiles/tile-dispatcher';
Expand Down Expand Up @@ -245,8 +246,6 @@ export class CollectionBrowser
*/
@property({ type: Boolean }) isManageView = false;

@property({ type: Boolean }) hasItemsDeleted = true;

@property({ type: String }) manageViewLabel = 'Select items to remove';

/** Whether to replace the default sort options with a slot for customization (default: false) */
Expand Down Expand Up @@ -301,6 +300,8 @@ export class CollectionBrowser

@query('collection-facets') private collectionFacets?: CollectionFacets;

@query('manage-bar') private manageBar?: ManageBar;

@property({ type: Object, attribute: false })
analyticsHandler?: AnalyticsManagerInterface;

Expand Down Expand Up @@ -776,12 +777,17 @@ export class CollectionBrowser
* showing the management view. This generally replaces the sort bar when present.
*/
private get manageBarTemplate(): TemplateResult {
const manageViewModelMsg =
this.profileElement === 'uploads'
? 'Note: it may take a few minutes for these items to stop appearing in your uploads list.'
: nothing;

return html`
<manage-bar
.label=${this.manageViewLabel}
.modalManager=${this.modalManager}
.selectedItems=${this.dataSource.checkedTileModels}
.hasItemsDeleted=${this.hasItemsDeleted}
.manageViewModelMsg=${manageViewModelMsg}
showSelectAll
showUnselectAll
?showItemManageButton=${this.pageContext === 'search'}
Expand All @@ -803,7 +809,6 @@ export class CollectionBrowser
* Emits an `itemRemovalRequested` event with all checked tile models.
*/
private handleRemoveItems(): void {
this.hasItemsDeleted = true;
this.dispatchEvent(
new CustomEvent<{ items: String[] }>('itemRemovalRequested', {
detail: {
Expand All @@ -830,6 +835,20 @@ export class CollectionBrowser
);
}

/**
* Handler to show processing modal while removing item
*/
showRemoveItemsProcessingModal(): void {
this.manageBar?.showRemoveItemsProcessingModal();
}

/**
* Handler to show error modal when item removal failed
*/
showRemoveItemsErrorModal(): void {
this.manageBar?.showRemoveItemsErrorModal();
}

/**
* Removes all tile models that are currently checked & adjusts the paging
* of the data source to account for any new gaps in the data.
Expand Down
39 changes: 9 additions & 30 deletions src/manage/manage-bar.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { msg } from '@lit/localize';
import {
LitElement,
html,
css,
TemplateResult,
CSSResultGroup,
PropertyValues,
} from 'lit';
import { LitElement, html, css, TemplateResult, CSSResultGroup } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { when } from 'lit/directives/when.js';
import {
Expand Down Expand Up @@ -39,6 +32,11 @@ export class ManageBar extends LitElement {
*/
@property({ type: Object }) selectedItems: Array<ManageableItem> = [];

/**
* Message shows as note in the modal when removing items
*/
@property({ type: String }) manageViewModelMsg?: string;

/**
* Whether to show the "Select All" button (default false)
*/
Expand All @@ -49,11 +47,6 @@ export class ManageBar extends LitElement {
*/
@property({ type: Boolean }) showUnselectAll = false;

/**
* Whether item has deleted or not (default true)
*/
@property({ type: Boolean }) hasItemsDeleted = true;

/**
* Whether to show "Item Manager the items" button (default false)
*/
Expand All @@ -64,12 +57,6 @@ export class ManageBar extends LitElement {
*/
@property({ type: Boolean }) removeAllowed = false;

updated(changed: PropertyValues): void {
if (changed.has('hasItemsDeleted') && !this.hasItemsDeleted) {
this.showRemoveItemsErrorModal();
}
}

render(): TemplateResult {
return html`
<div class="manage-container">
Expand Down Expand Up @@ -125,7 +112,6 @@ export class ManageBar extends LitElement {
}

private removeItemsClicked(): void {
this.showRemoveItemsProcessingModal();
this.dispatchEvent(new CustomEvent('removeItems'));
}

Expand All @@ -146,17 +132,10 @@ export class ManageBar extends LitElement {
* @param items Which items to list in the modal
*/
private showRemoveItemsModal(): void {
const delayMessage =
this.activeTabId === 'uploads'
? msg(
'Note: it may take a few minutes for these items to stop appearing in your uploads list.'
)
: undefined;

const customModalContent = html`
<remove-items-modal-content
.items=${this.selectedItems}
.message=${delayMessage}
.message=${this.manageViewModelMsg}
@confirm=${() => this.removeItemsClicked()}
></remove-items-modal-content>
`;
Expand Down Expand Up @@ -184,7 +163,7 @@ export class ManageBar extends LitElement {
/**
* Shows a modal dialog indicating that item removal is being processed
*/
private showRemoveItemsProcessingModal(): void {
showRemoveItemsProcessingModal(): void {
const config = new ModalConfig({
showProcessingIndicator: true,
processingImageMode: 'processing',
Expand All @@ -207,7 +186,7 @@ export class ManageBar extends LitElement {
/**
* Shows a modal dialog indicating that an error occurred while removing items
*/
private showRemoveItemsErrorModal(): void {
showRemoveItemsErrorModal(): void {
const config = new ModalConfig({
showProcessingIndicator: false,
processingImageMode: 'processing',
Expand Down

0 comments on commit b464f2b

Please sign in to comment.