Skip to content

Commit

Permalink
implemented search sort #130
Browse files Browse the repository at this point in the history
  • Loading branch information
n-ce committed Oct 5, 2023
1 parent 0bb17ca commit 29ba7f5
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 20 deletions.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<img height="100%" width="100%" crossorigin="anonymous" alt="Current Playing Media Thumbnail">

<div id="metadata">
<a id="title" href="" target="_blank">ytify 6.1</a>
<a id="title" href="" target="_blank">ytify 6.2</a>
<a id="author" href="" target="_blank">Channel</a>
<select id="bitrateSelector">
<option value="">Bitrate</option>
Expand Down Expand Up @@ -127,10 +127,15 @@ <h1 align="center">upcoming streams show here</h1>
<button aria-label="search" class="ri-search-2-line"></button>
</span>
<ul id="suggestions"></ul>
<div id="sort">
<toggle-switch id="sortByTime">Sort By Time&nbsp;&nbsp;</toggle-switch>
</div>
<div id="searchlist">
<h1>search results show here</h1>
</div>
<button id="loadMore">Load More</button>
<br>
<br>
</section>


Expand Down
1 change: 1 addition & 0 deletions src/components/toggleSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ customElements.define('toggle-switch', class extends HTMLElement {

this.addEventListener('click', () => {
input.checked = !input.checked;
this.toggleAttribute('checked');
});

label.append(input, document.createElement('span'));
Expand Down
41 changes: 30 additions & 11 deletions src/scripts/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ import { getSaved, save, itemsLoader, idFromURL, params } from "../lib/utils";

const searchlist = <HTMLDivElement>document.getElementById('searchlist');
const searchFilters = <HTMLSelectElement>document.getElementById('searchFilters');
const sortSwitch = <HTMLElement>document.getElementById('sortByTime');
const loadMoreBtn = <HTMLButtonElement>document.getElementById('loadMore');

let token = '';

loadMoreBtn.addEventListener('click', () => {
if (token)
fetch(
`${pipedInstances.value}/nextpage/search?nextpage=${encodeURIComponent(token)}&q=${superInput.value}&filter=${searchFilters.value}`
)
.then(res => res.json())
.then(data => {
token = data.nextpage;
searchlist.appendChild(itemsLoader(data.items));
})
const loadMoreResults = async () =>
fetch(
`${pipedInstances.value}/nextpage/search?nextpage=${encodeURIComponent(token)}&q=${superInput.value}&filter=${searchFilters.value}`
).then(res => res.json())


loadMoreBtn.addEventListener('click', async () => {
if (!token) return;
const data = await loadMoreResults();
token = data.nextpage;
searchlist.appendChild(itemsLoader(data.items));

});



// Get search results of input

const searchLoader = () => {
Expand All @@ -33,9 +37,21 @@ const searchLoader = () => {

fetch(pipedInstances.value + '/search?q=' + text + '&filter=' + searchFilters.value)
.then(res => res.json())
.then(searchResults => {
.then(async searchResults => {
token = searchResults.nextpage;
loadMoreBtn.style.display = 'block';

if (sortSwitch.hasAttribute('checked')) {
for (let i = 0; i < 3; i++) {
const data = await loadMoreResults();
token = data.nextpage;
searchResults.items = searchResults.items.concat(data.items);
}
searchResults.items.sort((
a: { uploaded: number },
b: { uploaded: number }
) => b.uploaded - a.uploaded);
}
searchlist.appendChild(
itemsLoader(
searchResults.items
Expand All @@ -61,6 +77,9 @@ const searchLoader = () => {
}


sortSwitch.addEventListener('click', searchLoader);


// super input supports both searching and direct link, also loads suggestions

let prevID: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/scripts/superModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ dlSelector.addEventListener('change', () => {

if (itag)
open(link);
dlSelector.innerHTML = '<option>Download</option>';
});


Expand Down
3 changes: 1 addition & 2 deletions src/stylesheets/footer.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
footer {
display: flex;
height: 20%;
height: 19%;
width: 100%;
border-radius: var(--roundness);
background-color: var(--onBg);
Expand All @@ -10,7 +10,6 @@ footer {
flex-direction: column;
box-shadow: var(--shadow);
overflow: hidden;
margin: -1.5vmin 0;
}

footer>span {
Expand Down
2 changes: 1 addition & 1 deletion src/stylesheets/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ img {

@media(orientation:portrait) {
img {
height: 50vw;
height: 52vw;
width: auto;
}

Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ nav a.active {
nav {
height: auto;
justify-content: space-around;
width: 90%;
padding: 5%;
width: 94%;
padding: 5% 3%;
padding-bottom: 0;
}

Expand Down
15 changes: 15 additions & 0 deletions src/stylesheets/search.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@
#suggestions li:focus {
background-color: #39FC;
color: #ADFD;
}


#sort {
height: 9vmin;
display: flex;
justify-content: space-around;
position: sticky;
top: calc(100% - 12vmin);
z-index: 3;
background-color: var(--bg);
padding: 0.5vmin 2vmin;
border: var(--border);
border-radius: calc(var(--roundness) + 0.5vmin);
box-shadow: var(--shadow);
}
10 changes: 7 additions & 3 deletions src/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ section.view {
}

main {
height: calc(100dvh - 10%);
width: 90%;
padding: 5%;
height: calc(100dvh - 6%);
width: 94%;
padding: 3%;
}

section {
Expand Down Expand Up @@ -196,6 +196,10 @@ playlist-item:hover {
display: none;
}

#searchlist {
margin-top: -10vmin;
}

#queuelist {
width: 100%;
height: 100%;
Expand Down

0 comments on commit 29ba7f5

Please sign in to comment.