astronaut
astronaut
PPrisma
Created by astronaut on 4/26/2024 in #help-and-questions
How can show advertisement in queue in sync with all users?
with useEffect I can show ads but its not real time, I mean not sync 1 advertisement with all users
8 replies
PPrisma
Created by astronaut on 4/26/2024 in #help-and-questions
How can show advertisement in queue in sync with all users?
import { SignedIn, SignedOut, useUser } from '@clerk/nextjs';
import axios from 'axios';
import Image from 'next/image';
import Link from 'next/link';
import React, { useEffect, useState } from 'react';
import { toast } from 'react-toastify';

type AdType = {
_id: string;
link: string;
image: string;
}

const AdBox = () => {

const [ads, setAds] = useState<AdType[]>([]);
// const [totalPages, setTotalPages] = useState(0);
const [currentAdIndex, setCurrentAdIndex] = useState(0);

useEffect(() => {
fetchAds();
}, []);

const fetchAds = async () => {
try {
const response = await axios.get(`/api/advertisement/getAllAds2`);
setAds(response.data.advertisement);
} catch (error) {
console.error("Failed to fetch ads:", error);
}
};

useEffect(() => {
const interval = setInterval(() => {
setCurrentAdIndex(prevIndex => (prevIndex + 1) % ads.length);
}, 20000);

return () => clearInterval(interval);
}, [ads.length]);

return (
<div className="hidden md:flex max-w-xl w-1/5 mx-2 bg-beige shadow-md border-t border-black bg-gray-50 flex flex-col justify-center items-center ">
<p>Free Advertisement</p>
{ads.length > 0 && (
<div className="w-full h-full relative" key={ads[currentAdIndex]?._id}>
<a href={ads[currentAdIndex]?.link} target="_blank" rel="noopener noreferrer" className="absolute inset-0">
<Image src={ads[currentAdIndex]?.image} alt="Advertisement Image" layout="fill" objectFit="cover" />
<div className="absolute bottom-0 right-0 bg-red-500 text-sm py-1 px-2 hover:bg-red-600 focus:outline-none focus:bg-red-600">
<Link href="/sign-in" className="text-white text-sm font-semibold animate-pulse">
Post Ads for FREE
</Link>
</div>
</a>
</div>
)}
</div>
);
};

export default AdBox;
import { SignedIn, SignedOut, useUser } from '@clerk/nextjs';
import axios from 'axios';
import Image from 'next/image';
import Link from 'next/link';
import React, { useEffect, useState } from 'react';
import { toast } from 'react-toastify';

type AdType = {
_id: string;
link: string;
image: string;
}

const AdBox = () => {

const [ads, setAds] = useState<AdType[]>([]);
// const [totalPages, setTotalPages] = useState(0);
const [currentAdIndex, setCurrentAdIndex] = useState(0);

useEffect(() => {
fetchAds();
}, []);

const fetchAds = async () => {
try {
const response = await axios.get(`/api/advertisement/getAllAds2`);
setAds(response.data.advertisement);
} catch (error) {
console.error("Failed to fetch ads:", error);
}
};

useEffect(() => {
const interval = setInterval(() => {
setCurrentAdIndex(prevIndex => (prevIndex + 1) % ads.length);
}, 20000);

return () => clearInterval(interval);
}, [ads.length]);

return (
<div className="hidden md:flex max-w-xl w-1/5 mx-2 bg-beige shadow-md border-t border-black bg-gray-50 flex flex-col justify-center items-center ">
<p>Free Advertisement</p>
{ads.length > 0 && (
<div className="w-full h-full relative" key={ads[currentAdIndex]?._id}>
<a href={ads[currentAdIndex]?.link} target="_blank" rel="noopener noreferrer" className="absolute inset-0">
<Image src={ads[currentAdIndex]?.image} alt="Advertisement Image" layout="fill" objectFit="cover" />
<div className="absolute bottom-0 right-0 bg-red-500 text-sm py-1 px-2 hover:bg-red-600 focus:outline-none focus:bg-red-600">
<Link href="/sign-in" className="text-white text-sm font-semibold animate-pulse">
Post Ads for FREE
</Link>
</div>
</a>
</div>
)}
</div>
);
};

export default AdBox;
8 replies
PPrisma
Created by astronaut on 4/26/2024 in #help-and-questions
How can show advertisement in queue in sync with all users?
I will share that code with you
8 replies
PPrisma
Created by astronaut on 4/26/2024 in #help-and-questions
How can show advertisement in queue in sync with all users?
every user will see 1st advertisement when they open, casue that time it invokes the api at client side, so its not real time
8 replies
PPrisma
Created by astronaut on 4/26/2024 in #help-and-questions
How can show advertisement in queue in sync with all users?
currently I implemented client side code where data is fetch at once then I show them in interval of 2 minutes for each advertisement but its not real time, right ?
8 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
@Nurul for your reference see this https://github.com/prisma/prisma/issues/17338
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
see cursor, its not going forward like showing successfully generated or something like that. It stuck there
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
I want to create database name with image editor but its my project name and created with schema public in supabase, why ?
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
No description
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
no only 1, which I shared
11 replies
PPrisma
Created by astronaut on 3/15/2024 in #help-and-questions
Data is not showing in table
DATABASE_URL I used but yesterday I tried DIRECT_URL then I changed it again to DATABASE_URL.
11 replies