Skip to content

Commit

Permalink
feat: fetch data from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
A1X5H04 committed Oct 20, 2023
1 parent 66aa450 commit fa0be47
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 175 deletions.
33 changes: 33 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export async function getProjectRepo() {
try {
const res = await fetch('https://api.npoint.io/8a1ae503884eede2a37f/projects_repo/');
const data = await res.json();
return data;
} catch (err) {
console.error(err);
return "Failed to fetch Projects Data"
}
}

export async function getLanguages() {
try {

const res = await fetch('https://api.npoint.io/8a1ae503884eede2a37f/languages/');
const data = await res.json();
return data;
} catch (err) {
console.error(err);
return "Failed to fetch Languages Data"
}
}

export async function getAbout() {
try {
const res = await fetch('https://api.npoint.io/8a1ae503884eede2a37f/about_list/');
const data = await res.json();
return data;
} catch (err) {
console.error(err);
return "Failed to fetch About Data"
}
}
28 changes: 2 additions & 26 deletions src/components/ChartImageLoader.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChartBar } from "@phosphor-icons/react";
import { useState, useEffect } from "react";
import LoadingSpinner from "./LoadingSpinner";

const ChartImageLoader = ({ imageUrl, ...props }) => {
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -27,7 +28,7 @@ const ChartImageLoader = ({ imageUrl, ...props }) => {
}, [imageUrl]);

if (loading) {
return <LoadingElement />;
return <LoadingSpinner />;
}

if (error) {
Expand All @@ -50,28 +51,3 @@ function ErrorElement() {
);
}

function LoadingElement() {
return (
<div className="p-10">
<div role="status">
<svg
aria-hidden="true"
className="w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-800 fill-black dark:fill-white"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
</div>
);
}
25 changes: 25 additions & 0 deletions src/components/LoadingSpinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default function LoadingSpinner() {
return (
<div className="p-10">
<div role="status">
<svg
aria-hidden="true"
className="w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-800 fill-black dark:fill-white"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
</div>
);
}
130 changes: 0 additions & 130 deletions src/data.js

This file was deleted.

32 changes: 19 additions & 13 deletions src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import React from "react";
import { languages } from "../data";
import ChartImageLoader from "../components/ChartImageLoader";
import GridPattern from "../components/GridPattern";
import { twMerge } from "tailwind-merge";
import { clsx } from "clsx";
import { Fade } from "react-awesome-reveal";
import { getLanguages, getAbout } from "../api";

function cn(...inputs) {
return twMerge(clsx(inputs));
}

const aboutArray = [
"👋 Hi I am Alish.",
"🖥️ See my portfolio at A1X5H04.github.com",
"👨‍💻 I'm currently working on contributing to Open Source projects.",
"✉️ You can reach me at [email protected]",
"🧠 I'm currently learning Android Development",
"🤝 I'm open to collaborating on anything?",
"⚡ Fun fact: I like phonk music",
];

function Dashboard() {

const [languagesArray, setLanguagesArray] = React.useState([]);
const [aboutArray, setAboutArray] = React.useState([]);

React.useEffect(() => {
const data = async () => {
const languages = await getLanguages();
setLanguagesArray(languages);
const about = await getAbout();
setAboutArray(about);
console.log(about);
}
data();
}, []);


return (
<div className="relative">
<div className="pt-10 mb-5 text-center">
Expand Down Expand Up @@ -57,7 +63,7 @@ function Dashboard() {
</div>
<div className="p-5">
<ul className="list-disc ml-3">
{aboutArray.map((item) => (
{aboutArray?.map((item) => (
<li className="my-2 font-medium">
<p className="text-sm">{item}</p>
</li>
Expand All @@ -80,7 +86,7 @@ function Dashboard() {
Languages Known
</p>
<div className="px-6 pb-5 w-full flex gap-3 flex-wrap">
{languages.map((item) => (
{languagesArray?.map((item) => (
<a
className="hover:opacity-75 duration-300"
href={item.link}
Expand Down
24 changes: 18 additions & 6 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import React from "react";
import ProjectTile from "../components/ProjectTile";
import { projects } from "../data";
import GridPattern from "../components/GridPattern";
import { twMerge } from "tailwind-merge";
import { getProjectRepo } from "../api";
import { clsx } from "clsx";
import { Fade, Flip, Hinge, Slide, Zoom } from "react-awesome-reveal";
import { Bounce, Fade, Flip, Hinge, JackInTheBox, Roll, Rotate, Slide, Zoom } from "react-awesome-reveal";

function cn(...inputs) {
return twMerge(clsx(inputs));
}


export default function Home() {
const [projectArray, setProjectArray] = React.useState([]);

React.useEffect(() => {
const data = async () => {
const projects = await getProjectRepo();
setProjectArray(projects);
}
data();
}, []);


return (
<div className="w-full overflow-hidden">
<div className=" border-b border-slate-400 dark:border-gray-800 text-center">
Expand Down Expand Up @@ -47,7 +59,7 @@ export default function Home() {
<div className="overflow-hidden">
<Slide direction="up" triggerOnce>
<h1 className="font-extrabold sm:inline-flex gap-3 tracking-wider h-full py-2 mb-2 mx-6 lg:text-7xl text-5xl text-transparent bg-clip-text bg-gradient-to-r from-[#8A2387] via-[#E94057] to-[#F27121] background-animate">
Frontend Developer
Frontend Developer
</h1>
</Slide>
</div>
Expand Down Expand Up @@ -113,7 +125,7 @@ export default function Home() {
</div>
<div className="mt-8 px-5">
<div className="h-min grid md:grid-cols-2 gap-4 grid-cols-1 ">
{projects.map((item) => {
{projectArray?.map((item) => {
return (
<ProjectTile
title={item.title}
Expand All @@ -127,8 +139,8 @@ export default function Home() {
</div>
<button
onClick={() =>
(window.location.href =
"https://github.com/A1X5H04?tab=repositories")
(window.location.href =
"https://github.com/A1X5H04?tab=repositories")
}
className="w-full my-4 hover:bg-slate-100 dark:hover:bg-gray-1000 text-sm font-bold py-2 rounded-md"
>
Expand Down

0 comments on commit fa0be47

Please sign in to comment.