Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 88 additions & 69 deletions src/Pages/LedSign/LedSign.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function LedSign() {
const [permissionRequest, setPermissionRequest] = useState(null);
const [checkingPermission, setCheckingPermission] = useState(false);
const [requestingPermission, setRequestingPermission] = useState(false);
const [cancelingRequest, setCancelingRequest] = useState(false);
const isOfficer = user.accessLevel >= membershipState.OFFICER;
const [tab, setTab] = useState('sign');
const [allPermissionRequests, setAllPermissionRequests] = useState([]);
Expand Down Expand Up @@ -237,6 +238,16 @@ function LedSign() {
// eslint-disable-next-line
}, []);

async function fetchAllPermissionRequests() {
if (!isOfficer) return;
setLoadingRequests(true);
const result = await getAllPermissionRequests('LED_SIGN', user.token);
if (!result.error && result.responseData) {
setAllPermissionRequests(result.responseData);
}
setLoadingRequests(false);
}

useEffect(() => {
if (isOfficer && tab === 'requests') {
fetchAllPermissionRequests();
Expand Down Expand Up @@ -272,6 +283,17 @@ function LedSign() {
setRequestingPermission(false);
}

async function handleCancelRequest() {
if (!permissionRequest || !permissionRequest._id) return;

setCancelingRequest(true);
const result = await deletePermissionRequest('LED_SIGN', permissionRequest._id, user.token);
if (!result.error) {
setPermissionRequest(null);
}
setCancelingRequest(false);
}

function renderPermissionRequestUI() {
if (user.accessLevel >= membershipState.OFFICER) {
return null;
Expand All @@ -294,6 +316,13 @@ function LedSign() {
<p className="text-sm text-gray-600 dark:text-gray-400 italic">
Drop a message in Discord to speed up the process!
</p>
<button
className="btn bg-gray-500 hover:bg-gray-400 text-white"
onClick={handleCancelRequest}
disabled={cancelingRequest}
>
{cancelingRequest ? 'Canceling...' : 'Nevermind'}
</button>
</div>
);
}
Expand Down Expand Up @@ -331,16 +360,6 @@ function LedSign() {
: 'p-2 hover:bg-gray-400 rounded-md dark:text-white text-gray-700';
}

async function fetchAllPermissionRequests() {
if (!isOfficer) return;
setLoadingRequests(true);
const result = await getAllPermissionRequests('LED_SIGN', user.token);
if (!result.error && result.responseData) {
setAllPermissionRequests(result.responseData);
}
setLoadingRequests(false);
}

async function handleApprove(requestId) {
const result = await approvePermissionRequest('LED_SIGN', requestId, user.token);
if (!result.error) await fetchAllPermissionRequests();
Expand Down Expand Up @@ -414,7 +433,7 @@ function LedSign() {
);
}

const hasAccess = user.accessLevel >= membershipState.OFFICER;
const hasAccess = user.accessLevel >= membershipState.OFFICER || (permissionRequest && permissionRequest.approved);

return (
<div>
Expand Down Expand Up @@ -442,75 +461,75 @@ function LedSign() {
</div>
{tab === 'sign' && (
<div className="space-y-12 mt-10 gap-x-6 gap-y-8 w-full sm:grid-cols-6">
<div className="flex border-b border-gray-900/10 pb-12 md:w-full">
<div className="flex flex-col justify-center items-center sm:col-span-3 w-full">
<div className='w-2/3 lg:w-1/2'>
<label>Preview</label>
<div>
<div
className="led-sign-preview-border-top"
style={{ backgroundColor: borderColor }}
></div>
<div
className="led-sign-preview-background"
style={{ backgroundColor: backgroundColor }}
>
<div className="led-sign-marquee-container">
<div className="led-sign-marquee" style={{ animationDuration: `${getAnimationDuration()}s` }}>
<h1 className="led-sign-preview-text text-3xl" style={{ color: textColor }} placeholder="Sign Text">
{/*
<div className="flex border-b border-gray-900/10 pb-12 md:w-full">
<div className="flex flex-col justify-center items-center sm:col-span-3 w-full">
<div className='w-2/3 lg:w-1/2'>
<label>Preview</label>
<div>
<div
className="led-sign-preview-border-top"
style={{ backgroundColor: borderColor }}
></div>
<div
className="led-sign-preview-background"
style={{ backgroundColor: backgroundColor }}
>
<div className="led-sign-marquee-container">
<div className="led-sign-marquee" style={{ animationDuration: `${getAnimationDuration()}s` }}>
<h1 className="led-sign-preview-text text-3xl" style={{ color: textColor }} placeholder="Sign Text">
{/*
we add a padding of 28 characters of whitespace so the entire message
scrolls to the end of the preview before repeating. the preview has a
width of about 28 characters.
*/}
{text.padEnd(28, ' ')}
</h1>
{text.padEnd(28, ' ')}
</h1>
</div>
</div>
</div>
<div
className="led-sign-preview-border-bottom"
style={{ backgroundColor: borderColor }}
></div>
</div>
</div>
<div
className="led-sign-preview-border-bottom"
style={{ backgroundColor: borderColor }}
></div>
</div>
</div>
{maybeShowExpirationDate()}
{getExpirationButtonOrInput()}
{
inputArray.map(({
id,
title,
type,
value,
onChange,
...rest
}) => (
<div key={title} className="sm:col-span-2 sm:col-start-1 w-2/3 lg:w-1/2">
<div className="mt-2 ">
<label htmlFor="copies" className="block text-sm font-medium leading-6">{title}</label>
<input
type={type}
value={value}
id={id}
onChange={onChange}
className="indent-2 text-black dark:text-white block w-full rounded-md border-0 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-500 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
{...rest}
/>
</div>
</div>
))
}
{maybeShowExpirationDate()}
{getExpirationButtonOrInput()}
{
inputArray.map(({
id,
title,
type,
value,
onChange,
...rest
}) => (
<div key={title} className="sm:col-span-2 sm:col-start-1 w-2/3 lg:w-1/2">
<div className="mt-2 ">
<label htmlFor="copies" className="block text-sm font-medium leading-6">{title}</label>
<input
type={type}
value={value}
id={id}
onChange={onChange}
className="indent-2 text-black dark:text-white block w-full rounded-md border-0 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-500 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
{...rest}
/>
</div>
</div>
))
}

<button className='btn w-2/3 lg:w-1/2 bg-red-500 hover:bg-red-400 text-black mt-4' onClick={handleStop}>
<button className='btn w-2/3 lg:w-1/2 bg-red-500 hover:bg-red-400 text-black mt-4' onClick={handleStop}>
Stop
</button>
<button className='btn w-2/3 lg:w-1/2 bg-green-500 hover:bg-green-400 text-black mt-2' onClick={handleSend}>
</button>
<button className='btn w-2/3 lg:w-1/2 bg-green-500 hover:bg-green-400 text-black mt-2' onClick={handleSend}>
Send
</button>
{renderRequestStatus()}
</button>
{renderRequestStatus()}
</div>
</div>
</div>
</div>
</div>
)}
{tab === 'requests' && <MaybeRenderListOfSignRequests />}
</>
Expand Down