Set up bridge folder + changes to Events/Jobs
- Copied bridge folder from frm.so - All handlers in handlers.js added from frm.so - Modified Events and Jobs pages' default events/jobs to model data structure from SQL/server - Set up getJobs(), checkForUpdates() on both Events/Jobs to fetch new items and update when needed
This commit is contained in:
@@ -23,7 +23,7 @@ class EventCard extends Shadow {
|
||||
|
||||
HStack(() => {
|
||||
img(util.cssVariable("time-src"), "1.2em")
|
||||
p(this.convertDate(this.event.time))
|
||||
p(this.convertDate(this.event.time_start))
|
||||
})
|
||||
.gap(0.4, em)
|
||||
.verticalAlign("center")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import "../../components/LoadingCircle.js"
|
||||
import "./EventCard.js"
|
||||
import server from "../../_/code/bridge/serverFunctions.js"
|
||||
import "../../components/SearchBar.js"
|
||||
|
||||
css(`
|
||||
@@ -23,10 +24,15 @@ css(`
|
||||
class Events extends Shadow {
|
||||
events = [
|
||||
{
|
||||
id: 1,
|
||||
network_id: 2,
|
||||
creator_id: 1,
|
||||
title: "Austin Chapter Lead",
|
||||
description: "This is the descriptio lets try a longer one agaiin just to see what it would look like? mayeb even longer bc that was pretty short now that i see it. maybe 2 sentences if possible or more.",
|
||||
location: "1234 location",
|
||||
time: "2026-01-13 13:41:41.0722"
|
||||
time_start: "2026-01-13 13:41:41.0722",
|
||||
created: "2026-01-13 12:00:00.0000",
|
||||
updated_at: "2026-01-13 13:41:41.0722"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -49,7 +55,7 @@ class Events extends Shadow {
|
||||
|
||||
SearchBar()
|
||||
|
||||
if (this.events == "") {
|
||||
if (this.events == "" || this.events == []) {
|
||||
LoadingCircle()
|
||||
} else if (this.events.length > 0) {
|
||||
for (let i = 0; i < this.events.length; i++) {
|
||||
@@ -71,6 +77,37 @@ class Events extends Shadow {
|
||||
.width(100, pct)
|
||||
}
|
||||
|
||||
async getEvents(networkId) {
|
||||
const fetchedEvents = await server.getEvents(networkId)
|
||||
if (this.checkForUpdates(this.events, fetchedEvents)) {
|
||||
this.events = fetchedEvents
|
||||
this.rerender()
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.getEvents(global.currentNetwork.id)
|
||||
}
|
||||
|
||||
checkForUpdates(currentEvents, fetchedEvents) {
|
||||
if (currentEvents.length !== fetchedEvents.length) return true;
|
||||
|
||||
const currentMap = new Map(currentEvents.map(event => [event.id, event]));
|
||||
|
||||
for (const fetchedEvent of fetchedEvents) {
|
||||
const currentEvent = currentMap.get(fetchedEvent.id);
|
||||
|
||||
// new event added
|
||||
if (!currentEvent) return true;
|
||||
|
||||
// existing event changed
|
||||
if (currentEvent.updated_at !== fetchedEvent.updated_at) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
convertDate(rawDate) {
|
||||
const parsed = new Date(rawDate);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import "./JobsGrid.js"
|
||||
import "./JobCard.js"
|
||||
import "./JobForm.js"
|
||||
import "../../components/SearchBar.js"
|
||||
import server from "../../_/code/bridge/serverFunctions.js"
|
||||
|
||||
css(`
|
||||
jobs- {
|
||||
@@ -25,11 +26,16 @@ css(`
|
||||
class Jobs extends Shadow {
|
||||
jobs = [
|
||||
{
|
||||
id: 1,
|
||||
network_id: 2,
|
||||
creator_id: 1,
|
||||
title: "Austin Chapter Lead",
|
||||
description: "This is the description",
|
||||
salary: "1% of Local Revenue",
|
||||
salary: 50000.00,
|
||||
company: "Hyperia",
|
||||
location: "1234 location"
|
||||
location: "1234 location",
|
||||
created: "2026-03-12 13:41:41.0722",
|
||||
updated_at: "2026-03-12 13:41:41.0722"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -49,7 +55,7 @@ class Jobs extends Shadow {
|
||||
|
||||
SearchBar()
|
||||
|
||||
if (this.jobs == "") {
|
||||
if (this.jobs == "" || this.jobs == []) {
|
||||
LoadingCircle()
|
||||
} else if (this.jobs.length > 0) {
|
||||
for (let i = 0; i < this.jobs.length; i++) {
|
||||
@@ -70,6 +76,37 @@ class Jobs extends Shadow {
|
||||
.height(100, pct)
|
||||
.width(100, pct)
|
||||
}
|
||||
|
||||
async getJobs(networkId) {
|
||||
const fetchedJobs = await server.getJobs(networkId)
|
||||
if (this.checkForUpdates(this.jobs, fetchedJobs)) {
|
||||
this.jobs = fetchedJobs
|
||||
this.rerender()
|
||||
}
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.getJobs(global.currentNetwork.id)
|
||||
}
|
||||
|
||||
checkForUpdates(currentJobs, fetchedJobs) {
|
||||
if (currentJobs.length !== fetchedJobs.length) return true;
|
||||
|
||||
const currentMap = new Map(currentJobs.map(job => [job.id, job]));
|
||||
|
||||
for (const fetchedJob of fetchedJobs) {
|
||||
const currentJob = currentMap.get(fetchedJob.id);
|
||||
|
||||
// new job added
|
||||
if (!currentJob) return true;
|
||||
|
||||
// existing job changed
|
||||
if (currentJob.updated_at !== fetchedJob.updated_at) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
register(Jobs)
|
||||
Reference in New Issue
Block a user