Laptop commited on
Commit
56bfcbb
·
unverified ·
1 Parent(s): d52da3a

less javascript (#621)

Browse files
Cargo.lock CHANGED
@@ -3273,6 +3273,7 @@ dependencies = [
3273
  "sync_wrapper",
3274
  "tokio 1.40.0",
3275
  "tokio-rustls",
 
3276
  "tokio-util",
3277
  "tower-service",
3278
  "url 2.5.2",
@@ -4103,6 +4104,18 @@ dependencies = [
4103
  "tokio 1.40.0",
4104
  ]
4105
 
 
 
 
 
 
 
 
 
 
 
 
 
4106
  [[package]]
4107
  name = "tokio-sync"
4108
  version = "0.1.8"
 
3273
  "sync_wrapper",
3274
  "tokio 1.40.0",
3275
  "tokio-rustls",
3276
+ "tokio-socks",
3277
  "tokio-util",
3278
  "tower-service",
3279
  "url 2.5.2",
 
4104
  "tokio 1.40.0",
4105
  ]
4106
 
4107
+ [[package]]
4108
+ name = "tokio-socks"
4109
+ version = "0.5.2"
4110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
4111
+ checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f"
4112
+ dependencies = [
4113
+ "either",
4114
+ "futures-util",
4115
+ "thiserror",
4116
+ "tokio 1.40.0",
4117
+ ]
4118
+
4119
  [[package]]
4120
  name = "tokio-sync"
4121
  version = "0.1.8"
public/static/index.js CHANGED
@@ -1,41 +1,6 @@
1
- /**
2
- * Selects the input element for the search box
3
- * @type {HTMLInputElement}
4
- */
5
- const searchBox = document.querySelector('input')
6
-
7
- /**
8
- * Redirects the user to the search results page with the query parameter
9
- */
10
- function searchWeb() {
11
- const query = searchBox.value.trim()
12
- try {
13
- let safeSearchLevel = document.querySelector('.search_options select').value
14
- if (query) {
15
- window.location.href = `search?q=${encodeURIComponent(
16
- query,
17
- )}&safesearch=${encodeURIComponent(safeSearchLevel)}`
18
- }
19
- } catch (error) {
20
- if (query) {
21
- window.location.href = `search?q=${encodeURIComponent(query)}`
22
- }
23
- }
24
- }
25
-
26
- /**
27
- * Listens for the 'Enter' key press event on the search box and calls the searchWeb function
28
- * @param {KeyboardEvent} e - The keyboard event object
29
- */
30
- searchBox.addEventListener('keyup', (e) => {
31
- if (e.key === 'Enter') {
32
- searchWeb()
33
- }
34
- })
35
-
36
  /**
37
  * A function that clears the search input text when the clear button is clicked.
38
  */
39
  function clearSearchText() {
40
- document.querySelector('.search_bar input').value = ''
41
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /**
2
  * A function that clears the search input text when the clear button is clicked.
3
  */
4
  function clearSearchText() {
5
+ document.querySelector('.search_bar > input').value = ''
6
  }
public/static/pagination.js DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * Navigates to the next page by incrementing the current page number in the URL query string.
3
- * @returns {void}
4
- */
5
- function navigate_forward() {
6
- let url = new URL(window.location);
7
- let searchParams = url.searchParams;
8
-
9
- let q = searchParams.get('q');
10
- let page = parseInt(searchParams.get('page'));
11
-
12
- if (isNaN(page)) {
13
- page = 1;
14
- } else {
15
- page++;
16
- }
17
-
18
- window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
19
- }
20
-
21
- /**
22
- * Navigates to the previous page by decrementing the current page number in the URL query string.
23
- * @returns {void}
24
- */
25
- function navigate_backward() {
26
- let url = new URL(window.location);
27
- let searchParams = url.searchParams;
28
-
29
- let q = searchParams.get('q');
30
- let page = parseInt(searchParams.get('page'));
31
-
32
- if (isNaN(page)) {
33
- page = 0;
34
- } else if (page > 0) {
35
- page--;
36
- }
37
-
38
- window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public/static/search_area_options.js DELETED
@@ -1,18 +0,0 @@
1
- document.addEventListener(
2
- 'DOMContentLoaded',
3
- () => {
4
- let url = new URL(window.location)
5
- let searchParams = url.searchParams
6
-
7
- let safeSearchLevel = searchParams.get('safesearch')
8
-
9
- if (
10
- safeSearchLevel >= 0 &&
11
- safeSearchLevel <= 2 &&
12
- safeSearchLevel !== null
13
- ) {
14
- document.querySelector('.search_options select').value = safeSearchLevel
15
- }
16
- },
17
- false,
18
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public/static/themes/simple.css CHANGED
@@ -448,7 +448,7 @@ footer div {
448
  align-items: center;
449
  }
450
 
451
- .page_navigation button {
452
  background: var(--background-color);
453
  color: var(--foreground-color);
454
  padding: 1rem;
@@ -457,7 +457,7 @@ footer div {
457
  border: none;
458
  }
459
 
460
- .page_navigation button:active {
461
  filter: brightness(1.2);
462
  }
463
 
 
448
  align-items: center;
449
  }
450
 
451
+ .page_navigation a {
452
  background: var(--background-color);
453
  color: var(--foreground-color);
454
  padding: 1rem;
 
457
  border: none;
458
  }
459
 
460
+ .page_navigation a:active {
461
  filter: brightness(1.2);
462
  }
463
 
src/server/routes/search.rs CHANGED
@@ -129,6 +129,7 @@ pub async fn search(
129
  &config.style.theme,
130
  &config.style.animation,
131
  query,
 
132
  &results.0,
133
  )
134
  .0,
 
129
  &config.style.theme,
130
  &config.style.animation,
131
  query,
132
+ page,
133
  &results.0,
134
  )
135
  .0,
src/templates/partials/bar.rs CHANGED
@@ -14,12 +14,13 @@ use maud::{html, Markup, PreEscaped};
14
  /// It returns the compiled html code for the search bar as a result.
15
  pub fn bar(query: &str) -> Markup {
16
  html!(
 
17
  (PreEscaped("<div class=\"search_bar\">"))
18
- input type="search" name="search-box" value=(query) placeholder="Type to search";
19
- button type="reset" onclick="clearSearchText()" {
20
  img src="./images/close.svg" alt="Clear button icon for clearing search input text";
21
  }
22
- button type="submit" onclick="searchWeb()" {
23
  img src="./images/magnifying_glass.svg" alt="Info icon for error box";
24
  }
25
  )
 
14
  /// It returns the compiled html code for the search bar as a result.
15
  pub fn bar(query: &str) -> Markup {
16
  html!(
17
+ (PreEscaped("<form action=\"/search\">"))
18
  (PreEscaped("<div class=\"search_bar\">"))
19
+ input type="search" name="q" value=(query) placeholder="Type to search";
20
+ button type="button" onclick="clearSearchText()" {
21
  img src="./images/close.svg" alt="Clear button icon for clearing search input text";
22
  }
23
+ button type="submit" {
24
  img src="./images/magnifying_glass.svg" alt="Info icon for error box";
25
  }
26
  )
src/templates/partials/search_bar.rs CHANGED
@@ -29,7 +29,7 @@ pub fn search_bar(
29
  (bar(query))
30
  .error_box {
31
  @if !engine_errors_info.is_empty(){
32
- button onclick="toggleErrorBox()" class="error_box_toggle_button"{
33
  img src="./images/warning.svg" alt="Info icon for error box";
34
  }
35
  .dropdown_error_box{
@@ -43,7 +43,7 @@ pub fn search_bar(
43
  }
44
  }
45
  @else {
46
- button onclick="toggleErrorBox()" class="error_box_toggle_button"{
47
  img src="./images/info.svg" alt="Warning icon for error box";
48
  }
49
  .dropdown_error_box {
@@ -56,10 +56,10 @@ pub fn search_bar(
56
  (PreEscaped("</div>"))
57
  .search_options {
58
  @if safe_search_level >= 3 {
59
- (PreEscaped("<select name=\"safe_search_levels\" disabled>"))
60
  }
61
  @else{
62
- (PreEscaped("<select name=\"safe_search_levels\">"))
63
  }
64
  @for (idx, name) in SAFE_SEARCH_LEVELS_NAME.iter().enumerate() {
65
  @if (safe_search_level as usize) == idx {
@@ -71,6 +71,7 @@ pub fn search_bar(
71
  }
72
  (PreEscaped("</select>"))
73
  }
 
74
  }
75
  )
76
  }
 
29
  (bar(query))
30
  .error_box {
31
  @if !engine_errors_info.is_empty(){
32
+ button type="button" onclick="toggleErrorBox()" class="error_box_toggle_button"{
33
  img src="./images/warning.svg" alt="Info icon for error box";
34
  }
35
  .dropdown_error_box{
 
43
  }
44
  }
45
  @else {
46
+ button type="button" onclick="toggleErrorBox()" class="error_box_toggle_button"{
47
  img src="./images/info.svg" alt="Warning icon for error box";
48
  }
49
  .dropdown_error_box {
 
56
  (PreEscaped("</div>"))
57
  .search_options {
58
  @if safe_search_level >= 3 {
59
+ (PreEscaped("<select name=\"safesearch\" disabled>"))
60
  }
61
  @else{
62
+ (PreEscaped(format!("<select name=\"safesearch\" value=\"{}\">", safe_search_level)))
63
  }
64
  @for (idx, name) in SAFE_SEARCH_LEVELS_NAME.iter().enumerate() {
65
  @if (safe_search_level as usize) == idx {
 
71
  }
72
  (PreEscaped("</select>"))
73
  }
74
+ (PreEscaped("</form>"))
75
  }
76
  )
77
  }
src/templates/views/search.rs CHANGED
@@ -24,6 +24,7 @@ pub fn search(
24
  theme: &str,
25
  animation: &Option<String>,
26
  query: &str,
 
27
  search_results: &SearchResults,
28
  ) -> Markup {
29
  html!(
@@ -108,15 +109,14 @@ pub fn search(
108
  }
109
  }
110
  .page_navigation {
111
- button type="button" onclick="navigate_backward()"{
112
  (PreEscaped("&#8592;")) "previous"
113
  }
114
- button type="button" onclick="navigate_forward()"{"next" (PreEscaped("&#8594;"))}
 
115
  }
116
  }
117
  script src="static/index.js"{}
118
- script src="static/search_area_options.js"{}
119
- script src="static/pagination.js"{}
120
  script src="static/error_box.js"{}
121
  (footer())
122
  )
 
24
  theme: &str,
25
  animation: &Option<String>,
26
  query: &str,
27
+ page: u32,
28
  search_results: &SearchResults,
29
  ) -> Markup {
30
  html!(
 
109
  }
110
  }
111
  .page_navigation {
112
+ a href=(format!("/search?q={}&safesearch={}&page={}", query, search_results.safe_search_level, if page > 1 {page-1} else {1})) {
113
  (PreEscaped("&#8592;")) "previous"
114
  }
115
+ a href=(format!("/search?q={}&safesearch={}&page={}", query, search_results.safe_search_level, page+2)) {
116
+ "next" (PreEscaped("&#8594;"))}
117
  }
118
  }
119
  script src="static/index.js"{}
 
 
120
  script src="static/error_box.js"{}
121
  (footer())
122
  )