Skip to content
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

UBER-872: StyleTextEditor: No update when change text in another text #3698

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/text-editor/src/components/StyledTextBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@

$: if (oldContent !== content) {
oldContent = content
rawValue = content
if (rawValue !== content) {
rawValue = content
textEditor?.setContent(content)
}
modified = false
}
$: if (!modified && rawValue !== content) modified = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Doc, Ref, updateAttribute } from '@hcengineering/core'
import { Doc, updateAttribute } from '@hcengineering/core'

import { IntlString } from '@hcengineering/platform'
import { createQuery, getAttribute, getClient, KeyedAttribute } from '@hcengineering/presentation'
Expand All @@ -27,27 +27,27 @@
export let key: KeyedAttribute
export let placeholder: IntlString
export let focusIndex = -1
let _id: Ref<Doc> | undefined = undefined
let _class: Ref<Class<Doc>> | undefined = undefined
const client = getClient()

const queryClient = createQuery()

let description = ''
let description: string
let haveUnsavedChanges = false

let doc: Doc | undefined
function checkForNewObject (object: Doc) {
if (object._id !== _id) return true
if (object._class !== _class) return true
return false
$: if (object && description === undefined) {
description = getAttribute(client, object, key)
}

// We need to query the document one more time
// To make a difference between update of description from the bottom
// And update to if from another tab.
$: object &&
queryClient.query(object._class, { _id: object._id }, async (result) => {
;[doc] = result
if (doc && checkForNewObject(object)) {
_class = object._class
_id = object._id
description = getAttribute(client, object, key)
queryClient.query(object._class, { _id: object._id }, async (result: Doc[]) => {
if (result.length > 0) {
if (!haveUnsavedChanges) {
haiodo marked this conversation as resolved.
Show resolved Hide resolved
const doc = result[0]
description = getAttribute(client, doc, key)
}
}
})

Expand All @@ -64,17 +64,21 @@
const old = getAttribute(client, object, key)
if (description !== old) {
await updateAttribute(client, object, object._class, key, description)
haveUnsavedChanges = false
haiodo marked this conversation as resolved.
Show resolved Hide resolved
dispatch('saved', true)
setTimeout(() => {
dispatch('saved', false)
}, 2500)
} else {
haveUnsavedChanges = false
}

await descriptionBox.createAttachments()
}

let saveTrigger: any
function triggerSave (): void {
haveUnsavedChanges = true
clearTimeout(saveTrigger)
saveTrigger = setTimeout(save, 2500)
}
Expand All @@ -84,7 +88,7 @@
}
</script>

{#key doc?._id}
{#key object?._id}
<AttachmentStyledBox
{focusIndex}
enableBackReferences={true}
Expand Down