Added basic state with selections
This commit is contained in:
@@ -62,6 +62,28 @@ const getMediaCleanerMoviesTitle = async () => {
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const selectedMovies = new Set();
|
||||
const selectedTvShows = new Set();
|
||||
|
||||
const createCheckbox = (mediaInfo = {}, state = []) => {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.dataset.mediaInfo = JSON.stringify(mediaInfo) || '';
|
||||
|
||||
checkbox.addEventListener('change', (e) => {
|
||||
const mediaInfo = checkbox.dataset.mediaInfo || '(no info)';
|
||||
if (checkbox.checked) {
|
||||
state.add(mediaInfo);
|
||||
} else {
|
||||
state.delete(mediaInfo);
|
||||
}
|
||||
// Update UI or state — use console.log for debugging
|
||||
console.log('selected:', Array.from(state));
|
||||
});
|
||||
|
||||
return checkbox;
|
||||
};
|
||||
|
||||
const populateTables = async () => {
|
||||
var moviesInfo = await getMediaCleanerMovieInfo();
|
||||
var seriesInfo = await getMediaCleanerSeriesInfo();
|
||||
@@ -78,9 +100,7 @@ const populateTables = async () => {
|
||||
var cell1 = row.insertCell(0);
|
||||
var cell2 = row.insertCell(1);
|
||||
cell1.innerHTML = moviesInfo[i].Name;
|
||||
// Will need to be enabled once radarr and sonarr integration is enabled.
|
||||
// Maybe change this to an element to remove hard coding.
|
||||
cell2.innerHTML = "<input type=\"checkbox\" disabled />";
|
||||
cell2.appendChild(createCheckbox(moviesInfo[i], selectedMovies));
|
||||
cell2.className = "actions-cell";
|
||||
}
|
||||
}
|
||||
@@ -100,9 +120,7 @@ const populateTables = async () => {
|
||||
var cell3 = row.insertCell(2);
|
||||
cell1.innerHTML = seriesInfo[i].Name;
|
||||
cell2.innerHTML = seriesInfo[i].Seasons.map(season => season.replace("Season ", "")).join(", ");
|
||||
// Will need to be enabled once radarr and sonarr integration is enabled.
|
||||
// Maybe change this to an element to remove hard coding.
|
||||
cell3.innerHTML = "<input type=\"checkbox\" disabled />";
|
||||
cell3.appendChild(createCheckbox(seriesInfo[i], selectedTvShows));
|
||||
cell3.className = "actions-cell";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user