-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
push kinderzuschlag profile to session storage
- Loading branch information
Showing
5 changed files
with
74 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { loadUserData } from './services/userService'; | ||
|
||
const AppStartup = () => { | ||
//const userId = useUserStore((state) => state.userId); | ||
const [sessionStoreInitialised, setSessionStoreInitialised] = useState(false); | ||
|
||
// initialise session store | ||
useEffect(() => { | ||
const initialiseSessionStore = async () => { | ||
if (!sessionStoreInitialised) { | ||
await loadUserData(); | ||
console.log('Session store initialised'); | ||
setSessionStoreInitialised(true); | ||
} | ||
}; | ||
|
||
initialiseSessionStore(); | ||
}, [sessionStoreInitialised]); | ||
|
||
return null; | ||
}; | ||
|
||
export default AppStartup; |
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,24 @@ | ||
import readJson from '../utilities/readJson'; | ||
import {UserModel} from "../models/UserModel"; | ||
|
||
export const loadUserData = async () => { | ||
// initialise kinderzuschlag profile | ||
const profilePath = 'kinderzuschlag-user-profile'; | ||
const userProfilePath = `assets/data/user-profile-examples/${profilePath}.json`; | ||
|
||
// fetch the JSON data from the specified path | ||
const userProfileData = await readJson(userProfilePath); | ||
|
||
// Store user data in session storage | ||
UserModel.storeUserData(userProfileData); | ||
}; | ||
|
||
|
||
|
||
// Assuming UserStore's storeUserData function | ||
export class UserStore { | ||
static storeUserData(userId, userData) { | ||
// Assuming this logic now stores data in session storage | ||
sessionStorage.setItem(userId, JSON.stringify(userData)); | ||
} | ||
} |
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,9 @@ | ||
const readJson = async (filePath) => { | ||
const response = await fetch(filePath); | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}; | ||
|
||
export default readJson; |