Skip to main content

Posts

Pagination in Server Component Next js

I have a project that I'm doing. I'm trying to do pagination using the NextJS 13 server component without using use client. We need to make the code work. Now this code only adds a parameter to the page url, but does not add entries to the screen. In theory, it should first show 1 article, then when the button is clicked, 1 more article, then another, and so on. Nothing is happening right now. //component fetch mdx files import fs from 'fs'; import path from 'path'; import matter from 'gray-matter'; interface Blog { meta: any; slug: string; } export function getAllPosts() { // 1) Set blogs directory const blogDir = "blog"; // 2) Find all files in the blog directory const files = fs.readdirSync(path.join(blogDir)); // 3) For each blog found const blogs: Blog[] = files.map((filename: string) => { // 4) Read the content of that blog const fileContent = fs.readFileSync(path.join(blogDir, filename), 'utf-8'

Next-Auth getServerSession not retrieving user data in Nextjs 13.4 API Route

I need to access user session data in a Next-Auth/Nextjs 13.4 API Route. I have configured the JWT and Session callback; however, the user data I specified in the callback function does not translate to what getServerSession is pulling in an API route. However, the session data does correctly reflect in a Client page when using useSession() so I'm not sure what the issue is. [...nextauth]/route.js import { connectToDB } from "@/app/server/db"; import NextAuth from "next-auth"; import CredentialsProvider from "next-auth/providers/credentials"; import bcrypt from 'bcrypt'; // Authorize function async function authorize(credentials) { const { email, password } = credentials; const { db } = await connectToDB("Tenants"); const user = await db.collection("Users").findOne({ email }); if (user) { const isPasswordValid = await bcrypt.compare(password, user.password); if (!isPasswordValid) { return

How to make audio element hide after pressing play

So I'm trying to make an audio element hide after you press "play" but sadly it will not work Here's the code var audio = document.querySelector('audio'); audio.addEventListener('play', function() { audio.style.display = 'none'; audio.removeAttribute('controls'); }); and here's the HTML code <audio controls autoplay loop> <source src="Music551.mp3" type="audio/mp3" /> </audio> also I added some CSS but it's just for it to be at the bottom right audio { position: absolute; bottom: 0; right: 0; } But it's still not working I've tried everything. Also the file is in .php but all the HTML and JavaScript and CSS still works fine so I don't know. Also the audio element works fine but when I click play, the element is not hiding for some reason. I was expecting the audio to hide after clicking play. Via Active questions tagged javascript - Stack Overflow https://i

Unable to fetch document from firestore using .doc()

I have a collection whose document id got changed. Now when I fetch that document using this piece of code: const doc = database.collection(col).doc(col.documentId as string); I get this error: Error: 5 NOT_FOUND: But if I use the where clause and provide the same col.documentId, I am able to fetch that document. Please help here. Via Active questions tagged javascript - Stack Overflow https://ift.tt/zmyXjp5

"TypeError: Cannot read properties of undefined (reading 'onDestroy')" while using observable with NgFor and the Async Pipe

I'm trying to display a list of jobs, the code looks like loadJob() { let query = { pageNo: this.pageNo, title: this.searchParam.title, location: this.searchParam.location, industry:this.searchParam.industry } this.store.dispatch(InitJobComponent({query})); this.jobs$ = this.store.pipe( select(getJobState) ); this.jobs$.subscribe((jobs) => { if (jobs && jobs.data && jobs.data.length>0) { this.currentJob = jobs.data[0]; this.checkSaveStatus(this.currentJob); this.trustedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.currentJob.file); } }); } <div *ngIf="(jobs$ | async) as jobs" class="page-wrapper job-list"> <div class="no-results" *ngIf="jobs.totalCount == 0"> <h3>No results found.</h3> </div> <nz-layout *ngIf="jobs.totalCount > 0" class="content"> <nz-sider class="sid

How can a View get information from another class?

I am writing a calculator program. class Main { constructor() { this.calculator = new Calculator // here I do my calculations this.view = new View(this.calculator) // <-- watch this this.keyboard = new Keyboard // here I have some event listeners and other fun stuff } } After user clicking on the button, I have to rerender the view. But for this I need to know the result of math operation. I can't call the calculator methods directly in View class, so I passed the calculator object as an argument. Is this normal practice? Please show me what other ways exist to exchange information between objects? Via Active questions tagged javascript - Stack Overflow https://ift.tt/IkPEmUo

Using PyGAD for feature selection

I'm trying to create a Python script for feature selection using PyGAD The code below shows my previous attempt, but I haven’t achieved the desired result. Can you please help me with the correct implementation? Im taking the primary example shown on the package's documentation page.The error Im receiving is: AttributeError: 'tuple' object has no attribute 'tb_frame' My attempt so far: import pygad import numpy from sklearn.model_selection import train_test_split, cross_val_score from src.learner_params import target_column, model_features from sklearn.datasets import load_breast_cancer from lightgbm import LGBMClassifier as lgbm bc = load_breast_cancer() bst = lgbm(random_state = 42) function_inputs = bc.feature_names X, y = bc.data,bc.target X = pd.DataFrame(X, columns=bc.feature_names) X_train, X_test, y_train, y_test = train_test_split(X, y, rando