Adds async update from flask with other content

This commit is contained in:
kvan7 2024-01-22 03:23:35 +00:00
parent b50ef14dce
commit f797519944
9 changed files with 49 additions and 61 deletions

View file

@ -11,6 +11,5 @@ def post_search(request, search: SearchWithPlugins) -> None:
search_request = search.search_query
container = search.result_container
# container.infoboxes.append(container.infoboxes[0])
container.chat_box = {'chat_box': 'hello world'}
print(container.infoboxes)
print("HELLO WORLD =====================================================================")
container.chat_box = [{'chat_box': 'hello world'}]
container.chat_box[0]['content'] = 'some string that relates to your search query here' + f'\n{search_request.query}'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -548,7 +548,8 @@ article[data-vim-selected].category-social {
}
#suggestions,
#infoboxes {
#infoboxes,
#chat_box {
input {
padding: 0;
margin: 3px;
@ -564,7 +565,8 @@ article[data-vim-selected].category-social {
}
input[type="submit"],
.infobox .url a {
.infobox .url a,
.chat_box .url a {
color: var(--color-result-link-font);
text-decoration: none;
font-size: 0.9rem;
@ -595,6 +597,7 @@ article[data-vim-selected].category-social {
}
#infoboxes .title,
#chat_box .title,
#suggestions .title,
#search_url .title,
#engines_msg .title,
@ -648,7 +651,8 @@ summary.title {
}
}
#infoboxes {
#infoboxes,
#chat_box {
form {
min-width: 210px;
}
@ -659,7 +663,8 @@ summary.title {
word-wrap: break-word;
color: var(--color-sidebar-font);
.infobox {
.infobox,
.chat_box {
margin: 10px 0 10px;
border: 1px solid var(--color-sidebar-border);
padding: 1rem;
@ -843,11 +848,13 @@ summary.title {
width: auto;
}
#infoboxes {
#infoboxes,
#chat_box {
position: inherit;
max-width: inherit;
.infobox {
.infobox,
.chat_box {
clear: both;
img {
@ -1056,7 +1063,8 @@ summary.title {
background: var(--color-base-background-mobile);
}
.infobox {
.infobox,
.chat_box {
border: none !important;
background-color: var(--color-sidebar-background);
}

View file

@ -1,48 +1,23 @@
<aside class="chat_box" aria-label="{{ chat_box.chat_box }}">
<h2 class="title"><bdi>{{ chat_box.chat_box }}</bdi></h2>
<!-- {%- if infobox.img_src -%}<img src="{{ image_proxify(infobox.img_src) }}" title="{{ infobox.infobox|striptags }}" alt="{{ infobox.infobox|striptags }}">{%- endif -%} -->
<!-- <p><bdi>{{ infobox.content | safe }}</bdi></p> -->
<!-- {%- if infobox.attributes -%}
<div class="attributes">
{%- for attribute in infobox.attributes -%}
<dl>
<dt><bdi>{{ attribute.label }} :</bdi></dt>
{%- if attribute.image -%}
<dd><img src="{{ image_proxify(attribute.image.src) }}" alt="{{ attribute.image.alt }}"></dd>
{%- else -%}
<dd><bdi>{{ attribute.value }}</bdi></dd>
{%- endif -%}
</dl>
{%- endfor -%}
</div>
{%- endif -%} -->
<!-- {%- if infobox.urls -%}
<div class="urls">
<ul>
{%- for url in infobox.urls -%}
<li class="url"><bdi><a href="{{ url.url }}" {%- if results_on_new_tab -%}target="_blank" rel="noopener noreferrer"{%- else -%}rel="noreferrer"{%- endif -%}>{{ url.title }}</a></bdi></li>
{%- endfor -%}
</ul>
</div>
{%- endif -%} -->
<!-- {%- if infobox.relatedTopics -%}
<div class="relatedTopics">
{%- for topic in infobox.relatedTopics -%}
<div>
<h3><bdi>{{ topic.name }}</bdi></h3>
{%- for suggestion in topic.suggestions -%}
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
<input type="hidden" name="q" value="{{ suggestion }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{%- if timeout_limit -%}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}" >{%- endif -%}
<input type="submit" value="{{ suggestion }}" />
</form>
{%- endfor -%}
</div>
{%- endfor -%}
</div>
{%- endif -%} -->
</aside>
<p><bdi>{{ chat_box.content | safe }}</bdi></p>
</aside>
<script>
document.addEventListener("DOMContentLoaded", function () {
function updateChatBox() {
fetch('/get-chat-content')
.then(response => response.json())
.then(data => {
const chatBox = document.querySelector('.chat_box');
console.log('response from api', data);
chatBox.querySelector('bdi').textContent = data.chat_box;
chatBox.querySelector('p').textContent = data.content;
})
.catch(error => console.error('Error:', error));
}
// Call updateChatBox after search is completed
// This might be tied to an event, depending on how your search functionality is implemented
updateChatBox();
});
</script>

View file

@ -47,7 +47,7 @@
<div id="chat_box">
<details open class="sidebar-collapsable">
<summary class="title">{{ _('Chat') }}</summary>
{%- for infobox in chat_box -%}
{%- for chat_box in chat_box -%}
{%- include 'kvanDark/elements/chat_box.html' -%}
{%- endfor -%}
</details>

View file

@ -1300,6 +1300,12 @@ def config():
}
)
@app.route('/get-chat-content')
def get_chat_content():
# Retrieve chat content from wherever it's stored
chat_content = {'chat_box': 'hello world', 'content': 'Response From Flask'}
return jsonify(chat_content)
@app.errorhandler(404)
def page_not_found(_e):