Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulsvgr committed Feb 5, 2024
1 parent 274804c commit d15b0d8
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 18 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/admin/EventsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function EventPage({ addMessage }) {


const handleAddEvent = () => {
setEditingEvent({ question: '', answer: '' }); // Empty Event for adding a new one
setEditingEvent(true); // Empty Event for adding a new one
};

const Event = ({ event }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/admin/ProcessPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function ProcessPage({ addMessage }) {
const [loading, setLoading] = useState(true);

const sortProcesses = (processes) => {
const statusOrder = { 'Unsupported':1, 'Processing': 2, 'Pending': 3, 'Completed': 4 };
const statusOrder = { 'Processing': 1, 'Pending': 2, 'Unsupported':3, 'Completed': 4 };
return processes.sort((a, b) => statusOrder[a.status] - statusOrder[b.status]);
};

Expand Down
119 changes: 119 additions & 0 deletions src/admin/SourceEditModal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// import React, { useState, useRef } from 'react';
// import client from '../utils/axiosConfig';
// import CanvasDraw from 'react-canvas-draw';

// const SourceEditModal = ({ source, onSave, onClose }) => {
// const [name, setName] = useState(source.name || '');
// const [spots, setSpots] = useState(source.spots || []);
// const sourceId = source.id || 'new';
// const [videoUrl, setVideoUrl] = useState('');
// const [currentFrameTime, setCurrentFrameTime] = useState(0);
// const [imageSrc, setImageSrc] = useState('');
// const canvasRef = useRef(null);

// const handleSave = () => {
// var sourceData = {
// name: name,
// spots: spots
// };
// onSave(sourceId, sourceData);
// };

// const updateSpots = (updatedSpots) => {
// setSpots(updatedSpots);
// };


// const fetchNextFrame = async () => {
// const nextFrameTime = currentFrameTime + 600; // Increase time by 10 minutes (600 seconds)
// setCurrentFrameTime(nextFrameTime);

// try {
// const response = await client.get(`/api/get-frame/`, {
// params: {
// video_url: videoUrl,
// frame_time: nextFrameTime
// },
// responseType: 'blob'
// });
// const imageObjectURL = URL.createObjectURL(response.data);
// setImageSrc(imageObjectURL);
// } catch (error) {
// console.error('Error fetching frame:', error);
// }
// };

// const handleDelete = () => {
// if (window.confirm('Are you sure you want to delete this name?')) {
// onSave(sourceId, null);
// }
// };

// const handleModalClick = (e) => {
// // Prsource click inside the modal from closing it
// e.stopPropagation();
// };
// const handleDraw = () => {
// const data = canvasRef.current.getSaveData();
// // Process the data to extract rectangle coordinates
// };

// return (
// <div className="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full"
// onClick={onClose}>
// <div className="relative flex justify-center items-center h-full">
// <div className='p-5 border mx-auto shadow-lg rounded-md bg-white'
// onClick={handleModalClick}>
// <h3 className="text-lg font-semibold">{sourceId === 'new' ? 'Add' : 'Edit'} Source</h3>
// <div className='flex flex-wrap'>
// <h3 className="w-full">Name</h3>
// <input
// type="text"
// value={name}
// onChange={(e) => setName(e.target.value)}
// className="w-full p-2 border border-gray-300 rounded mt-2"
// />
// <h3 className="w-full">Spots</h3>
// {spots.map(spot => (
// <div key={spot.id}>
// {spot.name}
// </div>
// ))}
// <h3 className="w-full">Image and Spots</h3>
// <div>
// <div>
// <input
// type="text"
// value={videoUrl}
// onChange={(e) => setVideoUrl(e.target.value)}
// placeholder="Enter YouTube video URL"
// />
// <button onClick={fetchNextFrame}>Fetch Next Frame</button>
// {imageSrc && <img src={imageSrc} alt="Fetched Frame" style={{ maxWidth: '100%' }} />}
// <div>
// <CanvasDraw ref={canvasRef} />
// <button onClick={handleDraw}>Get Drawing Data</button>
// </div>
// </div>
// </div>
// </div>
// <div className="flex justify-end mt-4">
// <button onClick={handleSave} className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mr-2">
// {sourceId === 'new' ? 'Add' : 'Save'}
// </button>
// {sourceId !== 'new' &&
// <button onClick={handleDelete} className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded mr-2">
// Delete
// </button>
// }
// <button onClick={onClose} className="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
// Close
// </button>
// </div>
// </div>
// </div>
// </div>
// );
// };

// export default SourceEditModal;
81 changes: 70 additions & 11 deletions src/admin/SourcePage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useState, useEffect } from 'react';
import client from '../utils/axiosConfig';
// import SourceEditModal from './SourceEditModal';

function ListNoDuplicates(existingList, newList, key = 'id') {
const uniqueIds = new Set(existingList.map(element => element[key]));
const filteredNewList = newList.filter(newElement => !uniqueIds.has(newElement[key]));
return [...existingList, ...filteredNewList];
}

function SourcePage() {
function SourcePage({ addMessage }) {
const [sources, setSources] = useState([]);
const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);

// const [refreshKey, setRefreshKey] = useState(0);
// const [editingSource, setEditingSource] = useState(null);

useEffect(() => {
const fetchData = async () => {
try {
Expand All @@ -25,14 +27,64 @@ function SourcePage() {
};

fetchData();
}, [page]);
// }, [refreshKey]);
}, []);

// const handleEdit = (source) => {
// setEditingSource(source);
// };

// const handleSaveSource = async (sourceId, about) => {
// try {
// let response;

// if (about === null) {
// // Delete Source
// response = await client.delete(`/api/source/${sourceId}`);
// addMessage("Source deleted successfully", "green");
// } else {
// // Update or create new Source
// if (sourceId === 'new') {
// response = await client.post(`/api/source`, about);
// addMessage("Source created successfully", "green");
// } else {
// response = await client.put(`/api/source/${sourceId}`, about);
// addMessage("Source updated successfully", "green");
// }
// }
// // Check if the response was successful
// if (!(response && response.status >= 200 && response.status < 300)) {
// addMessage("Something went wrong", "red");
// }
// } catch (error) {
// // Handle errors (e.g., network issues, server errors)
// console.error('Error:', error);
// addMessage("An error occurred: " + error.message, "red");
// }
// setEditingSource(null); // Close the modal after saving
// setRefreshKey(oldKey => oldKey + 1);
// setSources([])
// };

// const handleAddSource = () => {
// setEditingSource(true); // Empty Source for adding a new one
// };

const Source = ({ source }) => {
return (
<div className="flex justify-between w-full border-b border-gray-200 p-4">
<div>
<div className='flex w-wull justify-between'>
<h3 className="text-lg mr-2">{source.id} -</h3>
<h3 className="text-lg font-semibold">{source.name}</h3>
</div>
{/* <div className='flex items-center'>
<button
onClick={() => handleEdit(source)}
className="bg-blue-500 hover:bg-blue-700 text-white h-fit font-bold py-1 px-2 rounded mx-2"
>
Edit
</button>
</div> */}
</div>
);
};
Expand All @@ -41,6 +93,12 @@ function SourcePage() {
<div className="mt-20 mx-4 flex flex-1 flex-col items-center">
<div className='flex flex-wrap justify-between'>
<h1 className="text-2xl font-bold mb-4">Source</h1>
{/* <button
onClick={handleAddSource}
className="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded mb-4 ml-6"
>
Add Source
</button> */}
</div>
<div className='flex flex-col items-start h-[50vh] overflow-y-scroll w-full'>
{loading ? (
Expand All @@ -53,17 +111,18 @@ function SourcePage() {
source={source}
/>
))}
<button
onClick={() => setPage(prevPage => prevPage + 1)}
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 ml-auto mr-auto px-4 rounded mt-4"
>
More
</button>
</>
) : (
<p>No Source found.</p>
)}
</div>
{/* {editingSource && (
<SourceEditModal
event={editingSource}
onSave={handleSaveSource}
onClose={() => setEditingSource(null)}
/>
)} */}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/admin/VideoPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function VideoPage({ addMessage }) {


const handleAddVideo = () => {
setEditingVideo({ question: '', answer: '' }); // Empty Video for adding a new one
setEditingVideo(true); // Empty Video for adding a new one
};

const Video = ({ video }) => {
Expand Down

0 comments on commit d15b0d8

Please sign in to comment.