Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandrbig1 committed Aug 11, 2023
1 parent af2cb04 commit 69f00de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 44 deletions.
40 changes: 6 additions & 34 deletions src/js/02-video.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
import Player from '@vimeo/player';
import throttle from 'lodash.throttle';

const KEY_STORAGE = 'videoplayer-current-time';

const iframe = document.querySelector('iframe');
iframe.style.margin = '20px auto';
iframe.style.display = 'flex';

const player = new Player(iframe);
const throttle = require('lodash.throttle');

player.on('play', function () {
console.log('played the video!');
});

player.getVideoTitle().then(function (title) {
console.log('title:', title);
});
player.on('timeupdate', throttle(updatingTimeLocalStorage, 1000));

player.on('timeupdate', throttle(updateingTimeLocalStorage, 1000));

function updateingTimeLocalStorage(data) {
{
duration: 61.857;
percent: 0.049;
seconds: 3.034;
}
localStorage.setItem('videoplayer-current-time', data.seconds);
// data is an object containing properties specific to that event
function updatingTimeLocalStorage({ seconds }) {
localStorage.setItem(KEY_STORAGE, seconds);
}

player
.setCurrentTime(localStorage.getItem('videoplayer-current-time'))
.then(function (seconds) {
// seconds = the actual time that the player seeked to
})
.catch(function (error) {
switch (error.name) {
case 'RangeError':
// the time was less than 0 or greater than the video’s duration
break;

default:
// some other error occurred
break;
}
});
player.setCurrentTime(localStorage.getItem(KEY_STORAGE));
27 changes: 17 additions & 10 deletions src/js/03-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@ import throttle from 'lodash.throttle';

const STORAGE_KEY = 'feedback-form-state';

const throttle = require('lodash.throttle');

const formEl = document.querySelector('.feedback-form');
const inputEl = formEl[(name = 'email')];
const textAreaEl = formEl[(name = 'message')];

const allData = {};

savedStorageValue();

formEl.addEventListener('submit', onSubmitHandler);
formEl.addEventListener('input', throttle(onTextarealHandler, 500));

function onSubmitHandler(e) {
e.preventDefault();
console.log(textAreaEl.value);
console.log(inputEl.value);
const savedText = JSON.parse(localStorage.getItem(STORAGE_KEY));
console.log(savedText);
e.currentTarget.reset();
localStorage.removeItem(STORAGE_KEY);
}

function onTextarealHandler(e) {
localStorage.setItem(STORAGE_KEY, e.target.value);
localStorage.setItem(STORAGE_KEY, JSON.stringify(allData));
allData[e.target.name] = e.target.value;
localStorage.setItem(STORAGE_KEY, JSON.stringify(allData));
}

function savedStorageValue() {
const savedText = localStorage.getItem(STORAGE_KEY);
const savedText = JSON.parse(localStorage.getItem(STORAGE_KEY));

if (savedText) {
const textAreaSaved = JSON.parse(savedText);
textAreaEl.value = textAreaSaved.message;
inputEl.value = textAreaSaved.email;
if (savedText.message) {
textAreaEl.value = savedText.message;
}
if (savedText.email) {
inputEl.value = savedText.email;
}

// JSON.parse(savedText).message
// ? (textAreaEl.value = JSON.parse(savedText).message)
// : '';
// JSON.parse(savedText).email
// ? (inputEl.value = JSON.parse(savedText).email)
// : '';
}
}

0 comments on commit 69f00de

Please sign in to comment.