fix: improve maintenance and synchronize live conversations
This commit is contained in:
1 parent
bb541bd212
commit
ef86a5d3af
297 files changed
+2983
-1274
No files matched your search
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { computed, ref, watch, type Ref } from 'vue'
|
||||
import { computed, ref, type Ref } from 'vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
import { faqService } from '@/services/faq'
|
||||
@@ -34,17 +34,13 @@ export function useHelpCenterSettings(settings: Ref<HelpCenterSettings | null>)
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let saveInFlight = false
|
||||
let trailingSave: HelpCenterSettingsUpdate | null = null
|
||||
let suppressWatch = false
|
||||
let debouncedPayload: HelpCenterSettingsUpdate | null = null
|
||||
|
||||
const brandColor = computed(() => settings.value?.brand_color || '#4338CA')
|
||||
|
||||
function applyResponse(updated: HelpCenterSettings): void {
|
||||
suppressWatch = true
|
||||
settings.value = updated
|
||||
// Release after the watcher has seen (and ignored) this assignment.
|
||||
setTimeout(() => {
|
||||
suppressWatch = false
|
||||
}, 0)
|
||||
const pending = { ...(trailingSave || {}), ...(debouncedPayload || {}) }
|
||||
settings.value = { ...updated, ...pending }
|
||||
}
|
||||
|
||||
async function save(payload: HelpCenterSettingsUpdate): Promise<void> {
|
||||
@@ -72,26 +68,25 @@ export function useHelpCenterSettings(settings: Ref<HelpCenterSettings | null>)
|
||||
|
||||
/** Debounced path for text inputs (links, CTA, labels). */
|
||||
function queueSave(payload: HelpCenterSettingsUpdate): void {
|
||||
debouncedPayload = { ...(debouncedPayload || {}), ...payload }
|
||||
if (debounceTimer) clearTimeout(debounceTimer)
|
||||
debounceTimer = setTimeout(() => void save(payload), AUTOSAVE_DEBOUNCE_MS)
|
||||
debounceTimer = setTimeout(() => {
|
||||
debounceTimer = null
|
||||
const queued = debouncedPayload
|
||||
debouncedPayload = null
|
||||
if (queued) void save(queued)
|
||||
}, AUTOSAVE_DEBOUNCE_MS)
|
||||
}
|
||||
|
||||
/** Immediate path for discrete actions (swatch click, toggles, selects). */
|
||||
async function saveNow(payload: HelpCenterSettingsUpdate): Promise<void> {
|
||||
if (debounceTimer) clearTimeout(debounceTimer)
|
||||
await save(payload)
|
||||
debounceTimer = null
|
||||
const combined = { ...(debouncedPayload || {}), ...payload }
|
||||
debouncedPayload = null
|
||||
await save(combined)
|
||||
}
|
||||
|
||||
// Deep-watch branding fields the inputs mutate in place (header_links rows).
|
||||
watch(
|
||||
() => settings.value?.header_links,
|
||||
(links, previous) => {
|
||||
if (suppressWatch || links === undefined || previous === undefined) return
|
||||
queueSave({ header_links: links })
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
async function uploadLogo(file: File): Promise<void> {
|
||||
if (file.size > MAX_LOGO_BYTES) {
|
||||
toast.error('Logo 不能超过 2 MB')
|
||||
|
||||
Reference in new issue
Block a user