mirror of
https://github.com/janishutz/fundamentals-of-webengineering.git
synced 2025-11-25 05:44:24 +00:00
Add persistance
This commit is contained in:
@@ -5,20 +5,42 @@ import {
|
||||
// Using localStorage for persistance
|
||||
const persistanceStore: PersistanceConfig = JSON.parse( localStorage.getItem( 'persistance' ) ?? '{}' );
|
||||
|
||||
export const store = (
|
||||
/**
|
||||
* Store state for filename.
|
||||
* @param filename - The filename to store for
|
||||
* @param size - The filesize (in case file is changed)
|
||||
* @param sorted - The sorted column
|
||||
* @param active - The active column
|
||||
* @param ascending - True if sorting ascending
|
||||
*/
|
||||
const store = (
|
||||
filename: string,
|
||||
size: number,
|
||||
size: string,
|
||||
sorted: string,
|
||||
active: string
|
||||
active: string,
|
||||
ascending: boolean
|
||||
) => {
|
||||
persistanceStore[ `${ filename }-${ size }` ] = {
|
||||
'active': active,
|
||||
'sorted': sorted
|
||||
'sorted': sorted,
|
||||
'ascending': ascending
|
||||
};
|
||||
localStorage.setItem( 'persistance', JSON.stringify( persistanceStore ) );
|
||||
};
|
||||
|
||||
|
||||
export const get = ( filename: string, size: number ) => {
|
||||
/**
|
||||
* Get the state for filename
|
||||
* @param filename - The file to retrieve from
|
||||
* @param size - The size of the file
|
||||
* @returns The state, if found
|
||||
*/
|
||||
const get = ( filename: string, size: string ) => {
|
||||
return persistanceStore[ `${ filename }-${ size }` ];
|
||||
};
|
||||
|
||||
|
||||
export default {
|
||||
store,
|
||||
get
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user