diff --git a/src/Websites/Platform/src/Bit.Websites.Platform.Client/Pages/Butil/Butil11StoragePage.razor b/src/Websites/Platform/src/Bit.Websites.Platform.Client/Pages/Butil/Butil11StoragePage.razor index c3a1bdff33..8c368f25dc 100644 --- a/src/Websites/Platform/src/Bit.Websites.Platform.Client/Pages/Butil/Butil11StoragePage.razor +++ b/src/Websites/Platform/src/Bit.Websites.Platform.Client/Pages/Butil/Butil11StoragePage.razor @@ -1,5 +1,7 @@ @page "/butil/storage" @inherits AppComponentBase +@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage @@ -31,31 +33,361 @@
Methods
+
GetLength: Returns an integer representing the number of data items stored in the Storage object (MDN).

+ + + + +
+                                @getLengthExampleCode
+                            
+
+ +
+ GetLength +
+
+
LocalStorage length: @localLength
+
+
SessionStorage length: @sessionLength
+
+
+
+
+
+

GetKey: When passed a number n, this method will return the name of the nth key in the storage (MDN).

+ + + + +
+                                @getKeyExampleCode
+                            
+
+ +
+ +
+ GetKey +
+
+
LocalStorage key: @localKey
+
+
SessionStorage key: @sessionKey
+
+
+
+
+
+

GetItem: When passed a key name, will return that key's value (MDN).

+ + + + +
+                                @getItemExampleCode
+                            
+
+ +
+ +
+ +
+
+ GetItem +
+
+
LocalStorage item: @currentLocalItem
+
+
SessionStorage item: @currentSessionItem
+
+
+
+
+
+

SetItem: When passed a key name and value, will add that key to the storage, or update that key's value if it already exists (MDN).

+ + + + +
+                                @setItemExampleCode
+                            
+
+ +
+ +
+ +
+
+ SetItem +
+
+
+
+
+

RemoveItem: When passed a key name, will remove that key from the storage (MDN).

+ + + + +
+                                @removeItemExampleCode
+                            
+
+ +
+ +
+ +
+
+ RemoveItem +
+
+
+
+
+

Clear: When invoked, will empty all keys out of the storage (MDN).

+ + + + +
+                                @clearItemExampleCode
+                            
+
+ +
+ Clear +
+
+
+
+
+ +@code { + private string? localLength; + private string? sessionLength; + + private double keyIndex; + private string? localKey; + private string? sessionKey; + + private string? currentLocalItemKey; + private string? currentSessionItemKey; + private string? currentLocalItem; + private string? currentSessionItem; + + private string? newLocalItemKey; + private string? newSessionItemKey; + + private string? localItemKey; + private string? sessionItemKey; + + + private async Task GetLength() + { + var localResult = await localStorage.GetLength(); + localLength = localResult.ToString(); + + var sessionResult = await sessionStorage.GetLength(); + sessionLength = sessionResult.ToString(); + } + + private async Task GetKey() + { + localKey = await localStorage.GetKey((int)keyIndex); + + sessionKey = await sessionStorage.GetKey((int)keyIndex); + } + + private async Task GetItem() + { + currentLocalItem = await localStorage.GetItem(currentLocalItemKey); + + currentSessionItem = await sessionStorage.GetItem(currentSessionItemKey); + } + + private async Task SetItem() + { + await localStorage.SetItem(newLocalItemKey, newLocalItemKey); + + await sessionStorage.SetItem(newSessionItemKey, newSessionItemKey); + } + + private async Task RemoveItem() + { + await localStorage.RemoveItem(localItemKey); + + await sessionStorage.RemoveItem(sessionItemKey); + } + + private async Task Clear() + { + await localStorage.Clear(); + + await sessionStorage.Clear(); + } + + private string getLengthExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + +GetLength + +
LocalStorage length: @localLength
+ +
SessionStorage length: @sessionLength
+ +@code { + private string? localLength; + private string? sessionLength; + + private async Task GetLength() + { + var localResult = await localStorage.GetLength(); + localLength = localResult.ToString(); + + var sessionResult = await sessionStorage.GetLength(); + sessionLength = sessionResult.ToString(); + } +}"; + private string getKeyExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + + + +GetKey + +
LocalStorage key: @localKey
+ +
SessionStorage key: @sessionKey
+ +@code { + private double keyIndex; + private string? localKey; + private string? sessionKey; + + private async Task GetKey() + { + localKey = await localStorage.GetKey((int)keyIndex); + + sessionKey = await sessionStorage.GetKey((int)keyIndex); + } +}"; + private string getItemExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + + + + + +GetItem + +
LocalStorage item: @currentLocalItem
+ +
SessionStorage item: @currentSessionItem
+ +@code { + private string? currentLocalItemKey; + private string? currentSessionItemKey; + private string? currentLocalItem; + private string? currentSessionItem; + + private async Task GetItem() + { + currentLocalItem = await localStorage.GetItem(currentLocalItemKey); + + currentSessionItem = await sessionStorage.GetItem(currentSessionItemKey); + } +}"; + private string setItemExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + + + + + +SetItem + +@code { + private string? newLocalItemKey; + private string? newSessionItemKey; + + private async Task SetItem() + { + await localStorage.SetItem(newLocalItemKey, newLocalItemKey); + + await sessionStorage.SetItem(newSessionItemKey, newSessionItemKey); + } +}"; + private string removeItemExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + + + + + +RemoveItem + +@code { + private string? localItemKey; + private string? sessionItemKey; + + private async Task RemoveItem() + { + await localStorage.RemoveItem(localItemKey); + + await sessionStorage.RemoveItem(sessionItemKey); + } +}"; + private string clearItemExampleCode = +@"@inject Bit.Butil.LocalStorage localStorage +@inject Bit.Butil.SessionStorage sessionStorage + +Clear + +@code { + private async Task Clear() + { + await localStorage.Clear(); + + await sessionStorage.Clear(); + } +}"; +} \ No newline at end of file