Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Add HedySelect custom element #5540

Merged
merged 49 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
212a35b
adding dropdown class
jpelay May 15, 2024
3b74de4
replace dropdowns in customize adventure with hedy dropdowns
jpelay May 16, 2024
4884c6f
refactor some functions
jpelay May 16, 2024
bfc5e4b
fix some errors
jpelay May 16, 2024
72afa72
adding templates to their own file
jpelay May 16, 2024
ec082f4
generic arrow movement
jpelay May 16, 2024
5486f35
move select to their own file
jpelay May 16, 2024
dcd957b
for some reason it doesnt work in the custom elements file
jpelay May 16, 2024
73bf4db
test select in public adventures
jpelay May 16, 2024
1950c53
adding default label
jpelay May 20, 2024
b92137d
Merge branch 'main' into generic-dropdown
jpelay May 20, 2024
077f51c
🤖 Automatically update generated files
jpelay May 20, 2024
84e53c5
change selects of public adventures
jpelay May 20, 2024
8079e66
Merge branch 'generic-dropdown' of https://github.com/hedyorg/hedy in…
jpelay May 20, 2024
04aaeff
🤖 Automatically update generated files
jpelay May 20, 2024
464d82e
export from custom elements file
jpelay May 21, 2024
ac437de
🤖 Automatically update generated files
jpelay May 21, 2024
c8f6f01
change name of element and remove inner select
jpelay May 21, 2024
12d1f8d
Merge branch 'generic-dropdown' of https://github.com/hedyorg/hedy in…
jpelay May 21, 2024
a8faabb
🤖 Automatically update generated files
jpelay May 21, 2024
1b2df46
fix tests
jpelay Jun 13, 2024
ef93027
🤖 Automatically update generated files
jpelay Jun 13, 2024
b6c48e7
Merge branch main into class overview redesign
jpelay Jun 13, 2024
bbfb166
Merge branch 'generic-dropdown' of https://github.com/hedyorg/hedy in…
jpelay Jun 13, 2024
19762ad
🤖 Automatically update generated files
jpelay Jun 13, 2024
4c69249
fix public adventures
jpelay Jun 19, 2024
c253a3b
Merge branch 'main' into generic-dropdown
jpelay Jun 19, 2024
503ef8b
fix tests
jpelay Jun 19, 2024
31a76a3
close dropdowns when clicking outside
jpelay Jul 17, 2024
95485f0
replace explore page filters
jpelay Jul 17, 2024
4e1071b
🤖 Automatically update generated files
jpelay Jul 17, 2024
1822e37
add translation for level error
jpelay Jul 17, 2024
2ad551b
Merge branch 'generic-dropdown' of https://github.com/hedyorg/hedy in…
jpelay Jul 17, 2024
f6822db
Merge branch 'main' into generic-dropdown
jpelay Jul 18, 2024
656bae3
fix merge
jpelay Jul 18, 2024
2335deb
🤖 Automatically update generated files
jpelay Jul 18, 2024
a772d24
style adventure page a bit better
jpelay Jul 18, 2024
9d9820c
Merge branch 'main' into generic-dropdown
jpelay Jul 18, 2024
a4cdaff
🤖 Automatically update generated files
jpelay Jul 18, 2024
570341f
fix cypress tests
jpelay Jul 19, 2024
4895c91
fix translations
jpelay Jul 19, 2024
c012d18
🤖 Automatically update generated files
jpelay Jul 19, 2024
8237308
Merge branch 'main' into generic-dropdown
jpelay Jul 30, 2024
8bf516c
🤖 Automatically update generated files
jpelay Jul 30, 2024
b7926f8
fixed translations files
jpelay Jul 30, 2024
318b8bc
🤖 Automatically update generated files
jpelay Jul 30, 2024
cfd858a
Update messages.po
jpelay Jul 30, 2024
e0fac2e
🤖 Automatically update generated files
jpelay Jul 30, 2024
404683b
Merge branch 'main' into generic-dropdown
mergify[bot] Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change selects of public adventures
  • Loading branch information
jpelay committed May 20, 2024
commit 84e53c588ded7858d949f0b5ae0a3769235e65df
33 changes: 13 additions & 20 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -93455,13 +93455,13 @@ def note_with_error(value, err):
var openSearchPanel = (view) => {
let state = view.state.field(searchState, false);
if (state && state.panel) {
let searchInput2 = getSearchInput(view);
if (searchInput2 && searchInput2 != view.root.activeElement) {
let searchInput = getSearchInput(view);
if (searchInput && searchInput != view.root.activeElement) {
let query = defaultQuery(view.state, state.query.spec);
if (query.valid)
view.dispatch({ effects: setSearchQuery.of(query) });
searchInput2.focus();
searchInput2.select();
searchInput.focus();
searchInput.select();
}
} else {
view.dispatch({ effects: [
Expand Down Expand Up @@ -104589,7 +104589,7 @@ def note_with_error(value, err):
throw new Error("HedySelect should only have one span element!");
}
span[0].dataset["value"] = label;
span[0].innerHTML = label;
span[0].textContent = label;
updateLabelText(this.querySelector(".dropdown"));
}
onOptionClick(_event) {
Expand Down Expand Up @@ -124739,24 +124739,18 @@ def note_with_error(value, err):
ZC({ Validation: Ch, Select: _r });

// static/js/public-adventures.ts
var levelSelect;
var languageSelect;
var tagsSelect;
var searchInput;
function initializeVariables() {
levelSelect = document.getElementById("level-select");
languageSelect = document.getElementById("language-select");
tagsSelect = document.getElementById("tag-select");
searchInput = document.getElementById("search_adventure");
}
function updateURL() {
const levelSelect = document.getElementById("level-select");
const languageSelect = document.getElementById("language-select");
const tagsSelect = document.getElementById("tag-select");
const searchInput = document.getElementById("search_adventure");
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const level3 = levelSelect.getAttribute("data-value") || "";
const lanugage = languageSelect.getAttribute("data-value") || "";
const tags2 = tagsSelect.getAttribute("data-value") || "";
const level3 = levelSelect.selected[0];
const language2 = languageSelect.selected[0];
const tags2 = tagsSelect.selected.join(",");
urlParams.set("level", level3);
urlParams.set("lang", lanugage);
urlParams.set("lang", language2);
urlParams.set("tag", tags2);
if (searchInput) {
urlParams.set("search", searchInput.value);
Expand All @@ -124765,7 +124759,6 @@ def note_with_error(value, err):
}
document.addEventListener("updateTSCode", (e) => {
setTimeout(() => {
initializeVariables();
const js = e.detail;
updateURL();
initialize({
Expand Down
6 changes: 3 additions & 3 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions static/js/custom-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class HedySelect extends HTMLElement {
const span = this.getElementsByTagName('span')
if (span.length !== 1) {
throw new Error('HedySelect should only have one span element!');
}
}
span[0].dataset['value'] = label;
span[0].innerHTML = label;
span[0].textContent = label;
updateLabelText(this.querySelector('.dropdown')!)
}

Expand Down
30 changes: 10 additions & 20 deletions static/js/public-adventures.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
import { HedySelect } from "./custom-elements";
import { initialize } from "./initialize";

let levelSelect: HTMLElement;
let languageSelect: HTMLElement;
let tagsSelect: HTMLElement;
let searchInput: HTMLInputElement;

function initializeVariables() {
// Get and initialize needed variables
levelSelect = document.getElementById("level-select") as HTMLElement;
languageSelect = document.getElementById("language-select") as HTMLElement;
tagsSelect = document.getElementById("tag-select") as HTMLElement;
searchInput = document.getElementById('search_adventure') as HTMLInputElement;
}

function updateURL() {
const levelSelect = document.getElementById("level-select") as HedySelect;
const languageSelect = document.getElementById("language-select") as HedySelect;
const tagsSelect = document.getElementById("tag-select") as HedySelect;
const searchInput = document.getElementById('search_adventure') as HTMLInputElement;

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const level = levelSelect.getAttribute("data-value") || "";
const lanugage = languageSelect.getAttribute("data-value") || "";
const tags = tagsSelect.getAttribute("data-value") || "";
const level = levelSelect.selected[0];
const language = languageSelect.selected[0];
const tags = tagsSelect.selected.join(',');

urlParams.set('level', level)
urlParams.set('lang', lanugage)
urlParams.set('lang', language)
urlParams.set('tag', tags)
if (searchInput) {
urlParams.set('search', searchInput.value)
}
window.history.pushState({}, '', `${window.location.pathname}?${urlParams.toString()}`);

}


document.addEventListener("updateTSCode", (e: any) => {
setTimeout(() => {
initializeVariables();
const js = e.detail;

updateURL();
initialize({
lang: js.lang, level: parseInt(js.level), keyword_language: js.lang,
Expand Down
120 changes: 29 additions & 91 deletions templates/public-adventures/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,7 @@
</div>
<div class="flex w-full sm:basis-1/2 gap-2">
<div id="levels" class="flex-1">
<div class="dropdown relative" data-type="single" id="level-select" data-value="{{selectedLevel}}">
<button class="toggle-button font-semibold rounded inline-flex justify-between
appearance-none w-full border border-gray-200 text-gray-700 p-2 rounded"
onclick="$('#level_dropdown').slideToggle('medium');">
<span class="label" data-value="{{_('select_levels')}}">{{selectedLevel or _('select_levels')}}</span>
<svg id="keyword-arrow_level" class="fill-current h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</button>
<div class="dropdown-menu dropdown-blue z-30 mt-2 w-full" id="level_dropdown"
style="display: none; width: 100%;"
_="on mutation of @style
set arrow to #keyword-arrow_level
if *display == 'none'
remove .rotate-180 from arrow
else if not arrow.classList.contains('rotate-180')
add .rotate-180 to arrow
end">
{% for level in customizations["available_levels"] %}
<div class="option {% if selectedLevel|string == level|string %}selected{% endif %}"
hx-post="/public-adventures/filter?level={{level}}&lang={{selectedLang}}&tag={{selectedTag}}&search={{currentSearch}}"
hx-target="#public-adventures"
data-value="{{level}}"
>{{ level }}</div>
{% endfor %}
</div>
</div>
</div>
<div id="levels_test" class="flex-1">
<hedy-select>
<hedy-select id="level-select" data-label="{{_('select_levels')}}">
<select>
{% for level in customizations["available_levels"] %}
<option {% if selectedLevel|string == level|string %}selected{% endif %}
Expand All @@ -61,70 +32,37 @@
</hedy-select>
</div>
<div id="languages" class="flex-1">
<div class="dropdown relative" data-type="single" id="language-select" data-value="{{selectedLang}}">
<button class="toggle-button font-semibold rounded inline-flex justify-between
appearance-none w-full border border-gray-200 text-gray-700 p-2 rounded"
onclick="$('#lang_dropdown').slideToggle('medium');">
<span class="label" data-value="{{_('select_lang')}}">{{lang_to_sym(selectedLang) if selectedLang else _('select_lang')}}</span>
<svg id="keyword-arrow_lang" class="fill-current h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</button>
<div class="dropdown-menu dropdown-blue z-30 mt-2 w-full" id="lang_dropdown"
style="display: none; width: 100%;"
_="on mutation of @style
set arrow to #keyword-arrow_lang
if *display == 'none'
remove .rotate-180 from arrow
else if not arrow.classList.contains('rotate-180')
add .rotate-180 to arrow
end">
<div class="option default"
hx-post="/public-adventures/filter?lang=reset&level={{selectedLevel}}&tag={{selectedTag}}&search={{currentSearch}}"
hx-target="#public-adventures"
value="">{{_('select_lang')}}</div>
{% for lang in available_languages %}
<div class="option {% if lang == selectedLang %}selected{% endif %}"
hx-post="/public-adventures/filter?lang={{lang}}&level={{selectedLevel}}&tag={{selectedTag}}&search={{currentSearch}}"
hx-target="#public-adventures"
data-value="{{lang}}">{{lang_to_sym(lang)}}</div>
{% endfor %}
</div>
</div>
<hedy-select id="language-select" data-label="{{ lang_to_sym(selectedLang) if selectedLang else _('select_lang') }}">
<select>
<option
hx-post="/public-adventures/filter?lang=reset&level={{selectedLevel}}&tag={{selectedTag}}&search={{currentSearch}}"
hx-target="#public-adventures"
value="">{{_('select_lang')}}</option>
{% for lang in available_languages %}
<option {% if lang == selectedLang %}selected{% endif %}
hx-post="/public-adventures/filter?lang={{lang}}&level={{selectedLevel}}&tag={{selectedTag}}&search={{currentSearch}}"
hx-target="#public-adventures"
data-value="{{lang}}">{{lang_to_sym(lang)}}</option>
{% endfor %}
</select>
</hedy-select>
</div>

<div id="tags" class="flex-1">
<div class="dropdown relative" id="tag-select" data-value="{{selectedTag}}">
<button class="toggle-button font-semibold rounded inline-flex justify-between
appearance-none w-full border border-gray-200 text-gray-700 p-2 rounded"
onclick="$('#tags_dropdown').slideToggle('medium');">
<span class="label" data-value="{{_('select_tag')}}">{{selectedTag or _('select_tag')}}</span>
<svg id="keyword-arrow_tag" class="fill-current h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg>
</button>
<div class="dropdown-menu dropdown-blue z-30 mt-2 w-full" id="tags_dropdown"
style="display: none; width: 100%;"
_="on mutation of @style
set arrow to #keyword-arrow_tag
if *display == 'none'
remove .rotate-180 from arrow
else if not arrow.classList.contains('rotate-180')
add .rotate-180 to arrow
end">
{% for tag in available_tags %}
{% set selected = tag in selectedTag %}
<div class="option {% if selected %}selected{% endif %}"
{% if selected %}
hx-post="/public-adventures/filter?tag={{tag}}&reset={{selectedTag}}&level={{selectedLevel}}&lang={{selectedLang}}&search={{currentSearch}}"
{% else %}
hx-post="/public-adventures/filter?tag={{tag + ',' + selectedTag}}&level={{selectedLevel}}&lang={{selectedLang}}&search={{currentSearch}}"
{% endif %}
hx-target="#public-adventures"
data-value="{{tag}}">{{tag}}</div>
{% endfor %}
</div>
</div>
<hedy-select id="tag-select" data-label="{{ _('select_tag') }}">
<select multiple>
{% for tag in available_tags %}
{% set selected = tag in selectedTag %}
<option {% if selected %}selected{% endif %}
{% if selected %}
hx-post="/public-adventures/filter?tag={{tag}}&reset={{selectedTag}}&level={{selectedLevel}}&lang={{selectedLang}}&search={{currentSearch}}"
{% else %}
hx-post="/public-adventures/filter?tag={{tag + ',' + selectedTag}}&level={{selectedLevel}}&lang={{selectedLang}}&search={{currentSearch}}"
{% endif %}
hx-target="#public-adventures" value="{{tag}}">{{tag}}</option>
{% endfor %}
</select>
</hedy-select>
</div>

</div>
Expand Down