UI update

This commit is contained in:
sairaj mote 2021-06-19 18:15:04 +05:30
parent 01c0a18120
commit fc2aaea3a4
4 changed files with 148 additions and 60 deletions

View File

@ -381,12 +381,14 @@ ul {
display: grid; display: grid;
gap: 0.5rem; gap: 0.5rem;
padding-bottom: 4rem; padding-bottom: 4rem;
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
} }
.torrent-card { .torrent-card {
display: flex; display: grid;
flex-direction: column; gap: 0 1rem;
align-items: center;
grid-template-columns: auto 1fr auto;
grid-template-areas: "icon title button" "icon tags button";
cursor: pointer; cursor: pointer;
padding: 1rem; padding: 1rem;
border-radius: 0.3rem; border-radius: 0.3rem;
@ -395,26 +397,14 @@ ul {
} }
.torrent-card__icon { .torrent-card__icon {
grid-area: icon; grid-area: icon;
display: flex;
padding: 0.6rem;
border-radius: 50%;
margin-bottom: 1.5rem;
align-items: center;
justify-content: center;
align-self: flex-start;
aspect-ratio: 1/1;
flex-shrink: 0;
background-color: var(--accent-color);
} }
.torrent-card__icon .icon { .torrent-card__icon .icon {
height: 1.6rem; height: 1.6rem;
width: 1.6rem; width: 1.6rem;
fill: white;
} }
.torrent-card__title { .torrent-card__title {
grid-area: title; grid-area: title;
font-size: 1.2rem; font-size: 1.1rem;
margin-bottom: 0.5rem;
} }
.torrent-card__tags { .torrent-card__tags {
grid-area: tags; grid-area: tags;
@ -422,7 +412,6 @@ ul {
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
font-size: 0.85rem; font-size: 0.85rem;
margin-bottom: 1.5rem;
color: rgba(var(--text-color), 0.7); color: rgba(var(--text-color), 0.7);
} }
.torrent-card__description { .torrent-card__description {
@ -439,8 +428,7 @@ ul {
.torrent-card__download-button { .torrent-card__download-button {
grid-area: button; grid-area: button;
justify-self: flex-end; justify-self: flex-end;
margin-top: auto; align-self: flex-start;
justify-content: center;
background-color: rgba(var(--text-color), 0.1); background-color: rgba(var(--text-color), 0.1);
} }
.torrent-card__download-button .icon { .torrent-card__download-button .icon {
@ -452,16 +440,62 @@ ul {
--width: min(42rem, 100%); --width: min(42rem, 100%);
} }
.torrent-type-icon {
display: flex;
padding: 1rem;
border-radius: 50%;
align-items: center;
justify-content: center;
align-self: flex-start;
aspect-ratio: 1/1;
flex-shrink: 0;
background-color: var(--accent-color);
}
.torrent-type-icon .icon {
fill: white;
}
#torrent_type_icon {
grid-area: icon;
margin-bottom: 1rem;
}
#torrent_type_icon .icon {
height: 2rem;
width: 2rem;
}
#torrent_name {
margin-bottom: 1rem;
}
#torrent__description {
font-size: 0.9rem;
color: rgba(var(--text-color), 0.8);
}
#torrent_download_button {
color: white;
margin-top: 2rem;
background-color: var(--accent-color);
width: 100%;
justify-content: center;
padding: 1rem;
}
#torrent_download_button .icon {
fill: white;
}
#main_footer { #main_footer {
padding: 3rem 0; padding: 3rem 0;
background-color: rgba(var(--text-color), 0.06); background-color: rgba(var(--text-color), 0.06);
} }
@media only screen and (max-width: 640px) { @media only screen and (max-width: 640px) {
.popup__header {
padding: 0 1.5rem;
}
.torrent-card { .torrent-card {
display: grid;
gap: 0 1rem;
align-items: center;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
grid-template-areas: "icon title" "icon tags" "icon button"; grid-template-areas: "icon title" "icon tags" "icon button";
} }
@ -469,7 +503,7 @@ ul {
margin: 0; margin: 0;
} }
.torrent-card__title { .torrent-card__title {
font-size: 1.1rem; font-size: 1rem;
} }
.torrent-card__tags { .torrent-card__tags {
margin-bottom: 0; margin-bottom: 0;
@ -483,6 +517,10 @@ ul {
} }
} }
@media only screen and (min-width: 640px) { @media only screen and (min-width: 640px) {
.popup__header {
padding: 1.5rem 1.5rem 0 1.5rem;
}
.page-layout { .page-layout {
grid-template-columns: 1fr 90vw 1fr; grid-template-columns: 1fr 90vw 1fr;
} }
@ -493,7 +531,6 @@ ul {
.torrent-card { .torrent-card {
padding: 1.5rem; padding: 1.5rem;
min-height: 22rem;
} }
} }
@media only screen and (min-width: 1280px) { @media only screen and (min-width: 1280px) {

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -327,11 +327,14 @@ ul{
display: grid; display: grid;
gap: 0.5rem; gap: 0.5rem;
padding-bottom: 4rem; padding-bottom: 4rem;
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); // grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
} }
.torrent-card{ .torrent-card{
display: flex; display: grid;
flex-direction: column; gap: 0 1rem;
align-items: center;
grid-template-columns: auto 1fr auto;
grid-template-areas: 'icon title button' 'icon tags button';
cursor: pointer; cursor: pointer;
padding: 1rem; padding: 1rem;
border-radius: 0.3rem; border-radius: 0.3rem;
@ -339,26 +342,14 @@ ul{
background-color: rgba(var(--text-color), 0.06); background-color: rgba(var(--text-color), 0.06);
&__icon{ &__icon{
grid-area: icon; grid-area: icon;
display: flex;
padding: 0.6rem;
border-radius: 50%;
margin-bottom: 1.5rem;
align-items: center;
justify-content: center;
align-self: flex-start;
aspect-ratio: 1/1;
flex-shrink: 0;
background-color: var(--accent-color);
.icon{ .icon{
height: 1.6rem; height: 1.6rem;
width: 1.6rem; width: 1.6rem;
fill: white;
} }
} }
&__title{ &__title{
grid-area: title; grid-area: title;
font-size: 1.2rem; font-size: 1.1rem;
margin-bottom: 0.5rem;
} }
&__tags{ &__tags{
grid-area: tags; grid-area: tags;
@ -366,7 +357,6 @@ ul{
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
font-size: 0.85rem; font-size: 0.85rem;
margin-bottom: 1.5rem;
color: rgba(var(--text-color), 0.7); color: rgba(var(--text-color), 0.7);
} }
&__description{ &__description{
@ -383,8 +373,7 @@ ul{
&__download-button{ &__download-button{
grid-area: button; grid-area: button;
justify-self: flex-end; justify-self: flex-end;
margin-top: auto; align-self: flex-start;
justify-content: center;
background-color: rgba(var(--text-color), 0.1); background-color: rgba(var(--text-color), 0.1);
.icon{ .icon{
height: 1.4rem; height: 1.4rem;
@ -395,22 +384,62 @@ ul{
#torrent_popup{ #torrent_popup{
--width: min(42rem, 100%); --width: min(42rem, 100%);
} }
.torrent-type-icon{
display: flex;
padding: 1rem;
border-radius: 50%;
align-items: center;
justify-content: center;
align-self: flex-start;
aspect-ratio: 1/1;
flex-shrink: 0;
background-color: var(--accent-color);
.icon{
fill: white;
}
}
#torrent_type_icon{
grid-area: icon;
margin-bottom: 1rem;
.icon{
height: 2rem;
width: 2rem;
}
}
#torrent_name{
margin-bottom: 1rem;
}
#torrent__description{
font-size: 0.9rem;
color: rgba(var(--text-color), 0.8);
}
#torrent_download_button{
color: white;
margin-top: 2rem;
background-color: var(--accent-color);
width: 100%;
justify-content: center;
padding: 1rem;
.icon{
fill: white;
}
}
#main_footer{ #main_footer{
padding: 3rem 0; padding: 3rem 0;
background-color: rgba(var(--text-color), 0.06); background-color: rgba(var(--text-color), 0.06);
} }
@media only screen and (max-width: 640px) { @media only screen and (max-width: 640px) {
.popup__header{
padding: 0 1.5rem;
}
.torrent-card{ .torrent-card{
display: grid;
gap: 0 1rem;
align-items: center;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
grid-template-areas: 'icon title' 'icon tags' 'icon button'; grid-template-areas: 'icon title' 'icon tags' 'icon button';
&__icon{ &__icon{
margin: 0; margin: 0;
} }
&__title{ &__title{
font-size: 1.1rem; font-size: 1rem;
} }
&__tags{ &__tags{
margin-bottom: 0; margin-bottom: 0;
@ -425,6 +454,9 @@ ul{
} }
} }
@media only screen and (min-width: 640px) { @media only screen and (min-width: 640px) {
.popup__header{
padding: 1.5rem 1.5rem 0 1.5rem;
}
.page-layout{ .page-layout{
grid-template-columns: 1fr 90vw 1fr; grid-template-columns: 1fr 90vw 1fr;
} }
@ -433,7 +465,6 @@ ul{
} }
.torrent-card{ .torrent-card{
padding: 1.5rem; padding: 1.5rem;
min-height: 22rem;
} }
} }
@media only screen and (min-width: 1280px) { @media only screen and (min-width: 1280px) {

View File

@ -27,11 +27,17 @@
<sm-popup id="torrent_popup"> <sm-popup id="torrent_popup">
<header slot="header" class="popup__header"> <header slot="header" class="popup__header">
<button class="popup__header__close" onclick="this.closest('sm-popup').hide()"> <button class="popup__header__close" onclick="this.closest('sm-popup').hide()">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></svg> <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M7.828 11H20v2H7.828l5.364 5.364-1.414 1.414L4 12l7.778-7.778 1.414 1.414z"/></svg>
</button> </button>
</header> </header>
<div id="torrent_type_icon" class="torrent-type-icon"></div>
<div id="torrent_tags"></div>
<h1 id="torrent_name"></h1> <h1 id="torrent_name"></h1>
<p id="torrent_description"></p> <p id="torrent_description"></p>
<button id="torrent_download_button" class="torrent-card__download-button" onclick="downloadTorrent(currentTorrent.filename, currentTorrent.startTx, currentTorrent.chunks)">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16 2l5 5v14.008a.993.993 0 0 1-.993.992H3.993A1 1 0 0 1 3 21.008V2.992C3 2.444 3.445 2 3.993 2H16zm-3 10V8h-2v4H8l4 4 4-4h-3z"/></svg>
Get torrent
</button>
</sm-popup> </sm-popup>
<header id="main_header"> <header id="main_header">
<div class="flex align-center"> <div class="flex align-center">
@ -61,7 +67,7 @@
</footer> </footer>
<template id="torrent_card_template"> <template id="torrent_card_template">
<li class="torrent-card interact"> <li class="torrent-card interact">
<div class="torrent-card__icon"></div> <div class="torrent-card__icon torrent-type-icon"></div>
<h3 class="torrent-card__title"></h3> <h3 class="torrent-card__title"></h3>
<span class="torrent-card__tags"></span> <span class="torrent-card__tags"></span>
<!-- <p class="torrent-card__description"></p> --> <!-- <p class="torrent-card__description"></p> -->
@ -723,14 +729,26 @@
window.addEventListener('load', e => { window.addEventListener('load', e => {
showLatestTorrents() showLatestTorrents()
}) })
let currentTorrent
getRef('torrent_container').addEventListener('click', async e => { getRef('torrent_container').addEventListener('click', async e => {
if(e.target.closest('.torrent-card__download-button')){ if(e.target.closest('.torrent-card__download-button')){
const _target = e.target.closest('.torrent-card__download-button') const _target = e.target.closest('.torrent-card__download-button')
const card = _target.closest('.torrent-card') const card = _target.closest('.torrent-card')
const cardId = parseInt(card.id) const cardId = parseInt(card.id)
const {filename, chunks, startTx} = await getDataFromIDB(cardId)
downloadTorrent(filename, startTx, chunks) downloadTorrent(filename, startTx, chunks)
} }
else if(e.target.closest('.torrent-card')){
const card = e.target.closest('.torrent-card')
const cardId = parseInt(card.id)
currentTorrent = await getDataFromIDB(cardId)
const {id, name, description, tags, type = 'misc', size, uploader, startTx, filename, chunks} = currentTorrent
getRef('torrent_type_icon').innerHTML = getIcon(type)
getRef('torrent_name').textContent = name
getRef('torrent_description').textContent = description
getRef('torrent_tags').textContent = tags.split('/').join('•')
getRef('torrent_popup').show()
}
}) })
const render = { const render = {
torrentCard(obj){ torrentCard(obj){
@ -738,11 +756,16 @@
const card = getRef('torrent_card_template').content.cloneNode(true).firstElementChild const card = getRef('torrent_card_template').content.cloneNode(true).firstElementChild
card.id = id card.id = id
card.querySelector('.torrent-card__title').textContent = name card.querySelector('.torrent-card__title').textContent = name
card.querySelector('.torrent-card__tags').textContent = tags card.querySelector('.torrent-card__tags').textContent = tags.split('/').join('•')
// card.querySelector('.torrent-card__description').textContent = description // card.querySelector('.torrent-card__description').textContent = description
// card.querySelector('.torrent-card__size').textContent = size // card.querySelector('.torrent-card__size').textContent = size
let icon card.querySelector('.torrent-card__icon').innerHTML = getIcon(type)
switch(type.toLowerCase()){ return card
}
}
function getIcon(type){
let icon
switch(type.toLowerCase()){
case 'movie': case 'movie':
icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M17.998 7l2.31-4h.7c.548 0 .992.445.992.993v16.014a1 1 0 0 1-.992.993H2.992A.993.993 0 0 1 2 20.007V3.993A1 1 0 0 1 2.992 3h3.006l-2.31 4h2.31l2.31-4h3.69l-2.31 4h2.31l2.31-4h3.69l-2.31 4h2.31z"/></svg>` icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M17.998 7l2.31-4h.7c.548 0 .992.445.992.993v16.014a1 1 0 0 1-.992.993H2.992A.993.993 0 0 1 2 20.007V3.993A1 1 0 0 1 2.992 3h3.006l-2.31 4h2.31l2.31-4h3.69l-2.31 4h2.31l2.31-4h3.69l-2.31 4h2.31z"/></svg>`
break break
@ -770,11 +793,8 @@
default : default :
icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16 2l5 5v14.008a.993.993 0 0 1-.993.992H3.993A1 1 0 0 1 3 21.008V2.992C3 2.444 3.445 2 3.993 2H16zm-5 13v2h2v-2h-2zm2-1.645A3.502 3.502 0 0 0 12 6.5a3.501 3.501 0 0 0-3.433 2.813l1.962.393A1.5 1.5 0 1 1 12 11.5a1 1 0 0 0-1 1V14h2v-.645z"/></svg>` icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16 2l5 5v14.008a.993.993 0 0 1-.993.992H3.993A1 1 0 0 1 3 21.008V2.992C3 2.444 3.445 2 3.993 2H16zm-5 13v2h2v-2h-2zm2-1.645A3.502 3.502 0 0 0 12 6.5a3.501 3.501 0 0 0-3.433 2.813l1.962.393A1.5 1.5 0 1 1 12 11.5a1 1 0 0 0-1 1V14h2v-.645z"/></svg>`
break break
} }
card.querySelector('.torrent-card__icon').innerHTML = icon return icon
return card
}
} }
function renderTorrents(torrents){ function renderTorrents(torrents){
const torrentsFrag = document.createDocumentFragment() const torrentsFrag = document.createDocumentFragment()
@ -786,7 +806,7 @@
async function showLatestTorrents(){ async function showLatestTorrents(){
getRef('torrent_container').innerHTML = `` getRef('torrent_container').innerHTML = ``
let allTorrents = await getTorrents() let allTorrents = await getTorrents()
allTorrents = allTorrents.reverse().slice(0, 8) allTorrents = allTorrents.reverse().slice(0, 50)
getRef('torrent_container').append(renderTorrents(allTorrents)) getRef('torrent_container').append(renderTorrents(allTorrents))
} }
</script> </script>