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:
@@ -1,4 +1,4 @@
|
|||||||
const IS_NODE =
|
export const IS_NODE =
|
||||||
typeof process !== "undefined" &&
|
typeof process !== "undefined" &&
|
||||||
process.versions?.node != null
|
process.versions?.node != null
|
||||||
|
|
||||||
@@ -9,9 +9,7 @@ async function bridgeSend(name, args) {
|
|||||||
args: args
|
args: args
|
||||||
})
|
})
|
||||||
|
|
||||||
const json = await res.json()
|
return res
|
||||||
if (!res.ok) throw new Error(json.error)
|
|
||||||
return json.result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,8 +22,6 @@ export function createBridge(funcs) {
|
|||||||
get(target, prop) {
|
get(target, prop) {
|
||||||
const orig = target[prop]
|
const orig = target[prop]
|
||||||
|
|
||||||
if (typeof orig !== "function") return orig
|
|
||||||
|
|
||||||
return function (...args) {
|
return function (...args) {
|
||||||
if (IS_NODE) {
|
if (IS_NODE) {
|
||||||
return orig(...args)
|
return orig(...args)
|
||||||
|
|||||||
47
src/_/code/bridge/handlers.js
Normal file
47
src/_/code/bridge/handlers.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
const handlers = {
|
||||||
|
async getStripeProfile(networkId) {
|
||||||
|
return global.payments.getProfile(networkId)
|
||||||
|
},
|
||||||
|
|
||||||
|
async addEvent(newEvent, networkId, creatorId) {
|
||||||
|
return await global.db.events.add(newEvent, networkId, creatorId)
|
||||||
|
},
|
||||||
|
|
||||||
|
async editEvent(id, updatedEvent, networkId, userId) {
|
||||||
|
return await global.db.events.add(id, updatedEvent, networkId, userId);
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteEvent(id, networkId, userId) {
|
||||||
|
return await global.db.events.add(id, networkId, userId);
|
||||||
|
},
|
||||||
|
|
||||||
|
async getEvent(id) {
|
||||||
|
return global.db.events.getById(id)
|
||||||
|
},
|
||||||
|
|
||||||
|
async getEvents(networkId) {
|
||||||
|
return global.db.events.getByNetwork(networkId)
|
||||||
|
},
|
||||||
|
|
||||||
|
async addJob(newJob, networkId, creatorId) {
|
||||||
|
return await global.db.jobs.add(newJob, networkId, creatorId);
|
||||||
|
},
|
||||||
|
|
||||||
|
async editJob(id, updatedJob, networkId, userId) {
|
||||||
|
return await global.db.jobs.add(id, updatedJob, networkId, userId);
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteJob(id, networkId, userId) {
|
||||||
|
return await global.db.jobs.add(id, networkId, userId);
|
||||||
|
},
|
||||||
|
|
||||||
|
async getJob(id) {
|
||||||
|
return await global.db.jobs.getById(id)
|
||||||
|
},
|
||||||
|
|
||||||
|
async getJobs(networkId) {
|
||||||
|
return global.db.jobs.getByNetwork(networkId)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default handlers
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
import fs from "fs"
|
import { createBridge, IS_NODE } from "./bridge.js"
|
||||||
import { createBridge } from "./bridge.js"
|
|
||||||
|
|
||||||
const handlers = {
|
let handlers = {}
|
||||||
getProfile(one, two) {
|
|
||||||
fs.writeFileSync("output.txt", `${one} ${two}`)
|
if (IS_NODE) {
|
||||||
return "written to disk"
|
const mod = await import("./handlers.js")
|
||||||
},
|
handlers = mod.default
|
||||||
}
|
}
|
||||||
|
|
||||||
export const { getProfile } = createBridge(handlers)
|
export default createBridge(handlers)
|
||||||
@@ -23,7 +23,7 @@ class EventCard extends Shadow {
|
|||||||
|
|
||||||
HStack(() => {
|
HStack(() => {
|
||||||
img(util.cssVariable("time-src"), "1.2em")
|
img(util.cssVariable("time-src"), "1.2em")
|
||||||
p(this.convertDate(this.event.time))
|
p(this.convertDate(this.event.time_start))
|
||||||
})
|
})
|
||||||
.gap(0.4, em)
|
.gap(0.4, em)
|
||||||
.verticalAlign("center")
|
.verticalAlign("center")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import "../../components/LoadingCircle.js"
|
import "../../components/LoadingCircle.js"
|
||||||
import "./EventCard.js"
|
import "./EventCard.js"
|
||||||
|
import server from "../../_/code/bridge/serverFunctions.js"
|
||||||
import "../../components/SearchBar.js"
|
import "../../components/SearchBar.js"
|
||||||
|
|
||||||
css(`
|
css(`
|
||||||
@@ -23,10 +24,15 @@ css(`
|
|||||||
class Events extends Shadow {
|
class Events extends Shadow {
|
||||||
events = [
|
events = [
|
||||||
{
|
{
|
||||||
|
id: 1,
|
||||||
|
network_id: 2,
|
||||||
|
creator_id: 1,
|
||||||
title: "Austin Chapter Lead",
|
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.",
|
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",
|
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()
|
SearchBar()
|
||||||
|
|
||||||
if (this.events == "") {
|
if (this.events == "" || this.events == []) {
|
||||||
LoadingCircle()
|
LoadingCircle()
|
||||||
} else if (this.events.length > 0) {
|
} else if (this.events.length > 0) {
|
||||||
for (let i = 0; i < this.events.length; i++) {
|
for (let i = 0; i < this.events.length; i++) {
|
||||||
@@ -71,6 +77,37 @@ class Events extends Shadow {
|
|||||||
.width(100, pct)
|
.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) {
|
convertDate(rawDate) {
|
||||||
const parsed = new Date(rawDate);
|
const parsed = new Date(rawDate);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "./JobsGrid.js"
|
|||||||
import "./JobCard.js"
|
import "./JobCard.js"
|
||||||
import "./JobForm.js"
|
import "./JobForm.js"
|
||||||
import "../../components/SearchBar.js"
|
import "../../components/SearchBar.js"
|
||||||
|
import server from "../../_/code/bridge/serverFunctions.js"
|
||||||
|
|
||||||
css(`
|
css(`
|
||||||
jobs- {
|
jobs- {
|
||||||
@@ -25,11 +26,16 @@ css(`
|
|||||||
class Jobs extends Shadow {
|
class Jobs extends Shadow {
|
||||||
jobs = [
|
jobs = [
|
||||||
{
|
{
|
||||||
|
id: 1,
|
||||||
|
network_id: 2,
|
||||||
|
creator_id: 1,
|
||||||
title: "Austin Chapter Lead",
|
title: "Austin Chapter Lead",
|
||||||
description: "This is the description",
|
description: "This is the description",
|
||||||
salary: "1% of Local Revenue",
|
salary: 50000.00,
|
||||||
company: "Hyperia",
|
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()
|
SearchBar()
|
||||||
|
|
||||||
if (this.jobs == "") {
|
if (this.jobs == "" || this.jobs == []) {
|
||||||
LoadingCircle()
|
LoadingCircle()
|
||||||
} else if (this.jobs.length > 0) {
|
} else if (this.jobs.length > 0) {
|
||||||
for (let i = 0; i < this.jobs.length; i++) {
|
for (let i = 0; i < this.jobs.length; i++) {
|
||||||
@@ -70,6 +76,37 @@ class Jobs extends Shadow {
|
|||||||
.height(100, pct)
|
.height(100, pct)
|
||||||
.width(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)
|
register(Jobs)
|
||||||
Reference in New Issue
Block a user