-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Limit playlist length and check if level is already in list * add remove from playlist functionality * updateOne * cleanup * populate flag * tooltip * play later rename * handing off to sspenst * useSWR instead of fetch for the getReviews and getRecords * unrelated fix for formatted user level undefinede * play later api * fix from renames * private and reserve play-later slug * Private updates * show hide list * formatting * left scrollbar * auto smooth scroll to current level * Fix title of collection * play later link broken fix * fix hide show * copy tweaks * fix build * add test * collections can now be marked private * allowing creating of private levels on create * update collection tests for private check * cleanup * more tests and cleanup * 100% coverage for play-later * optimize play-attempt.test and format it. combine promise.alls. * test for reserved slug name * update tests some more * more tests * private to isPrivate * fix test * improve coverage of naturalsort * Handle PlayLater type in collection update. Allow making it private/public * [unrelated to PR] add test for api/user/[id]/index * gate play later behind pro * fix tests * add to play later from search * cleanup * pass stats in to selectoption * See play collection directly from search results * use session storage * cleanup * doh * search query in title link * fix play later link * include more in level_search_default_projection * add data only in search rather than generically * 3 dot * cleanup * edit level modal when no collection show a bit more info about what a collection is * move <Solved/> to top right * move play later to top * bring to top * helper file * toasterror undo * mobile view for list of collections * comment * add test. cleanup. also settimeout on the scroll only for mobile * select card ux updates * ux updates * fix bringToTop * models/constants * working on collection UX * naturalSort custom compare function * refactor level title out of gameLayout * tweaking * more efficient collection fetching * tempCollection tweaks * Add one click undo for play later * fix auto scroll to level in modal * userAgent now helps set defaults for useDeviceCheck * prevent relayout when collection is still loading * show + and - buttons hover effect only for desktop * fix tests * fixes * more fixes * we are getting close * fix apis and tests * lint --------- Co-authored-by: Spencer Spenst <[email protected]>
- Loading branch information
Showing
86 changed files
with
2,045 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { AppContext } from '@root/contexts/appContext'; | ||
import isPro from '@root/helpers/isPro'; | ||
import { EnrichedLevel } from '@root/models/db/level'; | ||
import Link from 'next/link'; | ||
import React, { useContext, useState } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
import StyledTooltip from '../page/styledTooltip'; | ||
|
||
interface PlayLaterToggleButtonProps { | ||
className?: string; | ||
level: EnrichedLevel; | ||
} | ||
|
||
export function PlayLaterToggleButton({ className, level }: PlayLaterToggleButtonProps) { | ||
const { mutatePlayLater, playLater, user } = useContext(AppContext); | ||
const isInPlayLater = !!(playLater && playLater[level._id.toString()]); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
if (!user || !isPro(user) || !playLater) { | ||
return null; | ||
} | ||
|
||
const boldedLevelName = <span className='font-bold'>{level.name}</span>; | ||
const fetchFunc = async (remove: boolean) => { | ||
setIsLoading(true); | ||
toast.dismiss(); | ||
toast.loading(remove ? 'Removing...' : 'Adding...', { | ||
position: 'bottom-center', | ||
}); | ||
|
||
const res = await fetch('/api/play-later/', { | ||
method: remove ? 'DELETE' : 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
id: level._id.toString(), | ||
}), | ||
}); | ||
|
||
toast.dismiss(); | ||
|
||
if (res.ok) { | ||
const message = ( | ||
<div className='flex flex-col items-center w-92 max-w-full text-center'> | ||
<span>{remove ? ['Removed ', boldedLevelName, ' from'] : ['Added ', boldedLevelName, ' to']} <Link className='underline' href={`/collection/${user.name}/play-later`}>Play Later</Link></span> | ||
<button className='text-sm underline' onClick={() => fetchFunc(!remove)}>Undo</button> | ||
</div> | ||
); | ||
|
||
toast.success(message, { | ||
duration: 5000, | ||
position: 'bottom-center', | ||
icon: remove ? '➖' : '➕', | ||
}); | ||
mutatePlayLater(); | ||
} else { | ||
let resp; | ||
|
||
try { | ||
resp = await res.json(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
toast.error(resp?.error || 'Could not update Play Later', { | ||
duration: 5000, | ||
position: 'bottom-center', | ||
}); | ||
} | ||
|
||
setIsLoading(false); | ||
}; | ||
|
||
const id = `play-later-btn-tooltip-${level._id.toString()}`; | ||
|
||
return <> | ||
<button | ||
className={className} | ||
data-tooltip-content={isInPlayLater ? 'Remove from Play Later' : 'Add to Play Later'} | ||
data-tooltip-id={id} | ||
disabled={isLoading} | ||
onClick={async (e) => { | ||
e.preventDefault(); | ||
fetchFunc(isInPlayLater); | ||
}} | ||
style={{ | ||
color: 'var(--color)', | ||
}} | ||
> | ||
{isInPlayLater ? | ||
<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' strokeWidth={1.5} stroke='currentColor' className='w-6 h-6'> | ||
<path strokeLinecap='round' strokeLinejoin='round' d='M19.5 12h-15' /> | ||
</svg> | ||
: | ||
<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' strokeWidth={1.5} stroke='currentColor' className='w-6 h-6'> | ||
<path strokeLinecap='round' strokeLinejoin='round' d='M12 4.5v15m7.5-7.5h-15' /> | ||
</svg> | ||
} | ||
</button> | ||
<StyledTooltip id={id} /> | ||
</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.