mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-11-23 17:54:55 +09:00
Keep an unsent message as a draft while switching rooms
The composer stores what's being written in localStorage per room and restores it when the room is opened again. Sending clears it.
This commit is contained in:
1 parent
8fa6138fb9
commit
5c5821a395
3 files changed
+46
-1
No files matched your search
@@ -12,11 +12,21 @@ export default class extends Controller {
|
||||
#files = []
|
||||
|
||||
connect() {
|
||||
this.#restoreDraft()
|
||||
|
||||
if (!this.#usingTouchDevice) {
|
||||
onNextEventLoopTick(() => this.textTarget.focus())
|
||||
}
|
||||
}
|
||||
|
||||
saveDraft() {
|
||||
if (this.textTarget.isBlank) {
|
||||
localStorage.removeItem(this.#draftKey)
|
||||
} else {
|
||||
localStorage.setItem(this.#draftKey, this.textTarget.value)
|
||||
}
|
||||
}
|
||||
|
||||
submit(event) {
|
||||
event.preventDefault()
|
||||
|
||||
@@ -107,6 +117,19 @@ export default class extends Controller {
|
||||
this.fieldsTarget.disabled = true
|
||||
}
|
||||
|
||||
#restoreDraft() {
|
||||
const draft = localStorage.getItem(this.#draftKey)
|
||||
|
||||
if (draft) {
|
||||
this.textTarget.value = draft
|
||||
this.textTarget.selection.placeCursorAtTheEnd()
|
||||
}
|
||||
}
|
||||
|
||||
get #draftKey() {
|
||||
return `composer-draft-${this.roomIdValue}`
|
||||
}
|
||||
|
||||
get #usingTouchDevice() {
|
||||
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
|
||||
}
|
||||
@@ -158,6 +181,7 @@ export default class extends Controller {
|
||||
|
||||
#reset() {
|
||||
this.textTarget.value = ""
|
||||
localStorage.removeItem(this.#draftKey)
|
||||
}
|
||||
|
||||
#updateFileList() {
|
||||
|
||||
Reference in new issue
Block a user