refactor: browser use object
This commit is contained in:
parent
38a405b1c1
commit
7999a23acc
|
@ -1,6 +1,5 @@
|
|||
import statusgo_backend/browser as status_browser
|
||||
import ../eventemitter
|
||||
|
||||
import ./types/[bookmark]
|
||||
|
||||
type
|
||||
|
@ -11,13 +10,13 @@ proc newBrowserModel*(events: EventEmitter): BrowserModel =
|
|||
result = BrowserModel()
|
||||
result.events = events
|
||||
|
||||
proc storeBookmark*(self: BrowserModel, url: string, name: string): Bookmark =
|
||||
result = status_browser.storeBookmark(url, name)
|
||||
proc storeBookmark*(self: BrowserModel, bookmark: Bookmark): Bookmark =
|
||||
return status_browser.storeBookmark(bookmark)
|
||||
|
||||
proc updateBookmark*(self: BrowserModel, ogUrl: string, url: string, name: string) =
|
||||
status_browser.updateBookmark(ogUrl, url, name)
|
||||
proc updateBookmark*(self: BrowserModel, originalUrl: string, bookmark: Bookmark) =
|
||||
status_browser.updateBookmark(originalUrl, bookmark)
|
||||
|
||||
proc getBookmarks*(self: BrowserModel): string =
|
||||
proc getBookmarks*(self: BrowserModel): seq[Bookmark] =
|
||||
result = status_browser.getBookmarks()
|
||||
|
||||
proc deleteBookmark*(self: BrowserModel, url: string) =
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
import core, ../types/[bookmark], json, chronicles
|
||||
import json, chronicles
|
||||
import core
|
||||
import ../types/[bookmark]
|
||||
|
||||
proc storeBookmark*(url: string, name: string): Bookmark =
|
||||
let payload = %* [{"url": url, "name": name}]
|
||||
result = Bookmark(name: name, url: url)
|
||||
proc storeBookmark*(bookmark: Bookmark): Bookmark =
|
||||
let payload = %* [{"url": bookmark.url, "name": bookmark.name}]
|
||||
try:
|
||||
let resp = callPrivateRPC("browsers_storeBookmark", payload).parseJson["result"]
|
||||
result.imageUrl = resp["imageUrl"].getStr
|
||||
bookmark.imageUrl = resp["imageUrl"].getStr
|
||||
return bookmark
|
||||
except Exception as e:
|
||||
error "Error updating bookmark", msg = e.msg
|
||||
discard
|
||||
|
||||
proc updateBookmark*(ogUrl: string, url: string, name: string) =
|
||||
let payload = %* [ogUrl, {"url": url, "name": name}]
|
||||
proc updateBookmark*(originalUrl: string, bookmark: Bookmark) =
|
||||
let payload = %* [originalUrl, {"url": bookmark.url, "name": bookmark.name}]
|
||||
try:
|
||||
discard callPrivateRPC("browsers_updateBookmark", payload)
|
||||
except Exception as e:
|
||||
error "Error updating bookmark", msg = e.msg
|
||||
discard
|
||||
|
||||
proc getBookmarks*(): string =
|
||||
proc getBookmarks*(): seq[Bookmark] =
|
||||
let payload = %* []
|
||||
result = callPrivateRPC("browsers_getBookmarks", payload)
|
||||
try:
|
||||
let responseResult = callPrivateRPC("browsers_getBookmarks", payload).parseJson["result"]
|
||||
if responseResult.kind != JNull:
|
||||
for bookmark in responseResult:
|
||||
result.add(Bookmark(url: bookmark{"url"}.getStr, name: bookmark{"name"}.getStr, imageUrl: bookmark{"imageUrl"}.getStr))
|
||||
except:
|
||||
discard
|
||||
|
||||
proc deleteBookmark*(url: string) =
|
||||
let payload = %* [url]
|
||||
|
|
Loading…
Reference in New Issue