Skip to content

Commit fc6e887

Browse files
committed
ui: download video button and animation while downloading..
1 parent 9a4830d commit fc6e887

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

client/components/video-element.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class VideoElement extends HTMLElement {
5252
else this.dataset['ignored'] = "false"
5353
this.innerHTML = /*html*/`
5454
${this.video.downloaded
55-
? /*html*/`<div class="play-video-placeholder" style="background-image: url(${this.video.thumbnail})"><div class="play-icon"></div></div>`
56-
: /*html*/`<img loading="lazy" src="${this.video.thumbnail}"/>`}
55+
? /*html*/`<div class="play video-placeholder" style="background-image: url(${this.video.thumbnail})"><div class="play-icon"></div></div>`
56+
: /*html*/`<div class="download video-placeholder" style="background-image: url(${this.video.thumbnail})"><div class="download-icon"></div></div>`}
5757
<span class="action ignore" tabindex="0">ignore</span>
5858
<div class="info">
5959
<span class="channel-name">${this.video.channelName}</span>
@@ -84,7 +84,8 @@ class VideoElement extends HTMLElement {
8484
handleClickAddListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))
8585
handleClickAddListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))
8686
handleClickAddListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))
87-
handleClickAddListener(this.querySelector('.play-video-placeholder'), this.watchVideoHandler.bind(this))
87+
handleClickAddListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))
88+
handleClickAddListener(this.querySelector('.download.video-placeholder'), this.downloadVideoHandler.bind(this))
8889
}
8990
unregisterEvents () {
9091
handleClickRemoveListener(this.querySelector('.action.download'), this.downloadVideoHandler.bind(this))
@@ -93,11 +94,13 @@ class VideoElement extends HTMLElement {
9394
handleClickRemoveListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))
9495
handleClickRemoveListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))
9596
handleClickRemoveListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))
97+
handleClickRemoveListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))
98+
handleClickRemoveListener(this.querySelector('.download.video-placeholder'), this.downloadVideoHandler.bind(this))
9699
this.querySelector('video') && this.unregisterVideoEvents(this.querySelector('video'))
97100
}
98101
watchVideoHandler (event) {
99102
event.preventDefault()
100-
this.querySelector('.play-video-placeholder').outerHTML = /*html*/`<video controls width="400">
103+
this.querySelector('.play.video-placeholder').outerHTML = /*html*/`<video controls width="400">
101104
<source src="/videos/${this.video.id}" type="video/mp4" />
102105
<track
103106
default
@@ -115,9 +118,14 @@ class VideoElement extends HTMLElement {
115118
}
116119
downloadVideoHandler (event) {
117120
event.preventDefault()
121+
118122
const downloadStartedText = '⚡️ Download started'
119-
if (event.target.innerText === downloadStartedText) return console.log('already downloading')
120-
event.target.innerText = downloadStartedText
123+
let $downloadButton = event.target.classList.contains('.action') ? event.target : this.querySelector('.action.download')
124+
if ($downloadButton.innerText === downloadStartedText) return console.log('already downloading')
125+
else $downloadButton.innerText = downloadStartedText
126+
127+
this.classList.add('downloading')
128+
121129
fetch('/api/download-video', {
122130
method: 'POST',
123131
headers: { 'Content-Type': 'application/json' },
@@ -137,6 +145,7 @@ class VideoElement extends HTMLElement {
137145
.then(() => {
138146
console.log('Video deleted')
139147
this.video.downloaded = false
148+
this.classList.remove('downloading')
140149
this.render()
141150
})
142151
.catch((error) => console.error('Error deleting video:', error))

client/main.css

+35-3
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ video-element, video-element video {
209209

210210

211211

212-
.play-video-placeholder:hover {
212+
.video-placeholder:hover {
213213
transform: scale(1.01);
214214
filter: drop-shadow(2px 4px 6px rgb(140, 138, 138));
215215
}
216-
.play-video-placeholder {
216+
.video-placeholder {
217217
transition: all .1s ease;
218218
}
219-
.play-video-placeholder {
219+
.video-placeholder {
220220
height: 225px;
221221
background-color: #ceaf80;
222222
background-size: cover;
@@ -246,6 +246,38 @@ video-element, video-element video {
246246
border-left: 30px solid rgb(255, 255, 255);
247247
}
248248

249+
.download-icon {
250+
position: relative;
251+
width: 0;
252+
height: 0;
253+
border-left: 20px solid transparent;
254+
border-right: 20px solid transparent;
255+
border-top: 30px solid rgb(0, 0, 0);
256+
z-index: 100;
257+
}
258+
.download-icon::after {
259+
z-index: 98;
260+
position: absolute;
261+
top: -28px;
262+
left: -26px;
263+
content: "";
264+
width: 0;
265+
height: 0;
266+
border-left: 20px solid transparent;
267+
border-right: 20px solid transparent;
268+
border-top: 30px solid rgb(255, 255, 255);
269+
}
270+
271+
.downloading .download-icon {
272+
/*wiggle up and down animation*/
273+
animation: wiggle 2s infinite ease-in-out;
274+
}
275+
@keyframes wiggle {
276+
0% { transform: translateY(0px); }
277+
50% { transform: translateY(-10px); }
278+
100% { transform: translateY(0px); }
279+
}
280+
249281

250282

251283

0 commit comments

Comments
 (0)