|
157 | 157 |
|
158 | 158 | // Initialize Loro manager for the current note |
159 | 159 | $effect(() => { |
160 | | - if (!id || !note || !data.user) return; |
| 160 | + const currentNote = note; |
| 161 | + if (!id || !currentNote || !data.user) return; |
161 | 162 |
|
162 | 163 | if (!loroManagers.has(id)) { |
163 | 164 | console.log(`Initializing Loro manager for ${id}`); |
|
166 | 167 | try { |
167 | 168 | // Decrypt the note key if it's an envelope (long) |
168 | 169 | // If it's short (raw key), use it directly. |
169 | | - let noteKey = note.encryptedKey; |
170 | | - if (note.encryptedKey.length > 60) { |
| 170 | + let noteKey = currentNote.encryptedKey; |
| 171 | + if (currentNote.encryptedKey.length > 60) { |
171 | 172 | const rawPrivKey = sessionStorage.getItem( |
172 | 173 | "notes_raw_private_key", |
173 | 174 | ); |
|
177 | 178 | ); |
178 | 179 | return; |
179 | 180 | } |
180 | | - noteKey = decryptKey(note.encryptedKey, rawPrivKey); |
| 181 | + noteKey = decryptKey(currentNote.encryptedKey, rawPrivKey); |
181 | 182 | } |
182 | 183 |
|
183 | 184 | // Create manager |
|
189 | 190 | // But we do update 'updatedAt' and maybe 'loroSnapshot' column? |
190 | 191 | // The updateNote command handles updating the snapshot column. |
191 | 192 | // Re-check data.user here as it might have changed or TS doesn't know |
192 | | - if (data.user && note.ownerId === data.user.id) { |
| 193 | + if (data.user && currentNote.ownerId === data.user.id) { |
193 | 194 | await updateNote({ noteId: id, loroSnapshot: snapshot }); |
194 | 195 | } else { |
195 | 196 | // Federated/Shared notes: We don't save snapshots to 'notes' table (as we don't own it). |
|
198 | 199 | // console.debug("[Loro] Skipping snapshot save for non-owned note"); |
199 | 200 | } |
200 | 201 | }, |
201 | | - note.loroSnapshot, |
| 202 | + currentNote.loroSnapshot, |
202 | 203 | ); |
203 | 204 |
|
204 | 205 | // Start sync |
|
0 commit comments