Skip to content

Commit

Permalink
chore: update menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Nov 2, 2024
1 parent 04efb41 commit 1824eab
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 41 deletions.
2 changes: 1 addition & 1 deletion core/map/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ export class Store<K extends string | number | symbol, V> {
count++;
}
}
console.log(`${count} entries deleted`);
// console.log(`${count} entries deleted`);
}
}
9 changes: 6 additions & 3 deletions core/server/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "./types.ts";
import { EsbuildMod } from "../build/esbuildMod.ts";
import { Store } from "../map/mod.ts";
import { createTaskQueue } from "@app/utils/queue.ts";

export function checkReferer(req: Request) {
const referer = req.headers.get("referer");
Expand Down Expand Up @@ -396,7 +397,8 @@ if (root) fetchProps(root);
const r = new Render(this);
key = key === "/" ? "" : key;
key = url.origin + "/__/props" + key;
return r.render(key, page, data, this.getNonce(), headers);
const x = r.render(key, page, data, this.getNonce(), headers);
return x;
};
ctx.info = info;
ctx.next = () => {};
Expand Down Expand Up @@ -553,10 +555,10 @@ if (root) fetchProps(root);
info,
) as any;
if (page) {
return page.handler(
return await page.handler(
this.#transformRequest(req, pageParams, pageUrl),
pageCtx,
) as Promise<Response>;
) as Response;
}

return this.#handleStaticFile(req);
Expand Down Expand Up @@ -673,4 +675,5 @@ if (root) fetchProps(root);
#nonce = "";
serverOptions: Record<string, any> = {};
stores = new Map<string, Store<string | number | symbol, any>>();
private taskQueue = createTaskQueue();
}
50 changes: 25 additions & 25 deletions modules/index/index.menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,9 @@ export function Menu(

return (
<div
class={`hidden w-2/12 min-w-[250px] lg:flex lg:flex-col gap-y-2 ps-5 pt-5`}
class={`hidden w-2/12 min-w-[250px] lg:flex lg:flex-col gap-y-5 ps-5 pt-5`}
>
{
/* <div class={`flex gap-2 items-center`}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="icon icon-tabler icons-tabler-outline icon-tabler-bolt"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11" />
</svg>
<span>Home</span>
</div> */
}
<div class={`flex gap-1 items-center`}>
<div class={`flex gap-2 items-center`}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
Expand All @@ -73,11 +52,11 @@ export function Menu(
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
</svg>

<span>Explore</span>
<span>Discover</span>
</div>
<div class={`pl-3`}>
{loading
? <div class={`text-xs border-l-2 pl-3`}>Loading</div>
? <div class={`text-xs border-l-[1px] pl-3`}>Loading</div>
: (
<ul
class={`flex flex-col text-xs font-thin border-l pl-3 gap-y-3`}
Expand Down Expand Up @@ -142,6 +121,27 @@ export function Menu(
</div>
*/
}
<div class={`flex gap-2 items-center`}>
<svg
class="w-6 h-6 text-gray-800 dark:text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M16 10.5h.01m-4.01 0h.01M8 10.5h.01M5 5h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-6.6a1 1 0 0 0-.69.275l-2.866 2.723A.5.5 0 0 1 8 18.635V17a1 1 0 0 0-1-1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1Z"
/>
</svg>

<span>Chats</span>
</div>
<div class={`grow`}></div>
<div class={`flex justify-between gap-2 items-center`}>
<div class={`inline-flex gap-2 items-center`}>
Expand Down
25 changes: 18 additions & 7 deletions modules/room/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import { createCollection } from "@app/modules/store/mod.ts";
import { DAY } from "jsr:@std/datetime@^0.221.0/constants";

const initRooms = [
{ name: "global", id: "01JAC4GM721KGRWZHG53SMXZP0" },
{ name: "news", id: "01JBNM8TFVV961WFHCDK50N7CV" },
{ name: "jobs", id: "01JACBS4WXSJ1EG8G5C6NVHY7E" },
{ name: "startup", id: "01JBNPF4KWPD0TYS6SSSHZGY5E" },
{ name: "english", id: "01JACJFARBMNDSF1FCAH776YST" },
{ name: "smooking", id: "01JACJJ3CN1ZAYXDMQHC4CB2SQ" },
{ name: "training", id: "01JACFZ32G13BHA2QZZYQ4KJEK" },
{ name: "health", id: "01JBNM5X3Y12692X1EDCCR3G2Z" },
{ name: "finance", id: "01JBNM75G892T2K4FN7Q10AYAZ" },
{ name: "travel", id: "01JBNM7ZRDMZTM21F6X0986YB4" },
Expand All @@ -22,7 +17,23 @@ const initRooms = [
{ name: "sport", id: "01JBNMDE6XR6S4WKKSZ715B913" },
{ name: "education", id: "01JBNMYGN7VSN4H49YF63TX08R" },
{ name: "trading", id: "01JBNPHEMX9GYCH0RXB1WR75VR" },
{ name: "fashion", id: "01JBNVTCRG7A5SQ61BHJZKHT2Y" },
{ name: "furniture", id: "01JBNVV1H4DM86NAJ59DBCSMNA" },
{ name: "electronic", id: "01JBNVW2H8GWWACVB6R7XYR49F" },
];

const g = [
{ name: "global", id: "01JAC4GM721KGRWZHG53SMXZP0" },
{
name: "jobs",
id: "01JACBS4WXSJ1EG8G5C6NVHY7E",
},
{ name: "news", id: "01JBNM8TFVV961WFHCDK50N7CV" },
];
const i = initRooms.sort((a, b) => {
return a.name.localeCompare(b.name);
});
const arr = [...g, ...i];

type Arr = {
type: string;
Expand Down Expand Up @@ -92,7 +103,7 @@ export default function roomModules(s: Fastro) {
entries.map(([id, { value }]) => {
r.push({ id, name: value.name });
});
const rooms = [...initRooms, ...r];
const rooms = [...arr, ...r];
return Response.json(rooms);
});

Expand Down Expand Up @@ -126,7 +137,7 @@ export default function roomModules(s: Fastro) {
const r: any = [];
entries.map(([id, { value }]) => r.push({ id, name: value.name }));

const rooms = [...initRooms, ...r];
const rooms = [...arr, ...r];
const room = rooms.find((v) => v.id.toString() === target);
if (!room) return Response.json([]);
return Response.json(room);
Expand Down
13 changes: 9 additions & 4 deletions modules/socket/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ export default function socketModule(s: Fastro) {
}

async function joinRoom(ctx: Context, socket: WebSocket, room: string) {
if (socket.readyState !== WebSocket.OPEN) return;
const connections = await ctx.stores.get("core")?.get("connections");
if (!connections.has(room)) connections.set(room, new Set<WebSocket>());
connections.get(room)?.add(socket);
if (socket.readyState == WebSocket.OPEN) {
const connections = await ctx.stores.get("core")?.get(
"connections",
);
if (!connections.has(room)) {
connections.set(room, new Set<WebSocket>());
}
connections.get(room)?.add(socket);
}
}

const injectData = async (ctx: Context, data: Data) => {
Expand Down
2 changes: 1 addition & 1 deletion utils/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export function createTaskQueue() {
});
}

return { process: process };
return { process };
}

0 comments on commit 1824eab

Please sign in to comment.