summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-26 17:05:14 +0200
commitdd72ab05da17309fd5ee6005cdc1fae686b5fa9e (patch)
tree9edc695fffa73a85d94e571f44c7d4c97de71654 /public/assets/js/lib/views
parent3de2a5872fd0481568e918a1ea798b3f75ace610 (diff)
filter by keyword, thread, or username
Diffstat (limited to 'public/assets/js/lib/views')
-rw-r--r--public/assets/js/lib/views/stream/hootstream.js40
-rw-r--r--public/assets/js/lib/views/stream/index.js22
2 files changed, 40 insertions, 22 deletions
diff --git a/public/assets/js/lib/views/stream/hootstream.js b/public/assets/js/lib/views/stream/hootstream.js
index 016c987..4be70bd 100644
--- a/public/assets/js/lib/views/stream/hootstream.js
+++ b/public/assets/js/lib/views/stream/hootstream.js
@@ -3,6 +3,10 @@ const IMAGE_REGEXP = /(.gif|.jpg|.jpeg|.png)$/gi;
var HootStream = View.extend({
el: "#hootstream",
+ events: {
+ "click a": "onClickLink",
+ },
+
initialize: function ({ parent }) {
this.parent = parent;
this.$hootevents = this.$("#hootevents");
@@ -10,6 +14,25 @@ var HootStream = View.extend({
this.threadTemplate = this.$(".threadTemplate").html();
this.lastlogTemplate = this.$(".lastlogTemplate").html();
this.fileTemplate = this.$(".fileTemplate").html();
+ this.onClickLink = this.onClickLink.bind(this);
+ },
+
+ onClickLink: function (event) {
+ // console.log(event.target.className, event.target.href);
+ const url = new URL(event.target.href);
+ switch (event.target.className) {
+ case "file":
+ // play audio?
+ break;
+ case "userLink":
+ case "threadLink":
+ case "keywordLink":
+ event.preventDefault();
+ console.log(">>", url.pathname);
+ app.router.go(url.pathname);
+ break;
+ }
+ // this.parent.onKeyword(keyword)
},
load: function (data) {
@@ -34,6 +57,10 @@ var HootStream = View.extend({
},
render: (template, object) => {
+ if (!template) {
+ console.log("No template", object);
+ return $("<div>No template</div>");
+ }
const rendered = Object.entries(object).reduce(
(newTemplate, [key, value]) =>
newTemplate.replace(new RegExp(`{{${key}}}`, "g"), value),
@@ -99,9 +126,9 @@ var HootStream = View.extend({
"<div class='divider dark'></div>",
this.renderHoot({
template: this.threadTemplate,
- hoot: `<a class="threadLink" href="/details/${thread.id}">${thread.title}</a>`,
+ hoot: `<a class="threadLink" href="/stream/thread/${thread.id}">${thread.title}</a>`,
keyword_link: thread.keyword
- ? `<a class="keywordLink" href="/stream/${thread.keyword}">${thread.keyword}</a>`
+ ? `<a class="keywordLink" href="/stream/keyword/${thread.keyword}">${thread.keyword}</a>`
: "",
username: thread.username,
className: postedToday ? "isRecent" : "",
@@ -155,7 +182,7 @@ var HootStream = View.extend({
});
},
- agglutinate: ({ threads, comments, files, hootbox, lastlog }) =>
+ agglutinate: ({ query, threads, comments, files, hootbox, lastlog }) =>
[
...threads.map((thread) => [
thread.id,
@@ -172,7 +199,12 @@ var HootStream = View.extend({
IMAGE_REGEXP.test(file.filename) ? "images" : "files",
file,
]),
- ...hootbox.map((hoot) => [1, hoot.date, "hoot", hoot]),
+ ...(query.has_query ? [] : hootbox).map((hoot) => [
+ 1,
+ hoot.date,
+ "hoot",
+ hoot,
+ ]),
...lastlog.map((user) => [1, user.lastseen, "lastlog", user]),
]
.sort((a, b) => b[1] - a[1])
diff --git a/public/assets/js/lib/views/stream/index.js b/public/assets/js/lib/views/stream/index.js
index d55a9c3..76dbfa8 100644
--- a/public/assets/js/lib/views/stream/index.js
+++ b/public/assets/js/lib/views/stream/index.js
@@ -1,8 +1,5 @@
var StreamView = View.extend({
- events: {},
-
- action: "/api/stream",
- keywordAction: "/api/keyword/",
+ action: "/api/stream/",
initialize: function (opt) {
// opt.parent = parent
@@ -14,21 +11,10 @@ var StreamView = View.extend({
// this.countdown = new Countdown({ parent: this });
},
- load: function (keyword) {
+ load: function ({ ...target }) {
$("body").addClass("index");
- // if (keyword) {
- // $(".subtitle").html(
- // '<a href="/">&lt; Home</a> &middot; <a href="/keywords">Keywords</a>'
- // );
- // this.threadbox.options.latest = false;
- // this.threadbox.options.welcome = false;
- // $.get(this.keywordAction + keyword, this.populate.bind(this));
- // } else {
- // this.hootbox.options.required = true;
- // this.threadbox.options.latest = true;
- // this.threadbox.options.welcome = true;
- // }
- $.get(this.action, this.populate.bind(this));
+ console.log(target);
+ $.get(this.action, target, this.populate.bind(this));
},
populate: function (data) {