Skip to content

Commit

Permalink
feat: check og data of original url and replace placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
RupaakSrinivas committed Jan 18, 2024
1 parent b8fb166 commit c4ade25
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/pages/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import Navbar from "@/components/Navbar";
import { Karantina, Space_Grotesk } from "next/font/google";
import { useEffect, useState } from "react";
import styles from "@/styles/index.module.css";
import Head from "next/head";

import {
Expand All @@ -17,8 +16,6 @@ import {
WhatsappIcon,
WhatsappShareButton,
} from "next-share";
import { clear } from "console";
import Footer from "@/components/Footer";

const karantina = Karantina({
subsets: ["latin"],
Expand All @@ -40,24 +37,24 @@ export default function Create() {

useEffect(() => {
const delayDebounceFn = setTimeout(() => {
const previewTestImage = document.getElementById("previewTest");
const previewImage = document.getElementById("previewImage");

if (url === "") {
return;
}
const Url = document.getElementById("urlInput") as HTMLInputElement;
const Title = document.getElementById("titleInput") as HTMLInputElement;
const Description = document.getElementById(
"descriptionInput"
) as HTMLInputElement;
const Image = document.getElementById("imageInput") as HTMLInputElement;

fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/metadata?url=${url}`)
.then((res) => res.json())
.then((data) => {
if (data.title != null && title != "") {
setTitle(data.title);
}
if (data.description != null && description != "") {
setDescription(data.description);
}
if (data.image != null && image != "") {
setImage(data.image);
}
Url.value = data.url;
Title.value = data.title;
Description.value = data.description;
Image.value = data.image;
})
.catch((err) => {
console.log(err);
Expand Down

0 comments on commit c4ade25

Please sign in to comment.