-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Queue Dynamo conversion to Typescript, and number of fixes #2603
Feature Queue Dynamo conversion to Typescript, and number of fixes #2603
Conversation
Create FeaturedQueue types.
Clarify type in component.
queue ordered by date. There would be no way to accurately move an item between places without messing with the dates of a large number of items.
@@ -16,7 +16,7 @@ import MainLayout from 'layouts/MainLayout'; | |||
interface FeaturedCubesQueuePageProps { | |||
cubes: Cube[]; | |||
daysBetweenRotations: number; | |||
lastRotation: Date; | |||
lastRotation: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the backend and frontend code, it is a number
@@ -202,11 +202,11 @@ router.get('/featuredcubes', ensureAdmin, async (req, res) => { | |||
|
|||
return render(req, res, 'FeaturedCubesQueuePage', { | |||
cubes: sortedCubes, | |||
lastRotation: featured[0].featuredOn, | |||
lastRotation: featured.length > 0 ? featured[0].featuredOn : new Date(0).valueOf(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge case that probably would only affect local development. If nothing in queue then the last rotation is 1969
}); | ||
}); | ||
|
||
router.post('/featuredcubes/rotate', ensureAdmin, async (req, res) => { | ||
router.get('/featuredcubes/rotate', ensureAdmin, async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with the rotate confirmation modal
@@ -237,25 +237,6 @@ router.post('/featuredcubes/rotate', ensureAdmin, async (req, res) => { | |||
return redirect(req, res, '/admin/featuredcubes'); | |||
}); | |||
|
|||
router.post( | |||
'/featuredcubes/setperiod', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing using this endpoint
@@ -765,7 +765,7 @@ router.get('/social', ensureAuth, async (req, res) => { | |||
}); | |||
|
|||
router.post('/queuefeatured', ensureAuth, async (req, res) => { | |||
const redirectTo = '/user/account?nav=patreon'; | |||
const redirectTo = '/user/account?nav=patreon&tab=4'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well go straight to the patron tab when the user is doing featured queue actions
@@ -796,10 +796,10 @@ router.post('/queuefeatured', ensureAuth, async (req, res) => { | |||
|
|||
try { | |||
if (shouldUpdate) { | |||
fq.replaceForUser(req.user.id, cube.id); | |||
await fq.replaceForUser(req.user.id, cube.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the awaits Errors thrown by the functions wouldn't be caught and so the frontend would say "success" even though the action failed
@@ -5,14 +5,24 @@ import { canBeFeatured } from './featuredQueueUtil'; | |||
|
|||
async function rotateFeatured(queue) { | |||
if (queue.length < 4) { | |||
throw new Error(`Not enough cubes in queue to rotate (need 4, have ${queue.length})`); | |||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code calling rotateFeatured expects a response with messages + succcess to indicate pass/fail, not errors
@@ -21,15 +31,15 @@ async function rotateFeatured(queue) { | |||
const owner1 = await Patron.getById(old1.owner); | |||
const owner2 = await Patron.getById(old2.owner); | |||
|
|||
for (const [owner, cube] of [ | |||
for (const [owner, featuredItem] of [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename for clarity, aligning the variable with the dynamo model being called
Improvements and fixes
Testing
After
Add cube to featured queue:

Remove cube from featured queue:

Successful rotation of featured queue:
Queue state:




Featured cubes showing on dashboard:
Queue state after rotate:
Featured cubes dashboard after rotate:
Patron cannot replace a currently featured cube:

Patron can add to the featured queue:

Patron can replace their item in the featured queue, as it isn't currently featured:

Patron can remove from featured queue:
