diff --git a/client/app/components/FetchRequested.jsx b/client/app/components/FetchRequested.jsx index 568a526..6683eae 100644 --- a/client/app/components/FetchRequested.jsx +++ b/client/app/components/FetchRequested.jsx @@ -4,16 +4,50 @@ import requestElement from './styles/requestElementStyle.jsx' import { getCookie } from './Cookie.jsx'; +class DropdownList extends React.Component { + constructor(props) { + super(props); + this.state = { + filter: ['all', 'requested', 'downloading', 'downloaded'], + sort: ['requested_date', 'name', 'status', 'requested_by', 'ip', 'user_agent'], + status: ['requested', 'downloading', 'downloaded'], + } + } + + render() { + const {elementType, elementId, elementStatus, elementCallback, props} = this.props; + + console.log(elementCallback('downloaded')) + + switch (elementType) { + case 'status': + return ( +
HERE
+ ) + } + + return ( +
+ +
+ ); + } +} + class RequestElement extends React.Component { constructor(props) { super(props); - this.default_requestList = null; + this.state = { + dropDownState: undefined, + } } filterRequestList(requestList, filter) { if (filter === 'all') return requestList + if (filter === 'movie' || filter === 'show') + return requestList.filter(item => item.type === filter) return requestList.filter(item => item.status === filter) } @@ -28,26 +62,91 @@ class RequestElement extends React.Component { requestList.reverse(); } + userAgent(agent) { + if (agent) { + try { + return agent.split(" ")[1].replace(/[\(\;]/g, ''); + } + catch(e) { + return agent; + } + } + return ''; + } + + updateDropDownState(status) { + if (status !== this.dropDownState) { + this.dropDownState = status; + } + } + + + ItemsStatusDropdown(id, type, status) { + return ( +
+ + + +
+ ) + } + + updateRequestedItem(id, type) { + console.log(id, type, this.dropDownState); + Promise.resolve() + fetch('https://apollo.kevinmidboe.com/api/v1/plex/request/' + id, { + method: 'PUT', + headers: { + 'Content-type': 'application/json', + 'authorization': getCookie('token') + }, + body: JSON.stringify({ + type: type, + status: this.dropDownState, + }) + }) + .then(response => { + if (response.status !== 200) { + console.log('error'); + } + + response.json() + .then(data => { + if (data.success === true) { + console.log('UPDATED :', id, ' with ', this.dropDownState) + } + }) + }) + .catch(error => { + new Error(error); + }) + } + createHTMLElement(data, index) { var posterPath = 'https://image.tmdb.org/t/p/w300' + data.image_path; - - if (data.user_agent !== null) { - var user_agent = data.user_agent.split(" "); - var agent_shortened = user_agent[1].replace(/[\(\;]/g, '') - } return (
- Name: {data.name} + Name: {data.name}

Year: {data.year}

+ Type: {data.type}

Status: {data.status}

Address: {data.ip}

Requested Data: {data.requested_date}

Requested By: {data.requested_by}

- Agent: {agent_shortened}

+ Agent: { this.userAgent(data.user_agent) }

+ + { this.ItemsStatusDropdown(data.id, data.type, data.status) }
) } @@ -138,6 +237,8 @@ class FetchRequested extends React.Component { + +