-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat save last selected item in local storage
- Loading branch information
Showing
2 changed files
with
40 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {Category, PlayerFaction} from "./Models"; | ||
|
||
const FACTION_KEY = "player-faction" | ||
|
||
const SELECTED_ITEM_KEY_PREFIX = "selected-item" | ||
|
||
export function setPlayerFaction(faction: PlayerFaction) { | ||
localStorage.setItem(FACTION_KEY, faction) | ||
} | ||
|
||
export function getPlayerFaction(): PlayerFaction { | ||
return localStorage.getItem(FACTION_KEY) as PlayerFaction | "colonial" | ||
} | ||
|
||
export function getSavedSelectedItemName(category: Category): string { | ||
return localStorage.getItem(selectedItemKey(category)) as string | "" | ||
} | ||
|
||
export function setSavedSelectedItemName(category: Category, itemName: string) { | ||
localStorage.setItem(selectedItemKey(category), itemName) | ||
} | ||
|
||
function selectedItemKey(category: Category): string { | ||
return `${SELECTED_ITEM_KEY_PREFIX}-${category}` | ||
} |
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