Skip to content

Commit

Permalink
Modified module encoding logic to support change to Programme domain
Browse files Browse the repository at this point in the history
  • Loading branch information
felpsey committed Jan 2, 2025
1 parent 718721d commit a5d25a7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Degree classification estimator for Open University undergraduate degree programmes">
<meta name="keywords" content="Open University, Degree classification calculator, Degree weight calculator">

<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->

<title>OU Degree Estimator</title>
</head>
<body>
Expand Down
73 changes: 34 additions & 39 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,37 @@ function App() {
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [programme, setProgramme] = useState<Programme>(new Programme("Example programme"));

// Decode search params when the component is mounted
useEffect(() => {
// decodeSearchParams();
}, []);
if(!programme.modules.current && (programme.modules.length != 0)) {

Check failure on line 21 in src/App.tsx

View workflow job for this annotation

GitHub Actions / deploy

Property 'current' does not exist on type 'Module[]'.
let encodedModuleData = encodeModuleData(programme.modules);

// Update encoded search params when modules state is changed
useEffect(() => {
if (programme.modules.length !== 0) {
// updateSearchParams()
updateSearchParams(encodedModuleData);
}
}, [programme]);
}), [programme];

// function decodeSearchParams(): void {
// let currentUrl: URL = new URL(document.location.href);
// let data: string|null = currentUrl.searchParams.get('data');
function decodeSearchParams(): void {
let currentUrl: URL = new URL(document.location.href);
let data: string|null = currentUrl.searchParams.get('data');

// if (data) {
// importUnstructuredModuleData(JSON.parse(atob(data)));
// }
// }
if (data) {
importModuleData(JSON.parse(atob(data)));
}
}

// function importUnstructuredModuleData(unstructuredModuleData: []): void {
// let structuredModuleData = unstructuredModuleData.map((module: any) => {
// return new Module(module._code, module._credits, module._stage, module._grade);
// });
function importModuleData(unstructuredModuleData: []): void {
let modules = unstructuredModuleData.map((module: any) => {
return new Module(module._code, module._credits, module._stage, module._grade);
});

// setProgramme(programme.modules.structuredModuleData);
// }
modules.forEach(module => {
addModuleData(module)
});
}

// function encodeModuleData(): string {
// // Convert modules array to JSON then base64 encode
// return btoa(JSON.stringify(programme));
// }
function encodeModuleData(modules): string {

Check failure on line 47 in src/App.tsx

View workflow job for this annotation

GitHub Actions / deploy

Parameter 'modules' implicitly has an 'any' type.
// Convert modules array to JSON then base64 encode
return btoa(JSON.stringify(modules));
}

function newModuleEntry(): void {
setIsModalOpen(true);
Expand All @@ -63,23 +61,20 @@ function App() {
// Return a new Programme instance with updated modules
return new Programme(currentProgramme.title, updatedModules);
});
}

console.log(programme);
}

// function updateSearchParams(): void {
// // Encode module data in memory
// let data = encodeModuleData();

// // Fetch the currentl URL, this will change each time this method is called
// let currentUrl = new URL(document.location.href);
function updateSearchParams(data): void {

Check failure on line 66 in src/App.tsx

View workflow job for this annotation

GitHub Actions / deploy

Parameter 'data' implicitly has an 'any' type.
// Fetch the currentl URL, this will change each time this method is called
let currentUrl = new URL(document.location.href);

// // Set encoded data on URL object on 'data' property
// currentUrl.searchParams.set('data', data);
// Set encoded data on URL object on 'data' property
currentUrl.searchParams.set('data', data);

// // Append encoded params to URI without reloading page
// history.replaceState({}, "", currentUrl.toString());
// }
// Append encoded params to URI without reloading page
history.replaceState({}, "", currentUrl.toString());
}

decodeSearchParams();

return (
<div className='container mx-auto h-screen border-l border-r border-gray-100'>
Expand Down
2 changes: 0 additions & 2 deletions src/domain/Programme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export class Programme {
get totalCredits() {
this._totalCredits = this.calculateTotalCredits();

console.log(this._totalCredits);

return this._totalCredits;
}

Expand Down

0 comments on commit a5d25a7

Please sign in to comment.