summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
authorjulian laplace <julescarbon@gmail.com>2022-10-27 13:30:26 +0200
committerjulian laplace <julescarbon@gmail.com>2022-10-27 13:30:26 +0200
commit6d672ffa9d7df081034dc5afda6ee7eab829dd7d (patch)
tree7ee6f1a92b1d9665086e0ee682a49bd116ee69d7 /public/assets/js
parentae29144f18bbd0cac3c65ae4bf869fade1c5ffb0 (diff)
fix sorting
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/views/stream/hootfilters.js2
-rw-r--r--public/assets/js/lib/views/stream/hootstream.js62
-rw-r--r--public/assets/js/util/format.js11
3 files changed, 61 insertions, 14 deletions
diff --git a/public/assets/js/lib/views/stream/hootfilters.js b/public/assets/js/lib/views/stream/hootfilters.js
index cfcbdf0..5b46a1d 100644
--- a/public/assets/js/lib/views/stream/hootfilters.js
+++ b/public/assets/js/lib/views/stream/hootfilters.js
@@ -85,6 +85,8 @@ var HootFilters = View.extend({
? this.state.order === "desc"
? "asc"
: "desc"
+ : value === "date"
+ ? "desc"
: "asc",
});
this.parent.onFilter(this.state);
diff --git a/public/assets/js/lib/views/stream/hootstream.js b/public/assets/js/lib/views/stream/hootstream.js
index 2789dee..6c02cc6 100644
--- a/public/assets/js/lib/views/stream/hootstream.js
+++ b/public/assets/js/lib/views/stream/hootstream.js
@@ -12,6 +12,7 @@ var HootStream = View.extend({
this.threadTemplate = this.$(".threadTemplate").html();
this.lastlogTemplate = this.$(".lastlogTemplate").html();
this.fileTemplate = this.$(".fileTemplate").html();
+ this.imageTemplate = this.$(".imageTemplate").html();
this.onClickLink = this.onClickLink.bind(this);
},
@@ -155,6 +156,8 @@ var HootStream = View.extend({
audio.init();
},
+ /** Render Methods */
+
render: (template, object) => {
if (!template) {
console.error("No template", object);
@@ -235,6 +238,7 @@ var HootStream = View.extend({
0.0,
1.0
);
+
// console.log(thread);
return [
"<div class='divider dark'></div>",
@@ -253,24 +257,64 @@ var HootStream = View.extend({
comment_count: `${thread.comment_count || 0} c.`,
comment_opacity: age_opacity * get_size_opacity(thread.comment_count),
}),
+ // this.renderImages(
+ // isViewingThread || postedToday ? images : images.slice(0, 6)
+ // ),
this.renderFiles(
isViewingThread || postedToday ? files : files.slice(0, 10)
),
...this.renderHoots({
- hoots: comments.slice(0, 1).map(trimComment(isViewingThread)),
+ hoots: comments
+ .slice(0, 1)
+ .map(
+ trimComment({
+ isViewingThread,
+ lines: 5,
+ snippetSize: 512,
+ cropSize: 256,
+ })
+ ),
className: "first_post",
}),
...this.renderHoots({
hoots:
isViewingThread || postedToday
- ? comments.slice(1)
- : comments.slice(1).slice(-5).map(trimComment(isViewingThread)),
+ ? comments
+ .slice(1)
+ .map(
+ trimComment({
+ isViewingThread,
+ lines: 1,
+ snippetSize: 256,
+ cropSize: 128,
+ })
+ )
+ : comments
+ .slice(1)
+ .slice(-5)
+ .map(
+ trimComment({
+ isViewingThread,
+ lines: 1,
+ snippetSize: 256,
+ cropSize: 128,
+ })
+ ),
}),
"<div class='divider'></div>",
];
- // say "in ... "
- // audio player OR recent file list
- // recent 3 comments
+ },
+
+ renderImages: function (files) {
+ if (!files.length) {
+ return null;
+ }
+ const $table = $("<div class='imageList'>");
+ for (const file of files) {
+ const $el = this.renderFile(this.imageTemplate, file);
+ $table.append($el);
+ }
+ return $table;
},
renderFiles: function (files) {
@@ -279,18 +323,18 @@ var HootStream = View.extend({
}
const $table = $("<div class='fileList'>");
for (const file of files) {
- const $el = this.renderFile(file);
+ const $el = this.renderFile(this.fileTemplate, file);
$table.append($el);
}
return $table;
},
- renderFile: function (file) {
+ renderFile: function (template, file) {
var size = hush_size(file.size);
var datetime = verbose_date(file.date, true);
var date_class = carbon_date(file.date);
var link = make_link(file);
- return this.render(this.fileTemplate, {
+ return this.render(template, {
id: file.id,
username: file.username,
link,
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
index 224678e..cb3d92e 100644
--- a/public/assets/js/util/format.js
+++ b/public/assets/js/util/format.js
@@ -304,19 +304,20 @@ function get_scale_opacity(value, scale) {
}
return scale[scale.length - 1][1];
}
-function trimComment(isViewingThread) {
+function trimComment({ isViewingThread, lines, snippetSize, cropSize }) {
return function (comment) {
- return isViewingThread || comment.comment.length < 256
+ return isViewingThread || comment.comment.length < (cropSize || 256)
? comment
: {
...comment,
comment:
comment.comment
.split("\n")
- .slice(0, 5)
+ .slice(0, lines || 5)
.join("\n")
- .substr(0, 512)
- .replace(/\s+\w+$/, "") +
+ .substr(0, snippetSize || 512)
+ .replace(/\s+\w+$/, "")
+ .replace(/<[^>]+$/, "") +
`... <a href="/stream/thread/${comment.thread}" class="readMore">Read more...</a>`,
};
};