Create separate page for new thread modal.
This commit is contained in:
parent
c966ec8f92
commit
76c7f43079
4 changed files with 39 additions and 58 deletions
|
|
@ -4,18 +4,20 @@ from dom import window, Location
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import jester/patterns
|
import jester/patterns
|
||||||
|
|
||||||
import threadlist, postlist, header, profile
|
import threadlist, postlist, header, profile, newthread
|
||||||
import karaxutils
|
import karaxutils
|
||||||
|
|
||||||
type
|
type
|
||||||
State = ref object
|
State = ref object
|
||||||
url: Location
|
url: Location
|
||||||
profile: ProfileState
|
profile: ProfileState
|
||||||
|
newThread: NewThread
|
||||||
|
|
||||||
proc newState(): State =
|
proc newState(): State =
|
||||||
State(
|
State(
|
||||||
url: window.location,
|
url: window.location,
|
||||||
profile: newProfileState()
|
profile: newProfileState(),
|
||||||
|
newThread: newNewThread()
|
||||||
)
|
)
|
||||||
|
|
||||||
var state = newState()
|
var state = newState()
|
||||||
|
|
@ -46,6 +48,10 @@ proc render(): VNode =
|
||||||
result = buildHtml(tdiv()):
|
result = buildHtml(tdiv()):
|
||||||
renderHeader()
|
renderHeader()
|
||||||
route([
|
route([
|
||||||
|
r("/newthread",
|
||||||
|
(params: Params) =>
|
||||||
|
(render(state.newThread))
|
||||||
|
),
|
||||||
r("/profile/@username",
|
r("/profile/@username",
|
||||||
(params: Params) =>
|
(params: Params) =>
|
||||||
(render(state.profile, params["username"]))
|
(render(state.profile, params["username"]))
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,17 @@ when defined(js):
|
||||||
import karaxutils
|
import karaxutils
|
||||||
|
|
||||||
type
|
type
|
||||||
NewThreadModal* = ref object
|
NewThread* = ref object
|
||||||
shown: bool
|
|
||||||
loading: bool
|
loading: bool
|
||||||
onNewThread: proc (threadId, postId: int)
|
|
||||||
error: Option[PostError]
|
error: Option[PostError]
|
||||||
replyBox: ReplyBox
|
replyBox: ReplyBox
|
||||||
|
|
||||||
proc onCreatePost(httpStatus: int, response: kstring, state: NewThreadModal) =
|
proc onCreatePost(httpStatus: int, response: kstring, state: NewThread) =
|
||||||
postFinished:
|
postFinished:
|
||||||
state.shown = false
|
# TODO
|
||||||
state.onNewThread(0, 0) # TODO
|
discard
|
||||||
|
|
||||||
proc onCreateClick(ev: Event, n: VNode, state: NewThreadModal) =
|
proc onCreateClick(ev: Event, n: VNode, state: NewThread) =
|
||||||
state.loading = true
|
state.loading = true
|
||||||
state.error = none[PostError]()
|
state.error = none[PostError]()
|
||||||
|
|
||||||
|
|
@ -32,46 +30,22 @@ when defined(js):
|
||||||
ajaxPost(uri, @[], cast[cstring](formData),
|
ajaxPost(uri, @[], cast[cstring](formData),
|
||||||
(s: int, r: kstring) => onCreatePost(s, r, state))
|
(s: int, r: kstring) => onCreatePost(s, r, state))
|
||||||
|
|
||||||
proc onClose(ev: Event, n: VNode, state: NewThreadModal) =
|
proc newNewThread*(): NewThread =
|
||||||
state.shown = false
|
NewThread(
|
||||||
ev.preventDefault()
|
|
||||||
|
|
||||||
proc newNewThreadModal*(
|
|
||||||
onNewThread: proc (threadId, postId: int)
|
|
||||||
): NewThreadModal =
|
|
||||||
NewThreadModal(
|
|
||||||
shown: false,
|
|
||||||
onNewThread: onNewThread,
|
|
||||||
replyBox: newReplyBox(nil)
|
replyBox: newReplyBox(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
proc show*(state: NewThreadModal) =
|
proc render*(state: NewThread): VNode =
|
||||||
state.shown = true
|
|
||||||
|
|
||||||
proc render*(state: NewThreadModal): VNode =
|
|
||||||
result = buildHtml():
|
result = buildHtml():
|
||||||
tdiv(class=class({"active": state.shown}, "modal modal-lg"),
|
section(class="container grid-xl"):
|
||||||
id="new-thread-modal"):
|
tdiv(id="new-thread"):
|
||||||
a(href="", class="modal-overlay", "aria-label"="close",
|
tdiv(class="title"):
|
||||||
onClick=(ev: Event, n: VNode) => onClose(ev, n, state))
|
p(): text "New Thread"
|
||||||
tdiv(class="modal-container"):
|
|
||||||
tdiv(class="modal-header"):
|
|
||||||
a(href="", class="btn btn-clear float-right",
|
|
||||||
"aria-label"="close",
|
|
||||||
onClick=(ev: Event, n: VNode) => onClose(ev, n, state))
|
|
||||||
tdiv(class="modal-title h5"):
|
|
||||||
text "New Thread"
|
|
||||||
tdiv(class="modal-body"):
|
|
||||||
tdiv(class="content"):
|
tdiv(class="content"):
|
||||||
input(class="form-input", `type`="text", name="username",
|
input(class="form-input", `type`="text", name="username",
|
||||||
placeholder="Type the title here")
|
placeholder="Type the title here")
|
||||||
renderContent(state.replyBox, none[Thread](), none[Post]())
|
renderContent(state.replyBox, none[Thread](), none[Post]())
|
||||||
|
tdiv(class="footer"):
|
||||||
tdiv(class="modal-footer"):
|
|
||||||
button(class="btn",
|
|
||||||
onClick=(ev: Event, n: VNode) =>
|
|
||||||
onClose(ev, n, state)):
|
|
||||||
text "Cancel"
|
|
||||||
button(class=class(
|
button(class=class(
|
||||||
{"loading": state.loading},
|
{"loading": state.loading},
|
||||||
"btn btn-primary"
|
"btn btn-primary"
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ $logo-height: $navbar-height - 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#new-thread-modal {
|
#new-thread {
|
||||||
.modal-container .modal-body {
|
.modal-container .modal-body {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
|
|
@ -124,9 +124,13 @@ $logo-height: $navbar-height - 20px;
|
||||||
|
|
||||||
textarea.form-input, .panel-body > div {
|
textarea.form-input, .panel-body > div {
|
||||||
margin-top: $control-padding-y*2;
|
margin-top: $control-padding-y*2;
|
||||||
resize: none;
|
resize: vertical;
|
||||||
min-height: 40vh;
|
min-height: 40vh;
|
||||||
max-height: 45vh;
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
float: right;
|
||||||
|
margin-top: $control-padding-y*2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,22 +24,20 @@ when defined(js):
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [vstyles, kajax, kdom]
|
import karax / [vstyles, kajax, kdom]
|
||||||
|
|
||||||
import karaxutils, error, newthread
|
import karaxutils, error
|
||||||
|
|
||||||
type
|
type
|
||||||
State = ref object
|
State = ref object
|
||||||
list: Option[ThreadList]
|
list: Option[ThreadList]
|
||||||
loading: bool
|
loading: bool
|
||||||
status: HttpCode
|
status: HttpCode
|
||||||
newThread: NewThreadModal
|
|
||||||
|
|
||||||
proc onNewThread(threadId, postId: int)
|
proc onNewThread(threadId, postId: int)
|
||||||
proc newState(): State =
|
proc newState(): State =
|
||||||
State(
|
State(
|
||||||
list: none[ThreadList](),
|
list: none[ThreadList](),
|
||||||
loading: false,
|
loading: false,
|
||||||
status: Http200,
|
status: Http200
|
||||||
newThread: newNewThreadModal(onNewThread)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -63,8 +61,8 @@ when defined(js):
|
||||||
button(class="btn btn-link"): text "Most Active"
|
button(class="btn btn-link"): text "Most Active"
|
||||||
button(class="btn btn-link"): text "Categories"
|
button(class="btn btn-link"): text "Categories"
|
||||||
section(class="navbar-section"):
|
section(class="navbar-section"):
|
||||||
button(class="btn btn-secondary",
|
a(href=makeUri("/newthread"), onClick=anchorCB):
|
||||||
onClick=(e: Event, n: VNode) => state.newThread.show()):
|
button(class="btn btn-secondary"):
|
||||||
italic(class="fas fa-plus")
|
italic(class="fas fa-plus")
|
||||||
text " New Thread"
|
text " New Thread"
|
||||||
|
|
||||||
|
|
@ -182,4 +180,3 @@ when defined(js):
|
||||||
result = buildHtml(tdiv):
|
result = buildHtml(tdiv):
|
||||||
genTopButtons()
|
genTopButtons()
|
||||||
genThreadList()
|
genThreadList()
|
||||||
render(state.newThread)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue