Add time range to search panel

This commit is contained in:
Zed 2019-09-19 22:11:38 +02:00
parent 70f89a9502
commit 8324508b2c
6 changed files with 72 additions and 13 deletions

View File

@ -15,7 +15,7 @@ const
# Experimental, this might break in the future # Experimental, this might break in the future
# Till then, it results in shorter urls # Till then, it results in shorter urls
const const
posPrefix = "thGAVUV0VFVBa" posPrefix = "thGAVUV0VFVB"
posSuffix = "EjUAFQAlAFUAFQAA" posSuffix = "EjUAFQAlAFUAFQAA"
template `@`(param: string): untyped = template `@`(param: string): untyped =
@ -28,6 +28,8 @@ proc initQuery*(pms: Table[string, string]; name=""): Query =
text: @"text", text: @"text",
filters: validFilters.filterIt("f-" & it in pms), filters: validFilters.filterIt("f-" & it in pms),
excludes: validFilters.filterIt("e-" & it in pms), excludes: validFilters.filterIt("e-" & it in pms),
since: @"since",
until: @"until"
) )
if name.len > 0: if name.len > 0:
@ -71,6 +73,10 @@ proc genQueryParam*(query: Query): string =
filters.add "-filter:" & e filters.add "-filter:" & e
result = strip(param & filters.join(&" {query.sep} ")) result = strip(param & filters.join(&" {query.sep} "))
if query.since.len > 0:
result &= " since:" & query.since
if query.until.len > 0:
result &= " until:" & query.until
if query.text.len > 0: if query.text.len > 0:
result &= " " & query.text result &= " " & query.text
@ -96,6 +102,11 @@ proc genQueryUrl*(query: Query): string =
for i in query.excludes: for i in query.excludes:
params.add "i-" & i & "=on" params.add "i-" & i & "=on"
if query.since.len > 0:
params.add "since=" & query.since
if query.until.len > 0:
params.add "until=" & query.until
if params.len > 0: if params.len > 0:
result &= params.join("&") result &= params.join("&")
@ -103,4 +114,6 @@ proc cleanPos*(pos: string): string =
pos.multiReplace((posPrefix, ""), (posSuffix, "")) pos.multiReplace((posPrefix, ""), (posSuffix, ""))
proc genPos*(pos: string): string = proc genPos*(pos: string): string =
posPrefix & pos & posSuffix result = posPrefix & pos
if "A==" notin result:
result &= posSuffix

View File

@ -12,7 +12,8 @@ button {
float: right; float: right;
} }
input[type="text"] { input[type="text"],
input[type="date"] {
@include input-colors; @include input-colors;
background-color: $bg_elements; background-color: $bg_elements;
padding: 1px 4px; padding: 1px 4px;
@ -22,6 +23,38 @@ input[type="text"] {
font-size: 14px; font-size: 14px;
} }
input[type="date"]::-webkit-inner-spin-button {
opacity: 0;
margin: 0;
padding: 0;
}
input::-webkit-calendar-picker-indicator {
opacity: 0;
}
input::-webkit-datetime-edit-day-field:focus,
input::-webkit-datetime-edit-month-field:focus,
input::-webkit-datetime-edit-year-field:focus {
background-color: $accent;
color: $fg_color;
outline: none;
}
.date-range {
display: block;
.icon-container {
margin-left: -22px;
margin-right: 4px;
pointer-events: none;
}
.search-title {
margin: 0 2px;
}
}
.icon-button button { .icon-button button {
color: $accent; color: $accent;
text-decoration: none; text-decoration: none;

View File

@ -40,7 +40,7 @@
@include input-colors; @include input-colors;
} }
@include create-toggle(search-panel, 140px); @include create-toggle(search-panel, 190px);
} }
.search-panel { .search-panel {
@ -82,14 +82,14 @@
} }
.profile-tabs { .profile-tabs {
@include search-resize(785px, 5, 185px); @include search-resize(785px, 5, 240px);
@include search-resize(725px, 4, 185px); @include search-resize(725px, 4, 240px);
@include search-resize(600px, 6, 140px); @include search-resize(600px, 6, 190px);
@include search-resize(530px, 5, 185px); @include search-resize(530px, 5, 240px);
@include search-resize(475px, 4, 185px); @include search-resize(480px, 4, 240px);
@include search-resize(406px, 3, 250px); @include search-resize(410px, 3, 305px);
} }
@include search-resize(530px, 5, 185px); @include search-resize(530px, 5, 240px);
@include search-resize(475px, 4, 185px); @include search-resize(480px, 4, 240px);
@include search-resize(406px, 3, 250px); @include search-resize(410px, 3, 305px);

View File

@ -66,6 +66,8 @@ type
includes*: seq[string] includes*: seq[string]
excludes*: seq[string] excludes*: seq[string]
fromUser*: seq[string] fromUser*: seq[string]
since*: string
until*: string
sep*: string sep*: string
Result*[T] = ref object Result*[T] = ref object

View File

@ -83,3 +83,8 @@ proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
option(value=opt, selected=""): text opt option(value=opt, selected=""): text opt
else: else:
option(value=opt): text opt option(value=opt): text opt
proc genDate*(pref, state: string): VNode =
buildHtml(span):
verbatim &"<input name={pref} type=\"date\" value=\"{state}\"/>"
icon "calendar"

View File

@ -76,6 +76,12 @@ proc renderSearchPanel*(query: Query): VNode =
else: k in query.excludes else: k in query.excludes
genCheckbox(&"{f[0]}-{k}", v, state) genCheckbox(&"{f[0]}-{k}", v, state)
span(class="search-title"): text "Time range"
tdiv(class="date-range"):
genDate("since", query.since)
span(class="search-title"): text "-"
genDate("until", query.until)
proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode = proc renderTweetSearch*(tweets: Result[Tweet]; prefs: Prefs; path: string): VNode =
let query = tweets.query let query = tweets.query
buildHtml(tdiv(class="timeline-container")): buildHtml(tdiv(class="timeline-container")):