(query?: NotesQuery)
| 381 | // --- CRUD --- |
| 382 | |
| 383 | export async function getNotes(query?: NotesQuery) { |
| 384 | return withNotesLoading(async () => { |
| 385 | // Защита от гонки ответов: применяется только самый свежий запрос. |
| 386 | const requestToken = ++notesRequestToken |
| 387 | const forSearch = isSearch.value |
| 388 | const resolvedQuery = { |
| 389 | ...(query || queryByLibraryOrFolderOrSearch.value), |
| 390 | ...getContentSortQuery('notes'), |
| 391 | } |
| 392 | |
| 393 | const { data: responseData } = await api.notes.getNotes(resolvedQuery) |
| 394 | |
| 395 | if (requestToken !== notesRequestToken) { |
| 396 | return |
| 397 | } |
| 398 | |
| 399 | const data = responseData as NotesResponse |
| 400 | |
| 401 | if (forSearch) { |
| 402 | notesBySearch.value = data |
| 403 | } |
| 404 | else { |
| 405 | notes.value = data |
| 406 | } |
| 407 | }) |
| 408 | } |
| 409 | |
| 410 | async function withNotesLoading<T>(loader: () => Promise<T>): Promise<T> { |
| 411 | notesLoadingCounter.value += 1 |
no test coverage detected