Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC-002: Top Nav + Routing: Ability + Tenancy #3

Merged
merged 14 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .env.public
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# please copy and fill this to .env.local
# or add it to you ci environment


# ----------------
# PRIVATE VARIABLES
# @@@ WARNING: DON'T ADD NEXT_PUBLIC_* VARIABLES IF THEY'RE PRIVATE @@@

# env specific
NEXTAUTH_SECRET=
NEXTAUTH_URL=
Expand All @@ -19,6 +24,9 @@ EMAIL_FROM=
# modes: "full" (feats: enable-multi-tenancy,;)
NEXUS_MODE=

# base path: server-only
NEXUS_BASE_PATH=

# env agnostic
MONGODB_URI=

Expand All @@ -27,4 +35,14 @@ MONGODB_DATABASE=

# optional dbs (if used, all must be filled)
MONGODB_USERS_DATABASE=
MONGODB_ORGS_DATABASE=
MONGODB_ORGS_DATABASE=

# ----------------
# PUBLIC VARIABLES
# @@@ WARNING: THESE APPEAR IN THE BROWSER OF EVERY VISITOR @@@

# base path: client (browser)
NEXT_PUBLIC_NEXUS_BASE_PATH=
NEXT_PUBLIC_NEXUS_NAME=
NEXT_PUBLIC_NEXUS_LOGO_PATH=
NEXT_PUBLIC_NEXUS_DEFAULT_IMAGE_PATH=
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@ License: © Purizu di Angelo Reale

Authors: varsnothing aka Angelo Reale

This repo is just an exercise on some engineering design patterns. I've used Next.js new pragma (App Router) to apply them, so that I could also learn that new way of using Next.js.

I didn't use Co-Pilot, nor ChatGPT. I use Sublime and Tmux. What is auto-suggestion and intelli-sense?

After a few weeks without coding, I have to say I should have been less eager to try so many new things/technologies/patterns in such a short timeframe, as that has definitely impacted my velocity and workflow. Also, TypeScript can slow things down when I'm out of stretch.

Nonetheless, I think I had a good opportunity to use a few of the things I like the most (DRY, YAGNI, KISS, SOLID, MVC, Singleton, Decorator, Curry, Flux, Interface, Gateway and other patterns). At the end I even thought of using Mutex for optimization on the context, but maybe next time.

I'm looking for a new job, and you can check my CV / book some time with me here: https://angeloreale.com


Why Libs?
Why Libs:

react

Expand Down
3 changes: 3 additions & 0 deletions lib/actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// README.md

This directory stores all Server/User Initiated Actions/Operations related things
139 changes: 139 additions & 0 deletions lib/actions/actions-init.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// actions-init.tsx
"use client";
import type {
ISupportedContexts,
IActionBack,
IAction,
IStatus,
ICreateAction,
IDispatch,
IPayload,
} from "@types";

import { createLogMessage, fluxLog as log } from "@log";

import { useState, useEffect, useContext, useRef } from "react";
import { AuthContext, RMContext, LogContext } from "@state";

export const CreateAction: ICreateAction =
({ action, type, verb, context }: IActionBack) =>
({ cb }: IAction) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const noop: IDispatch = async (...payload: IPayload): Promise<void> => {};

// to-do: abstract from auth context (link to ticket)
const _context: ISupportedContexts =
useContext<ISupportedContexts>(context);
const { setter }: ISupportedContexts = _context;

const init = useRef(false);
const s_current = useRef("loaded");
const message = useRef("");
const to_call = useRef<IDispatch>(noop);
const status = useRef<IStatus>({
current: s_current.current,
str: createLogMessage(),
ok: undefined,
});
const payload = useRef<IPayload>();
const [dispatchd, setDispatchd] = useState(false);

const updateStatus = (
{ ok }: { ok: boolean | undefined } = { ok: undefined },
) => {
const _status = {
category: "flux",
type,
action,
verb,
message: message.current,
status: s_current?.current,
};
const str = createLogMessage(_status);
status.current = {
str,
ok,
current: s_current.current,
};
log(_status);
};

const cancel = () => {
updateStatus({ ok: undefined });
return;
};

const dispatch: IDispatch = (clientPayload, toCall) => {
payload.current = { ...clientPayload };
s_current.current = "init:active";
message.current = "dispatched";
to_call.current = toCall || noop;
updateStatus();
setDispatchd(!dispatchd);
};

const reset = () => {
payload.current = undefined;
setDispatchd(false);
};

useEffect(() => {
if (!dispatchd) {
s_current.current = "init:idle";
message.current = "not dispatched yet";
return cancel();
}

if (!payload?.current) {
s_current.current = "cancelled";
message.current = "no payload data";
return cancel();
}

s_current.current = "started";
message.current = "loading payload data";
updateStatus();

if (setter) {
setter({
..._context,
...payload.current,
history: [..._context.history, status.current.str],
});
}

init.current = true;

s_current.current = "in progress";
message.current = "calling functions";
updateStatus({ ok: undefined });

if (typeof to_call?.current === "function")
to_call.current(payload.current);

s_current.current = "completed";
message.current = "success";
updateStatus({ ok: true });

if (cb && cb?.length > 0) {
cb.forEach((_cb) => {
_cb();
});
}

reset();

return () => {
s_current.current = "ended";
message.current = "exit 0";
updateStatus();
reset();
};
}, [dispatchd]);

return [status?.current?.ok, dispatch];
};

export const BuildAction = (Component: ICreateAction, options: IActionBack) => {
return Component(options);
};
Loading
Loading