From dd72ab05da17309fd5ee6005cdc1fae686b5fa9e Mon Sep 17 00:00:00 2001 From: julian laplace Date: Wed, 26 Oct 2022 17:05:14 +0200 Subject: filter by keyword, thread, or username --- public/assets/js/lib/views/stream/hootstream.js | 40 ++++++++++++++++++++++--- public/assets/js/lib/views/stream/index.js | 22 +++----------- 2 files changed, 40 insertions(+), 22 deletions(-) (limited to 'public/assets/js/lib/views') 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 $("
No template
"); + } const rendered = Object.entries(object).reduce( (newTemplate, [key, value]) => newTemplate.replace(new RegExp(`{{${key}}}`, "g"), value), @@ -99,9 +126,9 @@ var HootStream = View.extend({ "
", this.renderHoot({ template: this.threadTemplate, - hoot: `${thread.title}`, + hoot: `${thread.title}`, keyword_link: thread.keyword - ? `${thread.keyword}` + ? `${thread.keyword}` : "", 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( - // '< Home · Keywords' - // ); - // 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) { -- cgit v1.2.3-70-g09d2