Skip to content

Commit

Permalink
token sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
denver-code committed May 10, 2024
1 parent b58589b commit c20e229
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ const Page = () => {
const [globalScore, setGlobalScore] = useState(0);
const [overallGrade, setOverallGrade] = useState('');

useEffect(() => {
const queryParams = new URLSearchParams(window.location.search);
const token = queryParams.get('token');
if (token) {
// Load selected qualification and grades from token in URL
const parsedToken = JSON.parse(atob(token));
setSelectedQualification(parsedToken.qualification);
setSelectedGrades(parsedToken.grades);
}
}, []);


useEffect(() => {
// Save selected qualification and grades to URL
if (selectedQualification) {
const token = btoa(JSON.stringify({ qualification: selectedQualification, grades: selectedGrades }));
window.history.replaceState(null, '', `?token=${token}`);
}
}, [selectedQualification, selectedGrades]);

useEffect(() => {
if (!selectedQualification) return; // Do nothing if no qualification is selected

Expand Down

0 comments on commit c20e229

Please sign in to comment.