Revert "Switch to using typeahead for user search"
This reverts commit a3e11e3272
.
This commit is contained in:
parent
a3e11e3272
commit
88b005c9da
5 changed files with 11 additions and 15 deletions
12
src/api.nim
12
src/api.nim
|
@ -115,16 +115,22 @@ proc getGraphTweetSearch*(query: Query; after=""): Future[Timeline] {.async.} =
|
||||||
result = parseGraphSearch(await fetch(url, Api.search), after)
|
result = parseGraphSearch(await fetch(url, Api.search), after)
|
||||||
result.query = query
|
result.query = query
|
||||||
|
|
||||||
proc getUserSearch*(query: Query): Future[Result[User]] {.async.} =
|
proc getUserSearch*(query: Query; page="1"): Future[Result[User]] {.async.} =
|
||||||
if query.text.len == 0:
|
if query.text.len == 0:
|
||||||
return Result[User](query: query, beginning: true)
|
return Result[User](query: query, beginning: true)
|
||||||
|
|
||||||
let
|
let
|
||||||
url = userSearch ? genParams({"q": query.text, "result_type": "users"})
|
page = if page.len == 0: "1" else: page
|
||||||
|
url = userSearch ? genParams({"q": query.text, "skip_status": "1", "page": page})
|
||||||
js = await fetchRaw(url, Api.userSearch)
|
js = await fetchRaw(url, Api.userSearch)
|
||||||
|
|
||||||
result = parseTypeahead(js)
|
result = parseUsers(js)
|
||||||
|
|
||||||
result.query = query
|
result.query = query
|
||||||
|
if page.len == 0:
|
||||||
|
result.bottom = "2"
|
||||||
|
elif page.allCharsInSet(Digits):
|
||||||
|
result.bottom = $(parseInt(page) + 1)
|
||||||
|
|
||||||
proc getPhotoRail*(name: string): Future[PhotoRail] {.async.} =
|
proc getPhotoRail*(name: string): Future[PhotoRail] {.async.} =
|
||||||
if name.len == 0: return
|
if name.len == 0: return
|
||||||
|
|
|
@ -9,7 +9,7 @@ const
|
||||||
activate* = $(api / "1.1/guest/activate.json")
|
activate* = $(api / "1.1/guest/activate.json")
|
||||||
|
|
||||||
photoRail* = api / "1.1/statuses/media_timeline.json"
|
photoRail* = api / "1.1/statuses/media_timeline.json"
|
||||||
userSearch* = api / "1.1/search/typeahead.json"
|
userSearch* = api / "1.1/users/search.json"
|
||||||
|
|
||||||
graphql = api / "graphql"
|
graphql = api / "graphql"
|
||||||
graphUser* = graphql / "u7wQyGi6oExe8_TRWGMq4Q/UserResultByScreenNameQuery"
|
graphUser* = graphql / "u7wQyGi6oExe8_TRWGMq4Q/UserResultByScreenNameQuery"
|
||||||
|
|
|
@ -85,10 +85,3 @@ proc parseUsers*(json: string; after=""): Result[User] =
|
||||||
let raw = json.fromJson(seq[RawUser])
|
let raw = json.fromJson(seq[RawUser])
|
||||||
for user in raw:
|
for user in raw:
|
||||||
result.content.add user.toUser
|
result.content.add user.toUser
|
||||||
|
|
||||||
proc parseTypeahead*(json: string): Result[User] =
|
|
||||||
result = Result[User](beginning: true)
|
|
||||||
|
|
||||||
let raw = json.fromJson(Typeahead)
|
|
||||||
for user in raw.users:
|
|
||||||
result.content.add user.toUser
|
|
||||||
|
|
|
@ -42,6 +42,3 @@ type
|
||||||
|
|
||||||
Color* = object
|
Color* = object
|
||||||
red*, green*, blue*: int
|
red*, green*, blue*: int
|
||||||
|
|
||||||
Typeahead* = object
|
|
||||||
users*: seq[RawUser]
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
redirect("/" & q)
|
redirect("/" & q)
|
||||||
var users: Result[User]
|
var users: Result[User]
|
||||||
try:
|
try:
|
||||||
users = await getUserSearch(query)
|
users = await getUserSearch(query, getCursor())
|
||||||
except InternalError:
|
except InternalError:
|
||||||
users = Result[User](beginning: true, query: query)
|
users = Result[User](beginning: true, query: query)
|
||||||
resp renderMain(renderUserSearch(users, prefs), request, cfg, prefs, title)
|
resp renderMain(renderUserSearch(users, prefs), request, cfg, prefs, title)
|
||||||
|
|
Loading…
Reference in a new issue