Store Chat Prompt Input Value in Local Storage#4680
Conversation
|
@timothycarambat Let me know if you would like each chat thread to have it's own stored prompt input state, I can refactor to do that instead if you prefer. |
timothycarambat
left a comment
There was a problem hiding this comment.
A couple comments about UX and scope:
-
Since this is a convenience feature we should treat it like
LAST_VISITED_WORKSPACEas opposed to something critical likeAUTH_TOKEN -
This input should also be workspace/thread specific. If I type an input on workspace 1 and go to workspace 2, I should be able to go back to workspace 1 and see my old prompt that was unsent. Scoping this to workspace/thread would be even better and make more sense. Is this currently the case?
-
How do we clear the session variable when the input is finally sent? What about when the user deletes all text that was in that input?
-
Since the input value can change often it may make sense to put the setItem/update into a
debouncehandler and just run it after 300ms or some other timeframe has settled. This will keep us from spamming updates to localstorage in the event loop - especially if we are going to scope by workspace/thread since there may be a lookup
Considering the above, it may make sense to move all of this to a util so it has a common interface we can import or wrap around the prompt input as a context or provider. Whichever is cleaner.
In terms of UX, it is unlikely we have users on one machine login as another user on the same machine, but an easy way around this is to just removeItem the cached prompt storage item on all login actions. That way we dont need to remove them on all logouts since there are only a small handful of ways to login.
Tangentially, we do have a lot of code duplicated for removeItem of login methods, might be worth visiting that in another future PR as a refactor to make that a common interface so we are not manually managing these storage items in every place we care about them.
…excessive sources
|
• “Since this is a convenience feature…” • “This input should also be workspace/thread specific.” • “How do we clear the session variable when the input is finally sent?” • “It may make sense to move all of this to a util…” If you want me to pull it out, I’d recommend creating a small custom hook ( Let me know which direction you’d prefer and I’ll implement it. |
Let's do this for sure, as long as we can manage and look up the dict, we should be fine.
Once the first point is implemented, I think the footprint may be larger, since now we are CRUD'ing records in a local storage item where we have to stringify/parse JSON over and over. Once the above is implemented, it is worth looking into if this is breaking out into a util - just so management of this functionality is easier to parse. The prompt input is already so complex so making these kinds of things self-contained at least makes the code more readable. |
… into a custom hook | rename localStorage key variables for clarity.
…k to improve performance and prevent writing on every keystroke.
|
Let me know what you think of this approach. |
timothycarambat
left a comment
There was a problem hiding this comment.
Looks good, just some minor changes to use some existing widely used utils for JSON parsing. Additionally, lets remove some verbosity in the comments so its code-readable for the easy stuff
…ze safeJsonParse | Remove uneeeded comments
Pull Request Type
Relevant Issues
resolves #4604
What is in this change?
This PR implements a small feature to save the state of the workspace chat input value in local storage and will be applied as the initial state for all workspace chats if truthy. It also clears this value when in multi-user mode and the current users signs out. It also clears this value in every other auth clearing situation.
Additional Information
Developer Validations
yarn lintfrom the root of the repo & committed changes