Skip to content

Commit

Permalink
Merge branch 'main' into reefscape
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodellosso authored Feb 11, 2025
2 parents 99c7156 + c725109 commit 6d27abe
Show file tree
Hide file tree
Showing 20 changed files with 1,169 additions and 2,984 deletions.
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

/public/sw.js
/public/sw.js.map
/public/workbox-*
/public/fallback-*
/certs/*.*

/certs/*.*
# PWA
public/sw.js
public/swe-worker*
10 changes: 0 additions & 10 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ export default function Footer() {
? `SW Status: ${registration.active?.state}`
: "Service worker not found",
);
console.log("Service worker registration: ", registration);
if (registration) {
registration.addEventListener("updatefound", () => {
setSwStatus("Service worker update found");
console.log("Service worker update found");
registration.installing?.addEventListener("statechange", () => {
console.log(
"Service worker state change: ",
Expand All @@ -41,14 +39,6 @@ export default function Footer() {

registration.active?.addEventListener("statechange", () => {
setSwStatus(`SW Status: ${registration.active?.state}`);
console.log(
"Service worker state change: ",
registration.active?.state,
);
});

registration.update().then(() => {
console.log("Service worker update initiated");
});
}
});
Expand Down
27 changes: 21 additions & 6 deletions lib/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import CollectionId from "./client/CollectionId";
import { AdapterUser } from "next-auth/adapters";
import { wait } from "./client/ClientUtils";

var db = getDatabase();
const db = getDatabase();

const adapter = MongoDBAdapter(clientPromise, { databaseName: process.env.DB });

Expand Down Expand Up @@ -123,21 +123,36 @@ export const AuthenticationOptions: AuthOptions = {
if (!foundUser) await wait(50);
}

console.log(
"User is incomplete, filling in missing fields. User:",
typedUser,
);
console.log("User is incomplete, filling in missing fields.");

typedUser._id = foundUser._id;
typedUser.lastSignInDateTime = new Date();

typedUser = await repairUser(await db, typedUser);

console.log("User updated:", typedUser);
console.log("User updated:", typedUser._id?.toString());
};

repairUserOnceItIsInDb();
}

const today = new Date();
if (
(typedUser as User).lastSignInDateTime?.toDateString() !==
today.toDateString()
) {
// We use user.id since user._id strangely doesn't exist on user.
await getDatabase().then((db) =>
db.updateObjectById(
CollectionId.Users,
new ObjectId(typedUser._id?.toString()),
{
lastSignInDateTime: today,
},
),
);
}

new ResendUtils().createContact(typedUser as User);

return true;
Expand Down
121 changes: 121 additions & 0 deletions lib/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class User implements NextAuthUser {
level: number = 1;
onboardingComplete: boolean = false;
resendContactId: string | undefined = undefined;
lastSignInDateTime: Date | undefined = undefined;

constructor(
name: string | undefined,
Expand Down Expand Up @@ -567,6 +568,126 @@ export type CompPicklistGroup = {
strikethroughs: number[];
};

type LinkedNode<T> = T & {
prev?: LinkedNode<T>;
next?: LinkedNode<T>;
};

/**
* @tested_by tests/lib/Types.test.ts
*/
export class LinkedList<T> {
private head?: LinkedNode<T> = undefined;

constructor(head?: T | T[]) {
if (Array.isArray(head) && head.length > 0) {
let node: LinkedNode<T>;

for (const element of head) {
if (!this.head) {
this.head = {
...element,
next: undefined,
prev: undefined,
};

node = this.head;
} else node = this.insertAfter(node!, element);
}
} else if (head)
this.head = {
...(head as T),
next: undefined,
prev: undefined,
};
}

size() {
let count = 0;

for (let node = this.head; node !== undefined; node = node.next) count++;

return count;
}

isEmpty() {
return this.head === undefined;
}

first() {
return this.head;
}

last() {
let node = this.head;
while (node?.next) node = node.next;

return node;
}

// Add to criterion B
/**
* Will reset the list to just be head
*/
setHead(insertedVal: T) {
this.head = {
...insertedVal,
prev: undefined,
next: undefined,
};
}

insertBefore(existingNode: LinkedNode<T>, insertedVal: T) {
const insertedNode: LinkedNode<T> = {
...insertedVal,
next: existingNode,
};

if (existingNode.prev) {
existingNode.prev.next = insertedNode;
insertedNode.prev = existingNode.prev;
}
existingNode.prev = insertedNode;

if (this.head === existingNode) this.head = insertedNode;

return insertedNode;
}

insertAfter(existingNode: LinkedNode<T>, insertedVal: T) {
const insertedNode: LinkedNode<T> = {
...insertedVal,
prev: existingNode,
};

if (existingNode.next) {
existingNode.next.prev = insertedNode;
insertedNode.next = existingNode.next;
}
existingNode.next = insertedNode;

return insertedNode;
}

// Add to criterion B
forEach(func: (node: LinkedNode<T>) => any) {
for (let node = this.head; node; node = node.next) {
func(node);
}
}

// Add to criterion B
map<TMap>(func: (node: LinkedNode<T>) => TMap) {
const array: TMap[] = [];

for (let node = this.head; node; node = node.next) {
array.push(func(node));
}

return array;
}
}

/**
* DO NOT GIVE TO CLIENTS!
*/
Expand Down
Loading

0 comments on commit 6d27abe

Please sign in to comment.