grid split and searchbar

This commit is contained in:
Owen Rees
2023-05-24 00:07:34 +02:00
parent 8c67681825
commit 96eb4e37f1
7 changed files with 142 additions and 48 deletions
+21 -18
View File
@@ -1,31 +1,34 @@
import { MongoClient } from "mongodb";
if (!process.env.MONGODB_URI) {
throw new Error('Invalid environment variable: "MONGODB_URI"');
throw new Error('Invalid environment variable: "MONGODB_URI"');
}
const uri = process.env.MONGODB_URI
const options = {}
const uri = process.env.MONGODB_URI;
const options = {};
let client
let clientPromise: Promise<MongoClient>
let client;
let clientPromise: Promise<MongoClient>;
if (!process.env.MONGODB_URI) {
throw new Error('Please add your Mongo URI to .env.local')
throw new Error("Please add your Mongo URI to .env.local");
}
if (process.env.NODE_ENV === 'development') {
// In development mode, use a global variable so that the value
// is preserved across module reloads caused by HMR (Hot Module Replacement).
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options)
global._mongoClientPromise = client.connect()
}
clientPromise = global._mongoClientPromise
if (process.env.NODE_ENV === "development") {
// In development mode, use a global variable so that the value
// is preserved across module reloads caused by HMR (Hot Module Replacement).
//@ts-ignore
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options);
//@ts-ignore
global._mongoClientPromise = client.connect();
}
//@ts-ignore
clientPromise = global._mongoClientPromise;
} else {
// In production mode, it's best to not use a global variable.
client = new MongoClient(uri, options)
clientPromise = client.connect()
// In production mode, it's best to not use a global variable.
client = new MongoClient(uri, options);
clientPromise = client.connect();
}
export default clientPromise
export default clientPromise;