This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 374
fix: save extension state #6309
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
27fddbb
save name and target state
VanyLaw 2d6bfab
Merge remote-tracking branch 'origin/main' into wenyluo/fix
VanyLaw ee9db73
save extension status
VanyLaw 2442940
Merge branch 'main' into wenyluo/fix
luhan2017 6a0e2f1
remove annotation
VanyLaw 6ba1bd8
Merge branch 'wenyluo/fix' of https://github.com/microsoft/BotFramewo…
VanyLaw 2694e26
Merge remote-tracking branch 'origin/main' into wenyluo/fix
VanyLaw 62efde6
fix comments
VanyLaw 11e3bbb
fix conflict
VanyLaw 05bdda8
Merge branch 'main' into wenyluo/fix
benbrown bc7f820
Merge branch 'main' into wenyluo/fix
luhan2017 c930513
Merge branch 'main' into wenyluo/fix
benbrown cbecc39
Merge branch 'main' into wenyluo/fix
tonyanziano ccb0773
Merge branch 'main' into wenyluo/fix
benbrown f7e98aa
Merge branch 'main' into wenyluo/fix
srinaath 025cb97
use localStorage instead of setExtensionState to parent component to …
VanyLaw 7e1ae1a
Merge branch 'main' into wenyluo/fix
boydc2014 b55d5b4
remove setExtensionState, add useLocalStorage
VanyLaw 800899b
Merge branch 'wenyluo/fix' of https://github.com/microsoft/BotFramewo…
VanyLaw 0535572
polish
VanyLaw 8e3b290
Merge remote-tracking branch 'origin/main' into wenyluo/fix
VanyLaw 8b57d4c
update uselocalStorage, use hooks in extension to save state;
VanyLaw 642b86c
Merge remote-tracking branch 'origin/main' into wenyluo/fix
VanyLaw 2c2a087
fix comments
VanyLaw 6546249
polish
VanyLaw c8e6272
Merge branch 'main' into wenyluo/fix
VanyLaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
Composer/packages/extension-client/src/hooks/useLocalStorage.ts
This file contains hidden or 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,66 @@ | ||
| /* eslint-disable no-underscore-dangle */ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { useCallback } from 'react'; | ||
|
|
||
| const KEY = 'composer:extensions'; | ||
|
|
||
| export function useLocalStorage() { | ||
| const { __extensionId, __bundleId } = window.Composer; | ||
|
|
||
| const getExtensionState = useCallback(() => { | ||
| const allStatesString = window.localStorage.getItem(KEY); | ||
| const allStates = allStatesString ? JSON.parse(allStatesString) : {}; | ||
| const extensionState = allStates?.[__extensionId] || {}; | ||
| return extensionState; | ||
| }, [__extensionId]); | ||
|
|
||
| const updateExtensionState = useCallback( | ||
| (value = undefined) => { | ||
| const allStatesString = window.localStorage.getItem(KEY); | ||
| const allStates = allStatesString ? JSON.parse(allStatesString) : {}; | ||
VanyLaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const extensionState = allStates?.[__extensionId] || {}; | ||
| if (value) { | ||
| extensionState[__bundleId] = value; | ||
| } else { | ||
| delete extensionState[__bundleId]; | ||
| } | ||
| allStates[__extensionId] = extensionState; | ||
| window.localStorage.setItem(KEY, JSON.stringify(allStates)); | ||
| }, | ||
| [__extensionId, __bundleId] | ||
| ); | ||
|
|
||
| const getAll = useCallback(() => { | ||
| return getExtensionState()?.[__bundleId]; | ||
| }, [getExtensionState, __bundleId]); | ||
|
|
||
| const getItem = useCallback( | ||
| (key: string) => { | ||
| return getAll()?.[key]; | ||
| }, | ||
| [getAll] | ||
| ); | ||
|
|
||
| const setItem = useCallback( | ||
| (key: string, value: any) => { | ||
| const bundleState = getAll() || {}; | ||
| bundleState[key] = value; | ||
| updateExtensionState(bundleState); | ||
| }, | ||
| [getAll] | ||
| ); | ||
|
|
||
| const replaceAll = useCallback( | ||
| (value: any) => { | ||
| updateExtensionState(value); | ||
| }, | ||
| [updateExtensionState] | ||
| ); | ||
|
|
||
| const clearAll = useCallback(() => { | ||
| updateExtensionState(); | ||
| }, [updateExtensionState]); | ||
| return { getItem, setItem, getAll, clearAll, replaceAll }; | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.