change(ui): change notes filtering api
This commit is contained in:
parent
2216e75659
commit
84ec8f4d76
2 changed files with 22 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { makeAutoObservable } from "mobx"
|
||||
import { notesService } from "App/services"
|
||||
import { Note, WriteNote, iTag } from 'App/services/NotesService'
|
||||
import { Note, WriteNote, iTag, NotesFilter } from 'App/services/NotesService'
|
||||
|
||||
interface SessionNotes {
|
||||
[sessionId: string]: Note[]
|
||||
|
|
@ -13,15 +13,25 @@ export default class NotesStore {
|
|||
page = 1
|
||||
pageSize = 15
|
||||
activeTags: iTag[] = []
|
||||
sort = ''
|
||||
order: 'DESC' | 'ASC' = 'DESC'
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this)
|
||||
}
|
||||
|
||||
async fetchNotes() {
|
||||
const filter: NotesFilter = {
|
||||
page: this.page,
|
||||
limit: 15,
|
||||
sort: this.sort,
|
||||
order: this.order,
|
||||
tags: this.activeTags,
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
const notes = await notesService.getNotes()
|
||||
const notes = await notesService.fetchNotes(filter)
|
||||
this.notes = notes;
|
||||
return notes;
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ export interface Note {
|
|||
userId: number
|
||||
}
|
||||
|
||||
export interface NotesFilter {
|
||||
page: number
|
||||
limit: number
|
||||
sort: string
|
||||
order: 'DESC' | 'ASC'
|
||||
tags: iTag[]
|
||||
}
|
||||
|
||||
export default class NotesService {
|
||||
private client: APIClient;
|
||||
|
||||
|
|
@ -45,8 +53,8 @@ export default class NotesService {
|
|||
this.client = client || new APIClient();
|
||||
}
|
||||
|
||||
getNotes(): Promise<Note[]> {
|
||||
return this.client.get('/notes').then(r => {
|
||||
fetchNotes(filter: NotesFilter): Promise<Note[]> {
|
||||
return this.client.post('/notes', filter).then(r => {
|
||||
if (r.ok) {
|
||||
return r.json().then(r => r.data)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue