gotta try this on live.

This commit is contained in:
Jason Schwarzenberger 2020-12-02 13:22:47 +13:00
parent 32f1455bbb
commit 59c6f17e67
6 changed files with 17 additions and 13 deletions

View File

@ -67,9 +67,9 @@ def put_story(story):
logging.error('Problem putting MeiliSearch story: {}'.format(str(e)))
return False
def search(q):
def search(q, skip=0, limit=250):
try:
params = dict(q=q, limit=250)
params = dict(q=q, skip=skip, limit=limit)
r = requests.get(MEILI_URL + 'indexes/qotnews/search', params=params, timeout=2)
if r.status_code != 200:
raise Exception('Bad response code ' + str(r.status_code))

View File

@ -51,8 +51,10 @@ def api():
@flask_app.route('/api/search', strict_slashes=False)
def apisearch():
q = request.args.get('q', '')
skip = request.args.get('skip', 0)
limit = request.args.get('limit', 20)
if len(q) >= 3:
results = search.search(q)
results = search.search(q, skip=skip, limit=limit)
else:
results = []
return dict(results=results)

View File

@ -54,10 +54,6 @@
overflow: hidden;
color: #888;
}
.comment-text.is-collapsed::after {
content: "...";
font-style: italic;
}
.comment-children {
margin-left: 0.5rem;
padding-left: 0.5rem;
@ -85,14 +81,15 @@
<header class="comment-info">
<span
class={comment.author === story.author ? 'comment-author is-op' : 'comment-author'}>{comment.author || '[Deleted]'}</span>
&bull;
<a class="time-link" href="{story.id}#comment-{id}">
<Time date={comment.date} />
</a>
{#if comment.comments.length}
<button
class="toggle-children"
on:click={toggleComments}>[{showComments ? '-' : '+'}]</button>
on:click={toggleComments}>{#if showComments}
[&ndash;]
{:else}[+]{/if}</button>
{/if}
</header>

View File

@ -11,7 +11,7 @@
on
<a class="source" href={story.link || story.url}>{story.source}</a>
{#if story.score}&bull; {story.score} points{/if}
{#if story.num_comments}
{#if Number(story.num_comments)}
&bull;
<a rel="prefetch" href="/{story.id}#comments">{story.num_comments}
comments</a>

View File

@ -18,8 +18,10 @@
export let story;
export let related;
let others = related.filter((r) => r.id !== story.id && r.num_comments);
let hasComments = related.some((r) => r.num_comments);
let others = related.filter(
(r) => r.id !== story.id && Number(r.num_comments)
);
let hasComments = related.some((r) => Number(r.num_comments));
</script>
<style>

View File

@ -24,7 +24,10 @@ class Results extends React.Component {
const signal = this.controller.signal;
const search = this.props.location.search;
fetch('/api/search' + search, { method: 'get', signal: signal })
const params = new URLSearchParams(search);
params.set('skip', params.get('skip') || 0);
params.set('limit', params.get('limit') || 20);
fetch('/api/search?' + params.toString(), { method: 'get', signal: signal })
.then(res => res.json())
.then(
(result) => {