Skip to content

Commit

Permalink
Allow temp region selection from result view
Browse files Browse the repository at this point in the history
This adds a new "temporary" config section of the results view, where a
user can now change the country that their results come from without
changing their default config settings.

Closes #322
  • Loading branch information
benbusby committed Aug 1, 2022
1 parent 8e867a5 commit 3f363b0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ def search():
search_header=render_template(
'header.html',
config=g.user_config,
translation=translation,
languages=app.config['LANGUAGES'],
countries=app.config['COUNTRIES'],
logo=render_template('logo.html', dark=g.user_config.dark),
query=urlparse.unquote(query),
search_type=search_util.search_type,
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ select {
color: var(--whoogle-dark-contrast-text) !important;
}

.content {
.content, .result-config {
background-color: var(--whoogle-dark-element-bg) !important;
color: var(--whoogle-contrast-text) !important;
}
Expand Down
7 changes: 6 additions & 1 deletion app/static/css/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ header {
border-radius: 2px 0 0 0;
}

.result-config {
margin: 10px 0 10px 0;
padding: 10px;
border-radius: 8px;
}

.mobile-logo {
font: 22px/36px Futura, Arial, sans-serif;
padding-left: 5px;
Expand Down Expand Up @@ -121,7 +127,6 @@ a {
.header-tab-div {
border-radius: 0 0 8px 8px;
box-shadow: 0 2px 3px rgba(32, 33, 36, 0.18);
margin-bottom: 20px;
overflow: hidden;
}

Expand Down
2 changes: 1 addition & 1 deletion app/static/css/light-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ input {
color: var(--whoogle-contrast-text) !important;
}

.content {
.content, .result-config {
background-color: var(--whoogle-element-bg) !important;
color: var(--whoogle-contrast-text) !important;
}
Expand Down
11 changes: 11 additions & 0 deletions app/static/js/header.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
document.addEventListener("DOMContentLoaded", () => {
const searchBar = document.getElementById("search-bar");
const countrySelect = document.getElementById("result-country");
const arrowKeys = [37, 38, 39, 40];
let searchValue = searchBar.value;

countrySelect.onchange = () => {
let str = window.location.href;
n = str.lastIndexOf("search");
if (n > 0) {
str = str.substring(0, n) +
`search?q=${searchBar.value}&country=${countrySelect.value}`;
window.location.href = str;
}
}

searchBar.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
document.getElementById("search-form").submit();
Expand Down
2 changes: 1 addition & 1 deletion app/static/settings/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"lang_en": {
"search": "Search",
"config": "Configuration",
"config-country": "Set Country",
"config-country": "Country",
"config-lang": "Interface Language",
"config-lang-search": "Search Language",
"config-near": "Near",
Expand Down
20 changes: 20 additions & 0 deletions app/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
dir="auto">
<input id="search-reset" type="reset" value="x">
<input name="tbm" value="{{ search_type }}" style="display: none">
<input name="country" value="{{ config.country }}" style="display: none;">
<input type="submit" style="display: none;">
<div class="sc"></div>
</div>
Expand Down Expand Up @@ -79,6 +80,7 @@
value="{{ clean_query(query) }}"
dir="auto">
<input name="tbm" value="{{ search_type }}" style="display: none">
<input name="country" value="{{ config.country }}" style="display: none;">
<input type="submit" style="display: none;">
<div class="sc"></div>
</div>
Expand All @@ -103,6 +105,24 @@
</div>
</div>
</div>

<div class="result-config">
<label for="config-country">{{ translation['config-country'] }}: </label>
<select name="country" id="result-country">
{% for country in countries %}
<option value="{{ country.value }}"
{% if (
config.country != '' and config.country in country.value
) or (
config.country == '' and country.value == '')
%}
selected
{% endif %}>
{{ country.name }}
</option>
{% endfor %}
</select>
</div>
<div class="" id="s">
</div>
{% endif %}
Expand Down

7 comments on commit 3f363b0

@scgf
Copy link

@scgf scgf commented on 3f363b0 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@b-wize
Copy link

@b-wize b-wize commented on 3f363b0 Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a variable to disable this? I recently got this after updating my docker image, but would much rather keep a minimalist result view.

@benbusby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ariojas not yet. I'll work on either adding a variable to hide it or have it appear collapsed in the result view by default.

@benbusby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ariojas taken care of in a6a97aa. There's now a separate toggle to open/close the "advanced search" menu.

@b-wize
Copy link

@b-wize b-wize commented on 3f363b0 Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benbusby Wow, thanks. That was a super quick turnaround. I've been meaning to ask, I run my whoogle instance via a docker container in unraid. I'm not sure how many inquiries you get regarding that OS, but I'd be happy to contribute what little knowledge I have of managing the docker instance in that UI (the GUI makes managing the docker easier, but unconventional via the usual instructions).

@scgf
Copy link

@scgf scgf commented on 3f363b0 Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this toggle? On the latest version there is no way to select a temporary country. It looks exactly the same as before you implemented the change. The other issue where the option was available to temporarily change the country I would select 'UK' and nothing happened to the results - no refresh, no localised results, nothing. Have I missed a step in the process?

@benbusby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug with the previous implementation where nothing would happen when selecting the country (which has been fixed).

The toggle is in the tab bar on the results page, it should be a unicode gear icon.


TOGGLE CLOSED

toggle-closed


TOGGLE OPEN

toggle-open


COUNTRY SELECTED

country-selected

Please sign in to comment.