Moved lodash templates to react files

This commit is contained in:
Jesper Wrang 2018-01-14 11:12:41 +01:00
parent d9fef06004
commit 3f9786fda7
12 changed files with 146 additions and 183 deletions

View file

@ -1,25 +0,0 @@
<%
var isRemoved = _.has(comment,"removed");
var isDeleted = _.has(comment,"deleted");
var commentCss = "comment comment-" + (isRemoved ? "removed" : (isDeleted ? "deleted" : (comment.depth % 2 == 0 ? "even" : "odd")));
%>
<div id="<%= id %>" class="<%= commentCss %>">
<div class="comment-head">
<a href="javascript:void(0)" class="author">[]</a>
<a href="https://www.reddit.com/user/<%= comment.author %>" class="author comment-author">
<%= comment.author+(isDeleted ? " (deleted by user)" : "") %>
</a>
<span class="comment-score"><%= Format.prettyScore(comment.score) %> point<%= ((comment.score == 1) ? "": "s") %></span>
<span class="comment-time"><%= Format.prettyDate(comment.created_utc) %></span>
</div>
<div class="comment-body">
<%= (comment.body === "[removed]" && isRemoved ? "<p>[likely removed by automoderator]</p>" : Format.parse(comment.body)) %>
</div>
<div class="comment-links">
<a href="/r/<%= Reddit.subreddit %>/comments/<%= Reddit.threadID %>/_/<%= id %>/">permalink</a>
<a href="https://www.reddit.com/r/<%= Reddit.subreddit %>/comments/<%= Reddit.threadID %>/_/<%= id %>/">reddit</a>
</div>
</div>

View file

@ -1,78 +0,0 @@
var radioInput = function(name, displayNames, values) {
var inputs = "";
for(var i = 0, len = displayNames.length; i < len; i++){
inputs += '<span class="radioButton"'+ (Vars.lookup[name] === values[i] ? ' style="background: #239f2b; color:#fff"':'')+'>';
inputs += '<input type="radio" id="'+name+i+'" name="'+name+'" onchange="CSS.radio(this)"';
inputs += 'value="'+values[i]+'" '+(Vars.lookup[name] === values[i] ? ' checked "':'')+' >';
inputs += '<label for="'+name+i+'">'+displayNames[i]+'</label></span>';
}
return inputs;
};
var textInput = function(name){
return '<input type="text" name="'+name+'" id="'+name+'" value="'+Vars.get(name)+'">';
};
var label = function(name, display) {
return '<label for="'+name+'">'+display+': </label>';
};
var inputRow = function(text, input) {
return '<div class="search-row"><span class="search-left">'+text+'</span><span>'+input+"</span></div>";
};
var selectTime = function() {
var values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"];
var display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"];
var html = '<select name="time" id="time">';
for(var i = 0, len = values.length; i < len; i++) {
html += '<option value="'+values[i]+'"' + ((Vars.get("time") === values[i]) ? " selected" : '')+'>'+display[i]+'</option>';
}
return html + "</select>";
};
var select = function(name, display, values){
var html = '<select name="'+name+'" id="'+name+'">';
for(var i = 0, len = values.length; i < len; i++) {
html += '<option value="'+values[i]+'"' + ((Vars.get(name) === values[i]) ? " selected" : '')+'>'+display[i]+'</option>';
}
return html + "</select>";
};
return {
createSearch: function(){
var searchBox = document.createElement("div");
searchBox.id = "main-box";
searchBox.className = "search-box";
/*
Comments:
text (body) string
title (title) string
subreddit (subreddit) string
author (author) string
over_18 (over_18) sfw,nsfw,both *
locked (locked) bool *
between (after/before) "date"
sort (sort) asc,desc
*/
var html = inputRow('Im looking for: ', radioInput("thread", ["Thread","Comment"], ["true", "false"]));
html += inputRow(label("text", "Text"), textInput("text"));
html += inputRow(label("title","Title"), textInput("title"));
html += inputRow(label("subreddit", "Subreddit"), textInput("subreddit"));
html += inputRow(label("author", "Author"), textInput("author"));
html += inputRow("Over 18: ", radioInput("over_18", ["Both","NSFW","SFW"], ["both","nsfw","sfw"]));
html += inputRow("Locked: ", radioInput("locked", ["Both","True", "False"], ["both","true","false"]));
html += inputRow("Removed: ", select("removed", ["Removed and non-removed", "Only removed", "Only deleted"], ["all", "removed", "deleted"]));
html += inputRow("From:", selectTime());
html += inputRow("Sort: ", select("sort", ["Highest score","Lowest score","Newest","Oldest"], ["score_desc","score_asc","time_desc","time_asc"]));
html += '<input type="button" value="'+(showAdvanced?'Hide':'Show')+' advanced">';
html += '<input type="submit" value="Search">';
searchBox.innerHTML = html;
mainDiv.appendChild(searchBox);

View file

@ -1,13 +0,0 @@
<div class="subreddit-info">
top post of <a href="https://www.reddit.com/r/<%= subreddit %>">/r/<%= subreddit %></a> from:
<select onchange="Vars.reload(this)">
<option value="hour"<% if(time === "hour"){ %> selected<% } %>>past hour</option>
<option value="12hour"<% if(time === "12hour"){ %> selected<% } %>>past 12 hours</option>
<option value="day"<% if(time === "day"){ %> selected<% } %>>past day</option>
<option value="week"<% if(time === "week"){ %> selected<% } %>>past week</option>
<option value="month"<% if(time === "month"){ %> selected<% } %>>past month</option>
<option value="6month"<% if(time === "6month"){ %> selected<% } %>>past 6 months</option>
<option value="year"<% if(time === "year"){ %> selected<% } %>>past year</option>
<option value="all"<% if(time === "all"){ %> selected<% } %>>all time</option>
</select>
</div>

View file

@ -1,14 +0,0 @@
<div id="pagination">
Page:
<% if(start > 1) { %>
<a href="<%= urlBase+1 %>">1</a> ...
<% }
for(var i = start; i <= end; i++) {
if(currentPage === i) { %>
<span><%= i %></span>
<% } else { %>
<a href="<%= urlBase+i %>"><%= i %></a>
<% }
} %>
</div>

View file

@ -1,44 +0,0 @@
<div class="thread">
<% if(typeof postNr !== "undefined") { %>
<span class="post-rank"><%= postNr %></span>
<% } %>
<div class="thread-score-box">
<div class="vote upvote"></div>
<div class="thread-score"><%= Format.prettyScore(thread.score) %></div>
<div class="vote downvote"></div>
</div>
<% var url = _.replace(thread.url, "https://www.reddit.com", "https://www.removeddit.com");
if(_.includes(["self", "default", "image", "nsfw"], thread.thumbnail)) { %>
<a href="<%= url %>" class="thumbnail thumbnail-<%= thread.thumbnail%>"></a>
<% } else {
var thumbnailWidth = _.defaultTo(thread.thumbnail_width, 140) * 0.5;
var thumbnailHeight = _.defaultTo(thread.thumbnail_height, 140) * 0.5;
%> <a href="<%= url %>">
<img class="thumbnail" src="<%= thread.thumbnail %>" width="<%= thumbnailWidth %>" height="<%= thumbnailHeight %>">
</a>
<% } %>
<div class="thread-content">
<a class="thread-title" href="<%= url %>"><%= thread.title %></a>
<% if(!_.isNil(thread.link_flair_text)){ %>
<span class="link-flair"><%= thread.link_flair_text %></span>
<% } %>
<span class="domain">(<%= thread.domain %>)</span>
<div class="thread-info">
submitted <span class="thread-time"><%= Format.prettyDate(thread.created_utc) %></span> by
<a class="thread-author author" href="https://www.reddit.com/user/<%= thread.author %>"><%= thread.author %></a>
<% if(Reddit.isAll){ %>
to <a class="subreddit-link author" href="/r/<%= thread.subreddit %>">/r/<%= thread.subreddit %></a>
<% } %>
</div>
<div class="total-comments">
<a class="grey-link" href="<%= thread.permalink %>">
<b><%= thread.num_comments %> comments</b>
</a>
<a class="grey-link" href="https://www.reddit.com<%= thread.permalink %>">
<b>reddit</b>
</a>
</div>
</div>
</div>

View file

@ -1,4 +0,0 @@
<div id="comment-info">
removed comments: <%= removedComments %>/<%= totalComments %> (<%= (100 * removedComments / totalComments).toFixed(1) %>%)
</div>
<div id="comment-sort">sorted by: top</div>

View file

@ -0,0 +1,25 @@
// <%
// var isRemoved = _.has(comment,"removed");
// var isDeleted = _.has(comment,"deleted");
// var commentCss = "comment comment-" + (isRemoved ? "removed" : (isDeleted ? "deleted" : (comment.depth % 2 == 0 ? "even" : "odd")));
// %>
// <div id="<%= id %>" class="<%= commentCss %>">
// <div class="comment-head">
// <a href="javascript:void(0)" class="author">[]</a>
// <a href="https://www.reddit.com/user/<%= comment.author %>" class="author comment-author">
// <%= comment.author+(isDeleted ? " (deleted by user)" : "") %>
// </a>
// <span class="comment-score"><%= Format.prettyScore(comment.score) %> point<%= ((comment.score == 1) ? "": "s") %></span>
// <span class="comment-time"><%= Format.prettyDate(comment.created_utc) %></span>
// </div>
// <div class="comment-body">
// <%= (comment.body === "[removed]" && isRemoved ? "<p>[likely removed by automoderator]</p>" : Format.parse(comment.body)) %>
// </div>
// <div class="comment-links">
// <a href="/r/<%= Reddit.subreddit %>/comments/<%= Reddit.threadID %>/_/<%= id %>/">permalink</a>
// <a href="https://www.reddit.com/r/<%= Reddit.subreddit %>/comments/<%= Reddit.threadID %>/_/<%= id %>/">reddit</a>
// </div>
// </div>

View file

@ -0,0 +1,14 @@
// {/* <div id="pagination">
// Page:
// <% if(start > 1) { %>
// <a href="<%= urlBase+1 %>">1</a> ...
// <% }
// for(var i = start; i <= end; i++) {
// if(currentPage === i) { %>
// <span><%= i %></span>
// <% } else { %>
// <a href="<%= urlBase+i %>"><%= i %></a>
// <% }
// } %>
// </div> */}

View file

@ -0,0 +1,13 @@
// {/* <div class="subreddit-info">
// top post of <a href="https://www.reddit.com/r/<%= subreddit %>">/r/<%= subreddit %></a> from:
// <select onchange="Vars.reload(this)">
// <option value="hour"<% if(time === "hour"){ %> selected<% } %>>past hour</option>
// <option value="12hour"<% if(time === "12hour"){ %> selected<% } %>>past 12 hours</option>
// <option value="day"<% if(time === "day"){ %> selected<% } %>>past day</option>
// <option value="week"<% if(time === "week"){ %> selected<% } %>>past week</option>
// <option value="month"<% if(time === "month"){ %> selected<% } %>>past month</option>
// <option value="6month"<% if(time === "6month"){ %> selected<% } %>>past 6 months</option>
// <option value="year"<% if(time === "year"){ %> selected<% } %>>past year</option>
// <option value="all"<% if(time === "all"){ %> selected<% } %>>all time</option>
// </select>
// </div> */}

View file

@ -1,12 +1,12 @@
import React from 'react'
import {prettyScore, prettyDate, redditThumbnails} from 'utils'
import {prettyScore, prettyDate, parse, redditThumbnails} from 'utils'
export default (props) => {
if(!props.title) {
return <div></div>
}
const url = props.url.replace('reddit.com', 'removeddit.com')
const url = props.url.replace('https://www.reddit.com', '')
const userLink = props.author !== '[deleted]' ? `https://www.reddit.com/user/${props.author}` : ''
let thumbnail
@ -34,7 +34,7 @@ export default (props) => {
</div>
{thumbnail}
<div className='thread-content'>
<a className='thread-title' href={props.url}>{props.title}</a>
<a className='thread-title' href={url}>{props.title}</a>
{props.link_flair_text &&
<span className='link-flair'>{props.link_flair_text}</span>}
<span className='domain'>({props.domain})</span>
@ -43,13 +43,15 @@ export default (props) => {
<a className='thread-author author' href={userLink}>{props.author}</a>
&nbsp;to <a className='subreddit-link author' href={`/r/${props.subreddit}`}>/r/{props.subreddit}</a>
</div>
{props.selftext &&
<div className='thread-selftext user-text' dangerouslySetInnerHTML={{__html: parse(props.selftext)}}></div>}
<div className='total-comments'>
<a className='grey-link' href={props.permalink}>
<b>{props.num_comments} comments</b>
</a>
</a>&nbsp;
<a className='grey-link' href={`https://www.reddit.com${props.permalink}`}>
<b>reddit</b>
</a>
</a>&nbsp;
<a className='grey-link' href={`https://snew.github.io${props.permalink}`}>
<b>ceddit</b>
</a>

View file

@ -0,0 +1,9 @@
import React from 'react'
export default (props) => {
{/* <div id="comment-info">
removed comments: <%= removedComments %>/<%= totalComments %> (<%= (100 * removedComments / totalComments).toFixed(1) %>%)
</div>
<div id="comment-sort">sorted by: top</div> */}
}

78
src/js/pages/Search.js Normal file
View file

@ -0,0 +1,78 @@
// var radioInput = function(name, displayNames, values) {
// var inputs = "";
// for(var i = 0, len = displayNames.length; i < len; i++){
// inputs += '<span class="radioButton"'+ (Vars.lookup[name] === values[i] ? ' style="background: #239f2b; color:#fff"':'')+'>';
// inputs += '<input type="radio" id="'+name+i+'" name="'+name+'" onchange="CSS.radio(this)"';
// inputs += 'value="'+values[i]+'" '+(Vars.lookup[name] === values[i] ? ' checked "':'')+' >';
// inputs += '<label for="'+name+i+'">'+displayNames[i]+'</label></span>';
// }
// return inputs;
// };
// var textInput = function(name){
// return '<input type="text" name="'+name+'" id="'+name+'" value="'+Vars.get(name)+'">';
// };
// var label = function(name, display) {
// return '<label for="'+name+'">'+display+': </label>';
// };
// var inputRow = function(text, input) {
// return '<div class="search-row"><span class="search-left">'+text+'</span><span>'+input+"</span></div>";
// };
// var selectTime = function() {
// var values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"];
// var display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"];
// var html = '<select name="time" id="time">';
// for(var i = 0, len = values.length; i < len; i++) {
// html += '<option value="'+values[i]+'"' + ((Vars.get("time") === values[i]) ? " selected" : '')+'>'+display[i]+'</option>';
// }
// return html + "</select>";
// };
// var select = function(name, display, values){
// var html = '<select name="'+name+'" id="'+name+'">';
// for(var i = 0, len = values.length; i < len; i++) {
// html += '<option value="'+values[i]+'"' + ((Vars.get(name) === values[i]) ? " selected" : '')+'>'+display[i]+'</option>';
// }
// return html + "</select>";
// };
// return {
// createSearch: function(){
// var searchBox = document.createElement("div");
// searchBox.id = "main-box";
// searchBox.className = "search-box";
// /*
// Comments:
// text (body) string
// title (title) string
// subreddit (subreddit) string
// author (author) string
// over_18 (over_18) sfw,nsfw,both *
// locked (locked) bool *
// between (after/before) "date"
// sort (sort) asc,desc
// */
// var html = inputRow('Im looking for: ', radioInput("thread", ["Thread","Comment"], ["true", "false"]));
// html += inputRow(label("text", "Text"), textInput("text"));
// html += inputRow(label("title","Title"), textInput("title"));
// html += inputRow(label("subreddit", "Subreddit"), textInput("subreddit"));
// html += inputRow(label("author", "Author"), textInput("author"));
// html += inputRow("Over 18: ", radioInput("over_18", ["Both","NSFW","SFW"], ["both","nsfw","sfw"]));
// html += inputRow("Locked: ", radioInput("locked", ["Both","True", "False"], ["both","true","false"]));
// html += inputRow("Removed: ", select("removed", ["Removed and non-removed", "Only removed", "Only deleted"], ["all", "removed", "deleted"]));
// html += inputRow("From:", selectTime());
// html += inputRow("Sort: ", select("sort", ["Highest score","Lowest score","Newest","Oldest"], ["score_desc","score_asc","time_desc","time_asc"]));
// html += '<input type="button" value="'+(showAdvanced?'Hide':'Show')+' advanced">';
// html += '<input type="submit" value="Search">';
// searchBox.innerHTML = html;
// mainDiv.appendChild(searchBox);