feat(google-docs): overwrite-confirm on sync conflict and last-synced indicator

This commit is contained in:
Gagancreates 2026-06-01 02:35:29 +05:30
parent 7e6ee040aa
commit ccdfc0f6e9
2 changed files with 23 additions and 1 deletions

View file

@ -1454,7 +1454,19 @@ function App() {
setGoogleDocSyncDirection('up')
markRecentLocalMarkdownWrite(path)
try {
const result = await window.ipc.invoke('google-docs:sync', { path, markdown })
let result = await window.ipc.invoke('google-docs:sync', { path, markdown })
if (result.conflict) {
const overwrite = window.confirm(
'This Google Doc changed since your last sync.\n\n' +
'Overwrite it with your local version? Cancel to keep the remote copy ' +
'(use “Sync down” to pull it first).',
)
if (!overwrite) {
toast.info('Sync up cancelled — remote Google Doc is unchanged')
return
}
result = await window.ipc.invoke('google-docs:sync', { path, markdown, force: true })
}
if (!result.synced) {
throw new Error(result.error || 'This note is not linked to a Google Doc.')
}
@ -5776,6 +5788,7 @@ function App() {
googleDoc={linkedGoogleDoc && !isViewingHistory ? {
title: linkedGoogleDoc.title,
isSyncing: isActive ? googleDocSyncDirection : null,
lastSyncedAt: linkedGoogleDoc.syncedAt,
onOpen: () => {
if (linkedGoogleDoc.url) {
window.open(linkedGoogleDoc.url, '_blank')

View file

@ -39,9 +39,11 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { formatRelativeTime } from '@/lib/relative-time'
interface EditorToolbarProps {
editor: Editor | null
@ -56,6 +58,7 @@ interface EditorToolbarProps {
export interface GoogleDocToolbarState {
title: string
isSyncing?: 'up' | 'down' | null
lastSyncedAt?: string
onOpen: () => void
onSyncDown: () => void
onSyncUp: () => void
@ -470,6 +473,12 @@ export function EditorToolbar({
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel className="font-normal text-muted-foreground">
{googleDoc.lastSyncedAt
? `Last synced ${formatRelativeTime(googleDoc.lastSyncedAt)}`
: 'Not synced yet'}
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={googleDoc.onOpen}>
<GoogleDriveIcon className="size-4 mr-2" />
Open Google Doc