-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/implement local storage persistence - WF-93 #687
base: dev
Are you sure you want to change the base?
feat/implement local storage persistence - WF-93 #687
Conversation
87daa7d
to
896cb5e
Compare
896cb5e
to
e27f527
Compare
src/ui/src/core/index.ts
Outdated
const localStorageItems = {}; | ||
for (let i = 0; i < localStorage.length; i++) { | ||
const key = localStorage.key(i); | ||
if (key.startsWith("wf.")) { | ||
const value = localStorage.getItem(key); | ||
localStorageItems[key.replace("wf.", "")] = JSON.parse(value); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one value is not valid JSON, it'll throw and stop the execution of the initSession
. It might be better to catch it and remove the entry if so.
It could be something like
Object.entries(localStorage)
.filter(([key]) => key.startsWith("wf."))
.reduce((acc, [key, value]) => {
try {
acc[key.replace('wf.', '')] = JSON.parse(value)
} catch {
localStorage.removeItem(key)
}
}, {});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to remove this mechanism to use an interface closer to that of the browser. WF will only write strings to local storage. All keys will be loaded at startup and transferred to the backend.
I think there is no need to add error checking in this scenario. Am I right ?
src/ui/src/core/index.ts
Outdated
addMailSubscription("localStorageSetItem", (event) => { | ||
localStorage.setItem("wf." + event.key, JSON.stringify(event.value)); | ||
}); | ||
addMailSubscription("localStorageRemoveItem", (event) => { | ||
localStorage.removeItem("wf." + event.key); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add the type
addMailSubscription("localStorageSetItem", (event) => { | |
localStorage.setItem("wf." + event.key, JSON.stringify(event.value)); | |
}); | |
addMailSubscription("localStorageRemoveItem", (event) => { | |
localStorage.removeItem("wf." + event.key); | |
}); | |
addMailSubscription("localStorageSetItem", (event: LocalStorageSetItemEvent) => { | |
localStorage.setItem("wf." + event.key, JSON.stringify(event.value)); | |
}); | |
addMailSubscription("localStorageRemoveItem", (event: LocalStorageRemoveItemEvent) => { | |
localStorage.removeItem("wf." + event.key); | |
}); |
e27f527
to
5ec15a2
Compare
src/writer/core.py
Outdated
@@ -153,6 +157,19 @@ def __init__(self, session_id: str, cookies: Optional[Dict[str, str]], headers: | |||
def update_last_active_timestamp(self) -> None: | |||
self.last_active_timestamp = int(time.time()) | |||
|
|||
def process_local_storage_changes(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required anymore
5ec15a2
to
d6d7982
Compare
* feat: propagate local storage into session to keep it into sync
d6d7982
to
e57612c
Compare
The application can save values in local storage and retrieve them when the user reloads their page. This pattern allows you to introduce persistence beyond the current session.
implement #578