feat(themes): add random theme selection via ?theme=random#115
Open
Subhooo5 wants to merge 1 commit into
Open
Conversation
Contributor
|
@Subhooo5 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
5b1dbcc to
bf1a564
Compare
Author
|
Hey @JhaSourav07 , please feel free to review the PR and merge the same. It satisfies all the acceptance criteria. Thank you 🚀🫂. Looking forward to solving several more issues/bugs and adding enhancements/features throughout the GSSoC journey🥰. |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
|
can you attach a video of working? |
Owner
|
can you review this PR? |
Author
Done 🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #66
Adds support for ?theme=random as a valid theme value on the /api/streak endpoint. When passed, the API dynamically picks a random theme from the available themes object on every request, giving users a surprise theme on every load.
Changes made in app/api/streak/route.ts:
Added an isRandomTheme flag that checks if theme === 'random'. If true, a random key is picked from the themes object using Math.random(), with a || themes.dark fallback to ensure no crash if the selection somehow fails.
Also extended the cacheControl condition to disable caching when isRandomTheme is true:
const cacheControl = refresh || isRandomTheme
? 'no-cache, no-store, must-revalidate'
:
public, s-maxage=${secondsToMidnight}, stale-while-revalidate=86400;Without this, the CDN would cache the first random SVG and serve the same theme to all users for hours, defeating the purpose of the feature entirely.
Changes made in README.md:
Added random to the Theme Presets table with varies for all color columns since the values change dynamically on every load.
No other files were modified.
Pillar
Working Video
https://collection.cloudinary.com/dqvm8dce2/73286b27f012f3021856fee1142847bf
Checklist before requesting a review:
CONTRIBUTING.mdfile.localhost:3000/api/streak?user=YOUR_USERNAME&theme=random).npm run formatandnpm run lintlocally and resolved all errors.README.mdadded a new 'random' theme preset.