File size: 5,575 Bytes
727a40a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{% extends 'base.html' %}

{% block title %}
  Search | Devnoms
{% endblock %}

{% block style %}
  <style>
    * {
      margin: 0%;
      padding: 0%;
      box-sizing: border-box;
      font-family: 'Inter', sans-serif;
    }
    
    :root {
      font-size: 62.5%;
    }
    
    ::-webkit-scrollbar {
      width: 6px;
      height: 6px;
    }
    
    ::-webkit-scrollbar-thumb {
      background-color: white;
    }
    
    ::-webkit-scrollbar-thumb {
      background-color: #374045;
    }
    
    ::-webkit-scrollbar-track {
      background-color: transparent;
    }
    
    body {
      background-color: #131518;
      font-family: sans-serif;
      color: aliceblue;
    }
    
    .container {
      max-width: 500px;
      margin: auto;
      position: relative;
      top: 30px;
      height: 90vh;
      background-color: #282a2d;
      border: 2px solid rgb(255, 132, 0);
      text-align: center;
      border-radius: 8px;
      box-shadow: 4px 4px 10px -4px #9339f5;
      overflow-y: hidden;
    }
    
    @media screen and (max-width: 550px) {
      .container {
        top: 0px;
        max-width: 550px;
        height: 100vh;
      }
    }
    
    a {
      display: inline-block;
      width: 100%;
      text-decoration: none;
      color: aliceblue;
      cursor: pointer;
    }
    
    .row1 {
      display: flex;
      justify-content: space-around;
    }
    
    .top_row div {
      width: 100%;
    }
    
    .top_row {
      font-size: 1.8rem;
      padding: 1em 0em;
    }
    .user {
      font-size: 1.7rem;
      padding: 1em 0px;
      border-bottom: 1px solid rgb(146, 146, 146);
    }
    
    .friend_list {
      height: 100%;
      overflow-y: scroll;
    }
    .smessage {
      padding: 0.8em 0px;
      border-bottom: 1px solid grey;
      margin: 0px auto;
      font-size: 1.8rem;
      color: #39f542;
    }
    
    .smessage:hover {
      transition-duration: 0.2s;
      color: #7df587;
    }
    .emessage {
      margin-top: 10rem;
      color: #f53939;
      font-size: 1.8rem;
    }
    
    .emessage:hover {
      transition-duration: 0.2s;
      color: #f57d7d;
    }
    form {
      border-bottom: 1px solid rgb(146, 146, 146);
    }
    input {
      margin-right: 2rem;
      padding: 12px 0px;
      text-align: center;
      color: #fff;
      font-size: 2rem;
      background: #131518;
      border-radius: 8px;
      outline: none;
      border: none;
    }
    ::placeholder {
      color: #7a7a7a;
      opacity: 1;
    }
    .sbtn {
      padding: 1.3rem 2rem;
      color: #fff;
      background: #9339f5;
      border: none;
      border-radius: 5px;
      outline: none;
      cursor: pointer;
      font-size: 1.6rem;
    }
    .sbtn:hover {
      transition-duration: 0.2s;
      background: #6421eb;
    }
    @media screen and (max-width: 550px) {
      input {
        margin-right: 0rem;
        width: 69%;
      }
      .sbtn {
        width: 29%;
      }
    }
  </style>
{% endblock %}

{% block content %}
  <div class="container">
    <br />
    <div class="row1 top_row">
      <div class="col1">
        <a href="{% url 'home' %}" onclick="overlayLoader(event)">{{ user }}</a>
      </div>
    </div>
    <br />
    <div>
      <form class="form" method="get" action="{% url 'search' %}" onsubmit="return validateUsername()">
        <input type="text" name="q" placeholder="Search for users" value="{{ query }}" autocapitalize="none" id="username" required />
        <button class="sbtn" type="submit" id="search-button">
          <span id="btn-text">Search</span>
          <span id="loader" class="hidden"></span>
        </button>
      </form>
    </div>

    {% if query %}
      {% comment %} <p class="smessage user">Search Results for "{{ query }}"</p> {% endcomment %}

      <div class="friend_list">
        {% if users %}
          {% for fuser in users %}
            <div class="row1 user">
              <a href="{% url 'username' username=fuser.username %}" onclick="overlayLoader(event)">{{ fuser.username }}</a>
            </div>
          {% endfor %}
        {% else %}
          <p class="emessage">{{ not_found_message }}</p>
        {% endif %}
      </div>
    {% endif %}
    <div class="friend_list"></div>
  </div>
  <script>
    function validateUsername() {
      var usernameInput = document.getElementById('username')
      console.log(usernameInput)
      var usernameValue = usernameInput.value
    
      // Check if the username contains spaces
      if (/\s/.test(usernameValue)) {
        alert('Username cannot contain spaces.')
        usernameInput.value = usernameValue.replace(/\s/g, '')
        return false
      }
      const searchButton = document.getElementById('search-button')
      const btnText = document.getElementById('btn-text')
      const loader = document.getElementById('loader')
    
      // Disable button and show loader
      searchButton.disabled = true
      btnText.style.display = 'none'
      loader.classList.remove('hidden')
      loader.innerHTML = '<div class="spinner"></div>' // Add spinner content
      return true // Allow form submission if there are no spaces
    }
    window.addEventListener('pageshow', () => {
      const searchButton = document.getElementById('search-button')
      const btnText = document.getElementById('btn-text')
      const loader = document.getElementById('loader')
    
      // Reset the button and loader states
      searchButton.disabled = false
      btnText.style.display = 'inline'
      loader.classList.add('hidden')
    })
  </script>
{% endblock %}