Try using select rather than search for better mobile/browser compatibility

merge-requests/30/head
Bob Mottram 2023-01-01 10:25:28 +00:00
parent 0c2113c43a
commit 45fa7aa236
2 changed files with 52 additions and 6 deletions

View File

@ -63,7 +63,7 @@ from filters import is_filtered
from follow import is_follower_of_person
from follow import get_follower_domains
from webapp_frontscreen import html_front_screen
from webapp_utils import html_following_data_list
from webapp_utils import html_following_dropdown
from webapp_utils import edit_number_field
from webapp_utils import html_keyboard_navigation
from webapp_utils import html_hide_from_screen_reader
@ -1110,11 +1110,8 @@ def html_profile(signing_priv_key_pem: str,
' <input type="hidden" ' + \
'name="actor" value="' + actor + '">\n'
follow_search_str += \
' <input type="search" name="searchtext" ' + \
'list="' + selected + 'Handles" placeholder="🔎">\n'
follow_search_str += \
html_following_data_list(base_dir, nickname, domain,
domain_full, selected, False)
html_following_dropdown(base_dir, nickname, domain,
domain_full, selected, False)
follow_search_str += \
' <button type="submit" class="button" ' + \
'name="submitSearch">' + translate['Search'] + '</button>\n'

View File

@ -2016,3 +2016,52 @@ def html_following_data_list(base_dir: str, nickname: str,
list_str += '<option>@' + following_address + '</option>\n'
list_str += '</datalist>\n'
return list_str
def html_following_dropdown(base_dir: str, nickname: str,
domain: str, domain_full: str,
following_type: str,
use_petnames: bool) -> str:
"""Returns a select list of handles being followed or of followers
"""
list_str = '<select name="searchtext">\n'
following_filename = \
acct_dir(base_dir, nickname, domain) + '/' + following_type + '.txt'
msg = None
if os.path.isfile(following_filename):
with open(following_filename, 'r',
encoding='utf-8') as following_file:
msg = following_file.read()
# add your own handle, so that you can send DMs
# to yourself as reminders
msg += nickname + '@' + domain_full + '\n'
if msg:
# include petnames
petnames_filename = \
acct_dir(base_dir, nickname, domain) + '/petnames.txt'
if use_petnames and os.path.isfile(petnames_filename):
following_list = []
with open(petnames_filename, 'r',
encoding='utf-8') as petnames_file:
pet_str = petnames_file.read()
# extract each petname and append it
petnames_list = pet_str.split('\n')
for pet in petnames_list:
following_list.append(pet.split(' ')[0])
# add the following.txt entries
following_list += msg.split('\n')
else:
# no petnames list exists - just use following.txt
following_list = msg.split('\n')
following_list.sort()
if following_list:
for following_address in following_list:
if not following_address:
continue
if '@' not in following_address and \
'://' not in following_address:
continue
list_str += '<option value="' + following_address + '">' + \
following_address + '</option>\n'
list_str += '</select>\n'
return list_str