refactor: remove unused isAdmin parameter in frontend socket

This commit is contained in:
antebrl
2025-05-03 19:09:16 +02:00
parent 170de2da33
commit f0ab4f70ba
5 changed files with 12 additions and 26 deletions

View File

@@ -345,8 +345,6 @@ function AppContent() {
selectedChannel={selectedChannel} selectedChannel={selectedChannel}
setSearchQuery={setSearchQuery} setSearchQuery={setSearchQuery}
onEditChannel={handleEditChannel} onEditChannel={handleEditChannel}
isAdmin={isAdmin}
isAdminEnabled={isAdminEnabled}
/> />
</div> </div>
@@ -366,7 +364,6 @@ function AppContent() {
setEditChannel(null); setEditChannel(null);
}} }}
channel={editChannel} channel={editChannel}
isAdmin={isAdmin}
/> />
)} )}
@@ -383,7 +380,6 @@ function AppContent() {
<TvPlaylistModal <TvPlaylistModal
isOpen={isTvPlaylistOpen} isOpen={isTvPlaylistOpen}
onClose={() => setIsTvPlaylistOpen(false)} onClose={() => setIsTvPlaylistOpen(false)}
isAdmin={isAdmin}
/> />
<AdminModal <AdminModal

View File

@@ -1,15 +1,12 @@
import React, { useState } from "react"; import React from "react";
import { Channel } from "../types"; import { Channel } from "../types";
import socketService from "../services/SocketService"; import socketService from "../services/SocketService";
import { Lock } from "lucide-react";
interface ChannelListProps { interface ChannelListProps {
channels: Channel[]; channels: Channel[];
selectedChannel: Channel | null; selectedChannel: Channel | null;
setSearchQuery: React.Dispatch<React.SetStateAction<string>>; setSearchQuery: React.Dispatch<React.SetStateAction<string>>;
onEditChannel: (channel: Channel) => void; onEditChannel: (channel: Channel) => void;
isAdmin?: boolean;
isAdminEnabled?: boolean;
} }
function ChannelList({ function ChannelList({
@@ -17,8 +14,6 @@ function ChannelList({
selectedChannel, selectedChannel,
setSearchQuery, setSearchQuery,
onEditChannel, onEditChannel,
isAdmin = false,
isAdminEnabled = false,
}: ChannelListProps) { }: ChannelListProps) {
const onSelectChannel = (channel: Channel) => { const onSelectChannel = (channel: Channel) => {
setSearchQuery(""); setSearchQuery("");

View File

@@ -1,14 +1,15 @@
import { X, Copy, Tv2 } from 'lucide-react'; import { X, Copy, Tv2 } from 'lucide-react';
import { useContext } from 'react'; import { useContext } from 'react';
import { ToastContext } from './notifications/ToastContext'; import { ToastContext } from './notifications/ToastContext';
import { useAdmin } from './admin/AdminContext';
interface TvPlaylistModalProps { interface TvPlaylistModalProps {
isOpen: boolean; isOpen: boolean;
onClose: () => void; onClose: () => void;
isAdmin?: boolean;
} }
function TvPlaylistModal({ isOpen, onClose, isAdmin = false }: TvPlaylistModalProps) { function TvPlaylistModal({ isOpen, onClose }: TvPlaylistModalProps) {
const { isAdmin } = useAdmin();
const { addToast } = useContext(ToastContext); const { addToast } = useContext(ToastContext);
const playlistUrl = `${import.meta.env.VITE_BACKEND_URL || window.location.origin}/api/channels/playlist`; const playlistUrl = `${import.meta.env.VITE_BACKEND_URL || window.location.origin}/api/channels/playlist`;

View File

@@ -9,10 +9,9 @@ import { ModeTooltipContent, Tooltip } from '../Tooltip';
interface ChannelModalProps { interface ChannelModalProps {
onClose: () => void; onClose: () => void;
channel?: Channel | null; channel?: Channel | null;
isAdmin?: boolean;
} }
function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps) { function ChannelModal({ onClose, channel }: ChannelModalProps) {
const [type, setType] = useState<'channel' | 'playlist'>('playlist'); const [type, setType] = useState<'channel' | 'playlist'>('playlist');
const [isEditMode, setIsEditMode] = useState(false); const [isEditMode, setIsEditMode] = useState(false);
const [inputMethod, setInputMethod] = useState<'url' | 'text'>('url'); const [inputMethod, setInputMethod] = useState<'url' | 'text'>('url');
@@ -102,7 +101,6 @@ function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps)
avatar.trim() || 'https://via.placeholder.com/64', avatar.trim() || 'https://via.placeholder.com/64',
mode, mode,
JSON.stringify(headers), JSON.stringify(headers),
isAdmin
); );
} else if (type === 'playlist') { } else if (type === 'playlist') {
if (inputMethod === 'url' && !playlistUrl.trim()) return; if (inputMethod === 'url' && !playlistUrl.trim()) return;
@@ -114,7 +112,6 @@ function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps)
mode, mode,
playlistUpdate, playlistUpdate,
JSON.stringify(headers), JSON.stringify(headers),
isAdmin
); );
} }
@@ -135,7 +132,7 @@ function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps)
avatar: avatar.trim() || 'https://via.placeholder.com/64', avatar: avatar.trim() || 'https://via.placeholder.com/64',
mode: mode, mode: mode,
headers: headers, headers: headers,
}, isAdmin); });
} else if (type === 'playlist') { } else if (type === 'playlist') {
const newPlaylist = inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim(); const newPlaylist = inputMethod === 'url' ? playlistUrl.trim() : playlistText.trim();
socketService.updatePlaylist(channel!.playlist, { socketService.updatePlaylist(channel!.playlist, {
@@ -144,7 +141,7 @@ function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps)
playlistUpdate: playlistUpdate, playlistUpdate: playlistUpdate,
mode: mode, mode: mode,
headers: headers, headers: headers,
}, isAdmin); });
} }
addToast({ addToast({
@@ -159,9 +156,9 @@ function ChannelModal({ onClose, channel, isAdmin = false }: ChannelModalProps)
const handleDelete = () => { const handleDelete = () => {
if (channel) { if (channel) {
if (type === 'channel') { if (type === 'channel') {
socketService.deleteChannel(channel.id, isAdmin); socketService.deleteChannel(channel.id);
} else if (type === 'playlist') { } else if (type === 'playlist') {
socketService.deletePlaylist(channel.playlist, isAdmin); socketService.deletePlaylist(channel.playlist);
} }
} }
addToast({ addToast({

View File

@@ -146,7 +146,6 @@ class SocketService {
avatar: string, avatar: string,
mode: ChannelMode, mode: ChannelMode,
headersJson: string, headersJson: string,
isAdmin: boolean = false
) { ) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();
@@ -173,7 +172,7 @@ class SocketService {
} }
// Delete channel // Delete channel
deleteChannel(id: number, isAdmin: boolean = false) { deleteChannel(id: number) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();
@@ -186,7 +185,7 @@ class SocketService {
} }
// Update channel // Update channel
updateChannel(id: number, updatedAttributes: any, isAdmin: boolean = false) { updateChannel(id: number, updatedAttributes: any) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();
@@ -205,7 +204,6 @@ class SocketService {
mode: ChannelMode, mode: ChannelMode,
playlistUpdate: boolean, playlistUpdate: boolean,
headers: string, headers: string,
isAdmin: boolean = false
) { ) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();
@@ -228,7 +226,6 @@ class SocketService {
updatePlaylist( updatePlaylist(
playlist: string, playlist: string,
updatedAttributes: any, updatedAttributes: any,
isAdmin: boolean = false
) { ) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();
@@ -242,7 +239,7 @@ class SocketService {
} }
// Delete playlist // Delete playlist
deletePlaylist(playlist: string, isAdmin: boolean = false) { deletePlaylist(playlist: string) {
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
this.connect(); this.connect();