Skip to content

Commit

Permalink
Error Handling Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
The-XENO-Studios committed Jul 26, 2024
1 parent c2c61c4 commit 6245a8e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 93 deletions.
135 changes: 64 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dotenv": "^16.3.1",
"express": "^4.19.2",
"framer-motion": "^10.16.5",
"next": "14.0.2",
"next": "^14.2.5",
"nextjs-toploader": "^1.6.4",
"nodemailer": "^6.9.7",
"react": "^18",
Expand Down
22 changes: 17 additions & 5 deletions src/app/Components/HashtechPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ interface Props {
redirectUrl: string;
}

const HashtechPosts = async ({ title, desc, redirectUrl }: Props) => {
let regex = /fbid=(\d+)&/;
let imageCode = redirectUrl.match(regex);

async function getData(imageCode: any) {
const res = await fetch(
imageCode
? `https://hashtechimg.pythonanywhere.com/${imageCode[1]}?size=360`
: "https://hashtechimg.pythonanywhere.com/874301847421348?size=360",
{ cache: "no-store" }
);

const imgURL = await res.url;
if (!res.ok) {
return "/Logo.png";
} else {
return res.url;
}
}

const HashtechPosts = async ({ title, desc, redirectUrl }: Props) => {
let regex = /fbid=(\d+)&/;
let imageCode = redirectUrl.match(regex);

let imgURL = "";

try {
imgURL = await getData(imageCode);
} catch (error) {}

// const inView = useInView(ref, { once: true });
return (
Expand Down
25 changes: 20 additions & 5 deletions src/app/Components/Sidebar/NewNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import SaveData from "./SaveData";

const NewNotification = async () => {
let data = [];
async function getData() {
const res = await fetch(
"https://nditc.pythonanywhere.com/api/v1/notifications/web?page=1&limit=1",
{ cache: "no-store" }
);
if (res.ok) {
data = await res.json();

if (!res.ok) {
return [];
} else {
return res.json();
}
}

const NewNotification = async () => {
let data: any[] = [];
try {
data = await getData();
} catch (error) {
console.log("Error");
}

return <SaveData data={data} />;
if (data.length != 0) {
<SaveData data={data} />;
} else {
return <div></div>;
}
};

export default NewNotification;
7 changes: 5 additions & 2 deletions src/app/Components/Sidebar/SaveData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import Link from "next/link";
import { useEffect, useState } from "react";

const SaveData = ({ data }: { data: any }) => {
const detailsEncrypt = AES.encrypt(data[0].details_url, "Anime");
const detailsEncrypt = AES.encrypt(
data.length != 0 ? data[0].details_url : "OOOPS",
"Anime"
);
const [isNew, setIsNew] = useState(false);

const NewNotification = JSON.stringify(data[0].title);
const NewNotification = JSON.stringify(data[0]?.title);

useEffect(() => {
const savedNotification = localStorage.getItem("latestNotification");
Expand Down
Loading

0 comments on commit 6245a8e

Please sign in to comment.