|
|
|
@ -1,8 +1,9 @@ |
|
|
|
import Navbar from "../components/Navbar.jsx"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import Tag from "../components/Tag.jsx"; |
|
|
|
import { getChannel } from "../services/user.service.js"; |
|
|
|
import { getChannel, searchByUsername } from "../services/user.service.js"; |
|
|
|
import { uploadVideo, uploadThumbnail, uploadTags } from "../services/video.service.js"; |
|
|
|
import { on } from "node:events"; |
|
|
|
|
|
|
|
|
|
|
|
export default function AddVideo() { |
|
|
|
@ -14,10 +15,13 @@ export default function AddVideo() { |
|
|
|
const [videoTitle, setVideoTitle] = useState(""); |
|
|
|
const [videoDescription, setVideoDescription] = useState(""); |
|
|
|
const [videoTags, setVideoTags] = useState([]); |
|
|
|
const [visibility, setVisibility] = useState("public"); |
|
|
|
const [visibility, setVisibility] = useState("private"); |
|
|
|
const [videoThumbnail, setVideoThumbnail] = useState(null); |
|
|
|
const [videoFile, setVideoFile] = useState(null); |
|
|
|
const [channel, setChannel] = useState(null); |
|
|
|
const [searchUser, setSearchUser] = useState(""); |
|
|
|
const [authorizedUsers, setAuthorizedUsers] = useState([]); |
|
|
|
const [searchResults, setSearchResults] = useState([]); |
|
|
|
const [alerts, setAlerts] = useState([]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -102,6 +106,22 @@ export default function AddVideo() { |
|
|
|
setAlerts(alerts.filter(alert => alert !== alertToRemove)); |
|
|
|
}; |
|
|
|
|
|
|
|
const onUserSearch = (e) => { |
|
|
|
const searchUser = e.target.value; |
|
|
|
if (searchUser.trim() !== "") { |
|
|
|
// Call the API to search for users |
|
|
|
searchByUsername(searchUser, token, addAlert) |
|
|
|
.then((results) => { |
|
|
|
setSearchResults(results); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
addAlert('error', 'Erreur lors de la recherche d\'utilisateurs.'); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
setSearchResults([]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className="min-w-screen min-h-screen bg-linear-to-br from-left-gradient to-right-gradient"> |
|
|
|
<Navbar isSearchPage={false} alerts={alerts} onCloseAlert={onCloseAlert} /> |
|
|
|
@ -166,6 +186,65 @@ export default function AddVideo() { |
|
|
|
<option value="private">Privé</option> |
|
|
|
</select> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
visibility == "private" && ( |
|
|
|
<div className="mb-4"> |
|
|
|
<label className="block text-white text-xl font-montserrat font-semibold mb-2" htmlFor="authorizedUsers">Utilisateurs autorisés</label> |
|
|
|
<div> |
|
|
|
<input |
|
|
|
type="text" |
|
|
|
id="authorizedUsers" |
|
|
|
name="authorizedUsers" |
|
|
|
className="w-full p-2 mb-4 glassmorphism focus:outline-none font-inter text-xl text-white" |
|
|
|
placeholder="Rechercher un utilisateur" |
|
|
|
value={searchUser} |
|
|
|
onChange={(e) => setSearchUser(e.target.value)} |
|
|
|
onKeyDown={(e) => { |
|
|
|
if (e.key === 'Enter' && searchUser.trim() !== "") { |
|
|
|
onUserSearch(e); |
|
|
|
} |
|
|
|
}} |
|
|
|
/> |
|
|
|
<div> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="max-h-40 overflow-y-auto"> |
|
|
|
{authorizedUsers.map((user, index) => ( |
|
|
|
<div key={index} className="flex items-center justify-between p-2 border-b border-gray-700"> |
|
|
|
<span className="text-white">{user}</span> |
|
|
|
<button |
|
|
|
className="text-red-500" |
|
|
|
onClick={() => setAuthorizedUsers(authorizedUsers.filter((u) => u !== user))} |
|
|
|
> |
|
|
|
Supprimer |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
))} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<label className="block text-white text-xl font-montserrat font-semibold mb-2" htmlFor="videoThumbnail">Miniature</label> |
|
|
|
<input |
|
|
|
type="file" |
|
|
|
|