Skip to content

Commit acbcd6f

Browse files
committed
feat: Now we are fetching the likes using API. Removed the HarperFetch usage from the App component
1 parent d1d03db commit acbcd6f

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

components/core/App.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, { useEffect, useState } from "react";
2-
import axios from "axios";
3-
import dynamic from "next/dynamic";
42

5-
// harperDb fetch call
6-
import { harperFetch } from "../../utils/HarperFetch";
3+
// axios
4+
import axios from "axios";
75

8-
// Dummy Shape Data
9-
// import { shapes } from "../../data/shapes";
6+
// dynamic from next
7+
import dynamic from "next/dynamic";
108

119
// loader
1210
import Loader from "react-loader-spinner";
@@ -52,12 +50,12 @@ const App = (props) => {
5250
shapes = response.data;
5351

5452
// Fetch the shapes liked by the logged-in user
55-
const likedShapes = await harperFetch({
56-
operation: "sql",
57-
sql: `SELECT *
58-
FROM tryshape.likes
59-
WHERE email = '${user.email}'`,
53+
const likedResponse = await axios.get("/api/GET/likes", {
54+
params: {
55+
email: user.email
56+
}
6057
});
58+
const likedShapes = likedResponse.data;
6159

6260
// If there are liked shapes, take out the shape_id
6361
if (likedShapes.length > 0) {

pages/api/GET/likes.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export default async function handler(req, res) {
2+
const { email } = req.query;
3+
4+
let sql = `SELECT *
5+
FROM tryshape.likes
6+
WHERE email = '${email}'`;
7+
8+
9+
const request = await fetch(process.env.NEXT_PUBLIC_DB_URL, {
10+
method: "POST",
11+
headers: {
12+
"Content-Type": "application/json",
13+
Authorization: `Basic ${process.env.NEXT_PUBLIC_DB_AUTHORIZATION}`,
14+
},
15+
body: JSON.stringify({
16+
operation: "sql",
17+
sql: sql,
18+
}),
19+
});
20+
21+
const data = await request.json();
22+
// console.log(data);
23+
24+
res.status(200).json(data);
25+
}

0 commit comments

Comments
 (0)