Market filter works except for exclusive boxes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Sam Russell
|
Sam Russell
|
||||||
Captured Sun
|
Captured Sun
|
||||||
|
11.25.25 - Added onChange for check boxes, added setQuery / onQueryChanged for easy filtering
|
||||||
11.24.25 - Fixing onClick because it was reversed, adding event to onHover params
|
11.24.25 - Fixing onClick because it was reversed, adding event to onHover params
|
||||||
11.23.25 - Added onSubmit() event for form submission, added marginHorizontal() and marginVertical()
|
11.23.25 - Added onSubmit() event for form submission, added marginHorizontal() and marginVertical()
|
||||||
11.20.25 - Added "pct" style unit, added alignVertical and alignHorizontal for flex boxes
|
11.20.25 - Added "pct" style unit, added alignVertical and alignHorizontal for flex boxes
|
||||||
@@ -28,6 +29,23 @@ history.pushState = function pushState() {
|
|||||||
window.addEventListener('popstate', () => {
|
window.addEventListener('popstate', () => {
|
||||||
window.dispatchEvent(new Event('navigate'));
|
window.dispatchEvent(new Event('navigate'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.setQuery = function(key, value) {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const params = url.searchParams;
|
||||||
|
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
params.delete(key);
|
||||||
|
} else {
|
||||||
|
params.set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newUrl = url.toString();
|
||||||
|
history.replaceState(null, "", newUrl);
|
||||||
|
window.dispatchEvent(new Event('query-changed'));
|
||||||
|
|
||||||
|
return newUrl;
|
||||||
|
};
|
||||||
|
|
||||||
window.navigateTo = function(url) {
|
window.navigateTo = function(url) {
|
||||||
window.dispatchEvent(new Event('navigate'));
|
window.dispatchEvent(new Event('navigate'));
|
||||||
@@ -877,6 +895,14 @@ HTMLElement.prototype.onInput = function(cb) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HTMLElement.prototype.onChange = function(cb) {
|
||||||
|
if(!this.matches('input, textarea, [contenteditable=""], [contenteditable="true"]'))
|
||||||
|
throw new Error("Can't put input event on non-input element!")
|
||||||
|
this._storeListener("change", cb);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
HTMLElement.prototype.onSubmit = function(cb) {
|
HTMLElement.prototype.onSubmit = function(cb) {
|
||||||
if(!this.matches('form'))
|
if(!this.matches('form'))
|
||||||
throw new Error("Can't put form event on non-form element!")
|
throw new Error("Can't put form event on non-form element!")
|
||||||
@@ -929,6 +955,33 @@ window.addEventListener("navigate", () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
Same principle applies
|
||||||
|
*/
|
||||||
|
queryListeners = []
|
||||||
|
HTMLElement.prototype.onQueryChanged = function(cb) {
|
||||||
|
this._storeListener("query-changed", cb);
|
||||||
|
|
||||||
|
let found = false
|
||||||
|
for(entry of queryListeners) {
|
||||||
|
if(entry.cb.toString() === cb.toString() &&
|
||||||
|
this.nodeName === entry.el.nodeName) {
|
||||||
|
found = true
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(found === false) {
|
||||||
|
queryListeners.push({el: this, cb: cb})
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
window.addEventListener("query-changed", () => {
|
||||||
|
for(entry of queryListeners) {
|
||||||
|
entry.el.dispatchEvent(new CustomEvent("query-changed"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
HTMLElement.prototype.onEvent = function(name, cb) {
|
HTMLElement.prototype.onEvent = function(name, cb) {
|
||||||
window._storeListener(window, name, cb);
|
window._storeListener(window, name, cb);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -103,27 +103,6 @@ class Forum extends Shadow {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
button("+ New Message")
|
|
||||||
.width(13, em)
|
|
||||||
.marginLeft(1, em)
|
|
||||||
.borderRadius(10, px)
|
|
||||||
.background("transparent")
|
|
||||||
.border("0.5px solid #bb7c36")
|
|
||||||
.color("var(--accent)")
|
|
||||||
.fontFamily("Bona Nova")
|
|
||||||
.onHover(function (hovering) {
|
|
||||||
if(hovering) {
|
|
||||||
this.style.background = "var(--green)"
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.style.background = "transparent"
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.onClick((clicking) => {
|
|
||||||
console.log(this, "clicked")
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.x(55, vw).y(4, vh)
|
.x(55, vw).y(4, vh)
|
||||||
.position("absolute")
|
.position("absolute")
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ class MessagesPanel extends Shadow {
|
|||||||
}
|
}
|
||||||
window.addEventListener("new-message", (e) => {
|
window.addEventListener("new-message", (e) => {
|
||||||
this.messages = e.detail
|
this.messages = e.detail
|
||||||
this.rerender()
|
if(e.detail.length !== this.messages || e.detail.last.time !== this.messages.last.time || e.detail.first.time !== this.messages.first.time) {
|
||||||
|
this.rerender()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.scrollTop = this.scrollHeight
|
.scrollTop = this.scrollHeight
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class Market extends Shadow {
|
|||||||
price: "$12",
|
price: "$12",
|
||||||
company: "Hyperia",
|
company: "Hyperia",
|
||||||
type: "new",
|
type: "new",
|
||||||
image: "/db/images/1"
|
image: "/db/images/1",
|
||||||
|
madeIn: "America"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -29,24 +29,46 @@ class MarketGrid extends Shadow {
|
|||||||
ZStack(() => {
|
ZStack(() => {
|
||||||
// BuyModal()
|
// BuyModal()
|
||||||
|
|
||||||
for (let i = 0; i < this.listings.length; i++) {
|
let params = new URLSearchParams(window.location.search);
|
||||||
const rating = this.listings[i].stars
|
|
||||||
|
const hyperiaMade = params.get("hyperia-made") === "true";
|
||||||
|
const americaMade = params.get("america-made") === "true";
|
||||||
|
const newItem = params.get("new") === "true";
|
||||||
|
const usedItem = params.get("used") === "true";
|
||||||
|
|
||||||
|
|
||||||
|
let filtered = this.listings;
|
||||||
|
if (hyperiaMade) {
|
||||||
|
filtered = filtered.filter(item => item.madeIn === "Hyperia");
|
||||||
|
}
|
||||||
|
if (americaMade) {
|
||||||
|
filtered = filtered.filter(item => item.madeIn === "America");
|
||||||
|
}
|
||||||
|
if (newItem) {
|
||||||
|
filtered = filtered.filter(item => item.type === "new");
|
||||||
|
}
|
||||||
|
if (usedItem) {
|
||||||
|
filtered = filtered.filter(item => item.type === "used");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < filtered.length; i++) {
|
||||||
|
const rating = filtered[i].stars
|
||||||
const percent = (rating / 5)
|
const percent = (rating / 5)
|
||||||
|
|
||||||
VStack(() => {
|
VStack(() => {
|
||||||
img(this.listings[i].image)
|
img(filtered[i].image)
|
||||||
.marginBottom(0.5, em)
|
.marginBottom(0.5, em)
|
||||||
|
|
||||||
p(this.listings[i].company)
|
p(filtered[i].company)
|
||||||
.marginBottom(0.5, em)
|
.marginBottom(0.5, em)
|
||||||
|
|
||||||
p(this.listings[i].title)
|
p(filtered[i].title)
|
||||||
.fontSize(1.2, em)
|
.fontSize(1.2, em)
|
||||||
.fontWeight("bold")
|
.fontWeight("bold")
|
||||||
.marginBottom(0.5, em)
|
.marginBottom(0.5, em)
|
||||||
|
|
||||||
HStack(() => {
|
HStack(() => {
|
||||||
p(this.listings[i].stars)
|
p(filtered[i].stars)
|
||||||
.marginRight(0.2, em)
|
.marginRight(0.2, em)
|
||||||
|
|
||||||
ZStack(() => {
|
ZStack(() => {
|
||||||
@@ -67,21 +89,28 @@ class MarketGrid extends Shadow {
|
|||||||
.fontSize(1.2, em)
|
.fontSize(1.2, em)
|
||||||
.lineHeight(1)
|
.lineHeight(1)
|
||||||
|
|
||||||
p(this.listings[i].reviews)
|
p(filtered[i].reviews)
|
||||||
.marginLeft(0.2, em)
|
.marginLeft(0.2, em)
|
||||||
})
|
})
|
||||||
.marginBottom(0.5, em)
|
.marginBottom(0.5, em)
|
||||||
|
|
||||||
p(this.listings[i].price)
|
p(filtered[i].price)
|
||||||
.fontSize(1.75, em)
|
.fontSize(1.75, em)
|
||||||
.marginBottom(0.5, em)
|
.marginBottom(0.5, em)
|
||||||
|
|
||||||
button("Buy Now")
|
button("Coming Soon!")
|
||||||
.onClick((finished) => {
|
.onClick((finished) => {
|
||||||
if(finished) {
|
if(finished) {
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.onHover(function (hovering) {
|
||||||
|
if(hovering) {
|
||||||
|
this.style.backgroundColor = "var(--green)"
|
||||||
|
} else {
|
||||||
|
this.style.backgroundColor = ""
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
.padding(1, em)
|
.padding(1, em)
|
||||||
@@ -96,6 +125,10 @@ class MarketGrid extends Shadow {
|
|||||||
p("No Listings!")
|
p("No Listings!")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.onQueryChanged(() => {
|
||||||
|
console.log("query did change yup")
|
||||||
|
this.rerender()
|
||||||
|
})
|
||||||
.height(100, vh)
|
.height(100, vh)
|
||||||
.paddingLeft(2, em)
|
.paddingLeft(2, em)
|
||||||
.paddingRight(2, em)
|
.paddingRight(2, em)
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
class MarketSidebar extends Shadow {
|
class MarketSidebar extends Shadow {
|
||||||
|
|
||||||
|
handleChecked(e) {
|
||||||
|
let checked = e.target.checked
|
||||||
|
let label = $(`label[for="${e.target.id}"]`).innerText
|
||||||
|
if(checked) {
|
||||||
|
window.setQuery(label.toLowerCase(), true)
|
||||||
|
} else {
|
||||||
|
window.setQuery(label.toLowerCase(), null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
VStack(() => {
|
VStack(() => {
|
||||||
HStack(() => {
|
HStack(() => {
|
||||||
@@ -7,6 +18,7 @@ class MarketSidebar extends Shadow {
|
|||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"id": "hyperia-check"
|
"id": "hyperia-check"
|
||||||
})
|
})
|
||||||
|
.onChange(this.handleChecked)
|
||||||
label("Hyperia-Made")
|
label("Hyperia-Made")
|
||||||
.attr({
|
.attr({
|
||||||
"for": "hyperia-check"
|
"for": "hyperia-check"
|
||||||
@@ -20,6 +32,7 @@ class MarketSidebar extends Shadow {
|
|||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"id": "america-check"
|
"id": "america-check"
|
||||||
})
|
})
|
||||||
|
.onChange(this.handleChecked)
|
||||||
label("America-Made")
|
label("America-Made")
|
||||||
.attr({
|
.attr({
|
||||||
"for": "america-check"
|
"for": "america-check"
|
||||||
@@ -33,6 +46,7 @@ class MarketSidebar extends Shadow {
|
|||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"id": "new-check"
|
"id": "new-check"
|
||||||
})
|
})
|
||||||
|
.onChange(this.handleChecked)
|
||||||
label("New")
|
label("New")
|
||||||
.attr({
|
.attr({
|
||||||
"for": "new-check"
|
"for": "new-check"
|
||||||
@@ -46,6 +60,7 @@ class MarketSidebar extends Shadow {
|
|||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
"id": "used-check"
|
"id": "used-check"
|
||||||
})
|
})
|
||||||
|
.onChange(this.handleChecked)
|
||||||
label("Used")
|
label("Used")
|
||||||
.attr({
|
.attr({
|
||||||
"for": "used-check"
|
"for": "used-check"
|
||||||
|
|||||||
Reference in New Issue
Block a user