diff --git a/static/components/chat-dialog/chat-dialog.html b/static/components/chat-dialog/chat-dialog.html index 1e46a4d..a428044 100644 --- a/static/components/chat-dialog/chat-dialog.html +++ b/static/components/chat-dialog/chat-dialog.html @@ -33,7 +33,7 @@ :text="[message.msg]" :sent="message.sender == 'Me'" :bg-color="message.sender == 'Me' ? 'white' : 'light-green-2'" - :stamp="`${timeFromNow(message.timestamp * 1000)}`" + :stamp="message.timestamp" size="6" /> diff --git a/static/components/chat-dialog/chat-dialog.js b/static/components/chat-dialog/chat-dialog.js index e89e26d..c111e27 100644 --- a/static/components/chat-dialog/chat-dialog.js +++ b/static/components/chat-dialog/chat-dialog.js @@ -69,7 +69,7 @@ async function chatDialog(path) { } messagesMap.set(event.id, { msg: plaintext, - timestamp: event.created_at, + timestamp: timeFromNow(event.created_at * 1000), sender: `${mine ? 'Me' : 'Merchant'}` }) } catch { @@ -107,11 +107,9 @@ async function chatDialog(path) { let pub = relay.publish(event) pub.on('ok', () => { console.debug(`${relay.url} has accepted our event`) - relay.close() }) pub.on('failed', reason => { console.debug(`failed to publish to ${relay.url}: ${reason}`) - relay.close() }) this.newMessage = '' } catch (e) { @@ -146,59 +144,6 @@ async function chatDialog(path) { event = await window.nostr.signEvent(event) } return event - }, - timeFromNow(time) { - // Get timestamps - let unixTime = new Date(time).getTime() - if (!unixTime) return - let now = new Date().getTime() - - // Calculate difference - let difference = unixTime / 1000 - now / 1000 - - // Setup return object - let tfn = {} - - // Check if time is in the past, present, or future - tfn.when = 'now' - if (difference > 0) { - tfn.when = 'future' - } else if (difference < -1) { - tfn.when = 'past' - } - - // Convert difference to absolute - difference = Math.abs(difference) - - // Calculate time unit - if (difference / (60 * 60 * 24 * 365) > 1) { - // Years - tfn.unitOfTime = 'years' - tfn.time = Math.floor(difference / (60 * 60 * 24 * 365)) - } else if (difference / (60 * 60 * 24 * 45) > 1) { - // Months - tfn.unitOfTime = 'months' - tfn.time = Math.floor(difference / (60 * 60 * 24 * 45)) - } else if (difference / (60 * 60 * 24) > 1) { - // Days - tfn.unitOfTime = 'days' - tfn.time = Math.floor(difference / (60 * 60 * 24)) - } else if (difference / (60 * 60) > 1) { - // Hours - tfn.unitOfTime = 'hours' - tfn.time = Math.floor(difference / (60 * 60)) - } else if (difference / 60 > 1) { - // Minutes - tfn.unitOfTime = 'minutes' - tfn.time = Math.floor(difference / 60) - } else { - // Seconds - tfn.unitOfTime = 'seconds' - tfn.time = Math.floor(difference) - } - - // Return time from now data - return `${tfn.time} ${tfn.unitOfTime}` } }, created() { diff --git a/static/js/market.js b/static/js/market.js index 3cf9b90..52fed25 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -62,12 +62,13 @@ const market = async () => { if (this.activeStall) { products = products.filter(p => p.stall_id == this.activeStall) } - if (!this.searchText || this.searchText.length < 2) return products + const searchText = this.searchText.toLowerCase() + if (!searchText || searchText.length < 2) return products return products.filter(p => { return ( - p.name.includes(this.searchText) || - p.description.includes(this.searchText) || - p.categories.includes(this.searchText) + p.name.toLowerCase().includes(searchText) || + p.description.toLowerCase().includes(searchText) || + p.categories.toLowerCase().includes(searchText) ) }) }, diff --git a/static/js/utils.js b/static/js/utils.js index 736fc8d..86c4d00 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -47,3 +47,57 @@ function isJson(str) { return false } } + +function timeFromNow(time) { + // Get timestamps + let unixTime = new Date(time).getTime() + if (!unixTime) return + let now = new Date().getTime() + + // Calculate difference + let difference = unixTime / 1000 - now / 1000 + + // Setup return object + let tfn = {} + + // Check if time is in the past, present, or future + tfn.when = 'now' + if (difference > 0) { + tfn.when = 'future' + } else if (difference < -1) { + tfn.when = 'past' + } + + // Convert difference to absolute + difference = Math.abs(difference) + + // Calculate time unit + if (difference / (60 * 60 * 24 * 365) > 1) { + // Years + tfn.unitOfTime = 'years' + tfn.time = Math.floor(difference / (60 * 60 * 24 * 365)) + } else if (difference / (60 * 60 * 24 * 45) > 1) { + // Months + tfn.unitOfTime = 'months' + tfn.time = Math.floor(difference / (60 * 60 * 24 * 45)) + } else if (difference / (60 * 60 * 24) > 1) { + // Days + tfn.unitOfTime = 'days' + tfn.time = Math.floor(difference / (60 * 60 * 24)) + } else if (difference / (60 * 60) > 1) { + // Hours + tfn.unitOfTime = 'hours' + tfn.time = Math.floor(difference / (60 * 60)) + } else if (difference / 60 > 1) { + // Minutes + tfn.unitOfTime = 'minutes' + tfn.time = Math.floor(difference / 60) + } else { + // Seconds + tfn.unitOfTime = 'seconds' + tfn.time = Math.floor(difference) + } + + // Return time from now data + return `${tfn.time} ${tfn.unitOfTime}` +} diff --git a/views.py b/views.py index d83bc85..3b757fb 100644 --- a/views.py +++ b/views.py @@ -23,18 +23,8 @@ async def index(request: Request, user: User = Depends(check_user_exists)): @nostrmarket_ext.get("/market", response_class=HTMLResponse) -async def market( - request: Request, - stall_id: str = Query(None), - product_id: str = Query(None), - merchant_pubkey: str = Query(None), -): +async def market(request: Request): return nostrmarket_renderer().TemplateResponse( "nostrmarket/market.html", - { - "request": request, - "stall_id": stall_id, - "product_id": product_id, - "merchant_pubkey": merchant_pubkey, - }, + {"request": request}, )