update db a frontend
This commit is contained in:
parent
2f0a06e2ed
commit
a77323d2df
@ -45,9 +45,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Pripojenie skriptov -->
|
<!-- Pripojenie skriptov -->
|
||||||
|
<script type="module" src="videoplayer.js"></script>
|
||||||
<script src="kontrola_api.js"></script>
|
<script src="kontrola_api.js"></script>
|
||||||
<script src="speech_recognition.js"></script>
|
<script src="speech_recognition.js"></script>
|
||||||
<script src="videoplayer.js"></script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -39,7 +39,7 @@ h1 {
|
|||||||
width: 45%;
|
width: 45%;
|
||||||
max-width: 600px;
|
max-width: 600px;
|
||||||
min-width: 350px;
|
min-width: 350px;
|
||||||
box-sizing: border-box; /* Include padding and borders in the element’s dimensions */
|
box-sizing: border-box; /* Include padding and borders in the element’s dimensions */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Styling for the buttons above the textarea */
|
/* Styling for the buttons above the textarea */
|
||||||
@ -309,4 +309,4 @@ textarea.dark-mode:focus {
|
|||||||
#themeToggleBtn {
|
#themeToggleBtn {
|
||||||
font-size: 20px; /* Decrease theme toggle button size for mobile */
|
font-size: 20px; /* Decrease theme toggle button size for mobile */
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,20 +3,23 @@ const supabaseUrl = 'https://manesldshonpegglmyan.supabase.co'
|
|||||||
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1hbmVzbGRzaG9ucGVnZ2xteWFuIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTczMDcxNzQ2NCwiZXhwIjoyMDQ2MjkzNDY0fQ.saaJeTtwYZCS3YKJYmQsAOSAEFzUVUJnoJSD8-lgLHo'
|
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1hbmVzbGRzaG9ucGVnZ2xteWFuIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTczMDcxNzQ2NCwiZXhwIjoyMDQ2MjkzNDY0fQ.saaJeTtwYZCS3YKJYmQsAOSAEFzUVUJnoJSD8-lgLHo'
|
||||||
const supabase = createClient(supabaseUrl, supabaseKey)
|
const supabase = createClient(supabaseUrl, supabaseKey)
|
||||||
|
|
||||||
|
// Select DOM elements
|
||||||
const inputText = document.getElementById('inputText');
|
const inputText = document.getElementById('inputText');
|
||||||
const videoPlayer = document.getElementById('translationVideo');
|
const videoPlayer = document.getElementById('translationVideo');
|
||||||
const translateWordsBtn = document.getElementById('translateWordsBtn');
|
const translateWordsBtn = document.getElementById('translateWordsBtn');
|
||||||
const translateLettersBtn = document.getElementById('translateLettersBtn');
|
const translateLettersBtn = document.getElementById('translateLettersBtn');
|
||||||
const prevBtn = document.getElementById('prevBtn');
|
const prevBtn = document.getElementById('prevBtn');
|
||||||
const nextBtn = document.getElementById('nextBtn');
|
const nextBtn = document.getElementById('nextBtn');
|
||||||
const translateBtn = document.getElementById('translateBtn');
|
const translateBtn = document.getElementById('translateBtn'); // Prelož button
|
||||||
const statusText = document.getElementById('statusText');
|
const statusText = document.getElementById('statusText');
|
||||||
|
|
||||||
|
// Translation state variables
|
||||||
let videoSequence = [];
|
let videoSequence = [];
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
let autoPlayEnabled = true;
|
let autoPlayEnabled = true;
|
||||||
let currentTranslationMode = 'words';
|
let currentTranslationMode = 'words'; // Default mode
|
||||||
|
|
||||||
|
// Function to check if video exists (for local testing)
|
||||||
async function videoExists(src) {
|
async function videoExists(src) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const video = document.createElement('video');
|
const video = document.createElement('video');
|
||||||
@ -26,21 +29,29 @@ async function videoExists(src) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to fetch video URL from Supabase by label (for word translation)
|
||||||
async function fetchVideoUrl(word) {
|
async function fetchVideoUrl(word) {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('Videa')
|
.from('Videa')
|
||||||
.select('video_url')
|
.select('video_url')
|
||||||
.eq('label', word)
|
.eq('label', word)
|
||||||
.maybeSingle();
|
.maybeSingle(); // Use maybeSingle() instead of single()
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error fetching video:', error);
|
console.error('Error fetching video:', error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
console.warn(`No video found for word: ${word}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return data.video_url;
|
return data.video_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Function to load video sequence by words using Supabase
|
||||||
async function loadVideoSequenceByWords() {
|
async function loadVideoSequenceByWords() {
|
||||||
const words = inputText.value.trim().split(' ');
|
const words = inputText.value.trim().split(' ');
|
||||||
videoSequence = [];
|
videoSequence = [];
|
||||||
@ -59,7 +70,7 @@ async function fetchLetterVideoUrl(letter) {
|
|||||||
.from('Videa')
|
.from('Videa')
|
||||||
.select('video_url')
|
.select('video_url')
|
||||||
.eq('label', letter)
|
.eq('label', letter)
|
||||||
.maybeSingle();
|
.maybeSingle(); // Use maybeSingle() for letters
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error fetching video for letter:', letter, error);
|
console.error('Error fetching video for letter:', letter, error);
|
||||||
@ -74,6 +85,7 @@ async function fetchLetterVideoUrl(letter) {
|
|||||||
return data.video_url;
|
return data.video_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to load video sequence by letters using Supabase
|
||||||
async function loadVideoSequenceByLetters() {
|
async function loadVideoSequenceByLetters() {
|
||||||
const characters = inputText.value.trim().split('');
|
const characters = inputText.value.trim().split('');
|
||||||
videoSequence = [];
|
videoSequence = [];
|
||||||
@ -89,6 +101,7 @@ async function loadVideoSequenceByLetters() {
|
|||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to play video at a specific index
|
||||||
function playVideoAtIndex(index) {
|
function playVideoAtIndex(index) {
|
||||||
if (index < 0 || index >= videoSequence.length) return;
|
if (index < 0 || index >= videoSequence.length) return;
|
||||||
|
|
||||||
@ -96,6 +109,7 @@ function playVideoAtIndex(index) {
|
|||||||
videoPlayer.play();
|
videoPlayer.play();
|
||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
|
|
||||||
|
// Update the title with the current word or letter
|
||||||
const currentLabel = videoSequence[index].split('/').pop().split('.')[0];
|
const currentLabel = videoSequence[index].split('/').pop().split('.')[0];
|
||||||
document.getElementById('currentLetter').innerText = currentLabel.toUpperCase();
|
document.getElementById('currentLetter').innerText = currentLabel.toUpperCase();
|
||||||
|
|
||||||
@ -113,9 +127,11 @@ function playVideoAtIndex(index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Event listener for "Prelož" button (Translate button)
|
||||||
translateBtn.addEventListener('click', async () => {
|
translateBtn.addEventListener('click', async () => {
|
||||||
autoPlayEnabled = true;
|
autoPlayEnabled = true;
|
||||||
|
|
||||||
|
// Load the video sequence based on the current translation mode
|
||||||
if (currentTranslationMode === 'words') {
|
if (currentTranslationMode === 'words') {
|
||||||
await loadVideoSequenceByWords();
|
await loadVideoSequenceByWords();
|
||||||
} else if (currentTranslationMode === 'letters') {
|
} else if (currentTranslationMode === 'letters') {
|
||||||
@ -129,18 +145,21 @@ translateBtn.addEventListener('click', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event listener for "Preložiť po slovách" button
|
||||||
translateWordsBtn.addEventListener('click', () => {
|
translateWordsBtn.addEventListener('click', () => {
|
||||||
currentTranslationMode = 'words';
|
currentTranslationMode = 'words'; // Set to words mode
|
||||||
translateWordsBtn.classList.add('active');
|
translateWordsBtn.classList.add('active');
|
||||||
translateLettersBtn.classList.remove('active');
|
translateLettersBtn.classList.remove('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event listener for "Preložiť po písmenách" button
|
||||||
translateLettersBtn.addEventListener('click', () => {
|
translateLettersBtn.addEventListener('click', () => {
|
||||||
currentTranslationMode = 'letters';
|
currentTranslationMode = 'letters'; // Set to letters mode
|
||||||
translateLettersBtn.classList.add('active');
|
translateLettersBtn.classList.add('active');
|
||||||
translateWordsBtn.classList.remove('active');
|
translateWordsBtn.classList.remove('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event listeners for prev and next buttons to navigate video sequence
|
||||||
prevBtn.addEventListener('click', () => {
|
prevBtn.addEventListener('click', () => {
|
||||||
if (currentIndex > 0) {
|
if (currentIndex > 0) {
|
||||||
autoPlayEnabled = false;
|
autoPlayEnabled = false;
|
||||||
@ -155,4 +174,4 @@ nextBtn.addEventListener('click', () => {
|
|||||||
currentIndex++;
|
currentIndex++;
|
||||||
playVideoAtIndex(currentIndex);
|
playVideoAtIndex(currentIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user