Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do Not Merge]]Revert code added for Collection API endpoints update #48

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 28 additions & 9 deletions blocks/adp-add-to-collection-modal/adp-add-to-collection-modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decorateIcons } from '../../scripts/lib-franklin.js';
import {
searchListCollection, createCollection, patchCollection, getCollection,
listCollection, createCollection, patchCollection, getCollection,
} from '../../scripts/collections.js';
import { getSelectedAssetsFromInfiniteResultsBlock, populateAssetViewLeftDialog } from '../../scripts/scripts.js';
import createMultiSelectedAssetsTable from '../../scripts/multi-selected-assets-table.js';
Expand Down Expand Up @@ -43,18 +43,38 @@ async function createDropdown(addToExistingRadioDropboxContainer) {
dropdownSelect.classList.add('add-to-existing-dropdown'); // Add the new class

// Function to load more data when reaching the end of the dropdown
const loadMoreData = async (page) => {
// Call to get the nbHits for the total number of Collections
const collectionMax = await searchListCollection(0, 0);
// Get all the collections
const collectionData = await searchListCollection(collectionMax.nbHits, page);
const loadMoreData = async (cursor) => {
const collectionData = await listCollection({ cursor, limit: 10 }); // Adjust the limit as needed
return collectionData;
};

const page = 0;
let cursor = null;

// Event listener to detect scroll and load more data when at the bottom
dropdownSelect.addEventListener('scroll', async () => {
if (dropdownSelect.scrollTop + dropdownSelect.clientHeight >= dropdownSelect.scrollHeight) {
const moreData = await loadMoreData(cursor);
if (moreData.items.length > 0) {
// Update the cursor for the next load
cursor = moreData.cursor;

// Populate the options in the dropdown from the additional data
moreData.items.forEach((collection) => {
const option = document.createElement('option');
option.value = collection.id;
option.textContent = collection.title;
dropdownSelect.appendChild(option);
});
}
}
});

// Initial data loading
const initialData = await loadMoreData(page);
const initialData = await loadMoreData(cursor);
if (initialData.items.length > 0) {
// Update the cursor for the next load
cursor = initialData.cursor;

// Populate the options in the dropdown with the initial data
initialData.items.forEach((collection) => {
const option = document.createElement('option');
Expand Down Expand Up @@ -140,7 +160,6 @@ export async function openModal(items) {
const { etag } = collection;
patchCollection(collectionId, etag, payload);
});

resetDialogState();
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/adp-collection-header/adp-collection-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
selectAllAssets, deselectAllAssets,
} from '../adp-infinite-results-collection/adp-infinite-results-collection.js';


Check failure on line 10 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed
function createCollectionInfoHeader(collectionInfoHeader, collection) {
// include back to collections listing similar to hide filters button
collectionInfoHeader.innerHTML = `
Expand Down Expand Up @@ -47,11 +47,11 @@
backButton.href = createLinkHref(backButton.href);

document.getElementById('select-all-checkbox').addEventListener('click', (event) => {
event.target.checked ? selectAllAssets() : deselectAllAssets();

Check failure on line 50 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 4 spaces but found 6

Check failure on line 50 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Expected an assignment or function call and instead saw an expression
});

document.getElementById('shareButton').addEventListener('click', (event) => {

Check failure on line 53 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

'event' is defined but never used
copyCurrentUrlToClipboard();

Check failure on line 54 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 4 spaces but found 6
});

collectionInfoHeader.querySelector('.action-collection-delete').addEventListener('click', async (e) => {
Expand All @@ -62,7 +62,7 @@
'Delete collection',
`Are you sure you want to delete the collection "${collection.title}"?`,
async () => {
await deleteCollection(collectionId, collection.title, collection.etag);
await deleteCollection(collectionId, collection.title);
navigateTo(createLinkHref('/collections'));
},
'Proceed',
Expand All @@ -86,8 +86,8 @@
// This function is called when the "Share" button is clicked
function copyCurrentUrlToClipboard() {
// Create a dummy input to copy the string
const dummy = document.createElement('input'),

Check failure on line 89 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Split 'const' declarations into multiple statements
text = window.location.href; // Get the current URL

Check failure on line 90 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 4 spaces but found 8
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
Expand All @@ -95,7 +95,7 @@
document.body.removeChild(dummy);

// Here you can also trigger any feedback to the user, like a tooltip or toast
//alert('URL copied to clipboard!'); // For demonstration purposes, using an alert

Check failure on line 98 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Expected exception block, space or tab after '//' in comment
showToast();
}

Expand All @@ -114,5 +114,5 @@
// Add "show" class again in case it was removed
toast.className = "toast show";
// Set a timeout to hide the toast after 3 seconds
setTimeout(function() { closeToast(); }, 3000);

Check warning on line 117 in blocks/adp-collection-header/adp-collection-header.js

View workflow job for this annotation

GitHub Actions / build

Unexpected unnamed function
}
19 changes: 7 additions & 12 deletions blocks/adp-infinite-results-collections/CollectionsDatasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@ import { createLinkHref, navigateTo } from '../../scripts/scripts.js';
import {
getCollectionID,
getCollectionTitle,
searchListCollection,
listCollection,
} from '../../scripts/collections.js';
import { createCollectionCardElement } from '../../scripts/card-html-builder.js';

export default class CollectionsDatasource {
cursor;
infiniteResultsContainer = null;

container = null;

pageNumber = 0;

lastPage = false;

async showMore() {

const list = await searchListCollection(5, this.pageNumber);
const list = await listCollection(5, this.cursor);
this.cursor = list.cursor;

this.pageNumber += 1;

if (this.pageNumber >= list.nbPages){
this.lastPage = true;
}

this.infiniteResultsContainer.resultsCallback(
this.container,
list.items,
Expand All @@ -37,14 +32,14 @@ export default class CollectionsDatasource {
}

isLastPage() {
return this.lastPage;
return !this.cursor;
}

async registerResultsCallback(container, infiniteResultsContainer) {
this.infiniteResultsContainer = infiniteResultsContainer;
this.container = container;

const list = await searchListCollection(5, this.pageNumber);
const list = await listCollection(5, this.cursor);
this.cursor = list.cursor;

infiniteResultsContainer.resultsCallback(
container,
Expand Down
Loading
Loading