Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WS] 1 Supabase Set-Up and Web Scraper Research #3

Merged
merged 12 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/supabase/createClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createClient } from '@supabase/supabase-js';

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL as string;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string;

if (!supabaseUrl || !supabaseKey) {
throw new Error(
'No Supabase environment variables detected, please make sure they are in place!',
);
}

const supabase = createClient(supabaseUrl, supabaseKey);

export default supabase;
9 changes: 9 additions & 0 deletions api/supabase/queries/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import supabase from '../createClient';

export default async function queryProjects() {
const { data: projects, error } = await supabase.from('Projects').select('*');

console.log('PROJECTS', projects, 'ERROR', error);

return { projects, error };
}
77 changes: 77 additions & 0 deletions app/testing/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use client';

import { CSSProperties, useEffect, useState } from 'react';
import Image from 'next/image';
import BPLogo from '@/assets/images/bp-logo.png';
import queryProjects from '../../api/supabase/queries/query';

interface Project {
id: string;
project_name: string;
energy_category: string;
size: number;
developer: string;
longitude: number;
latitude: number;
project_statues: string;
county: string;
town: string;
region: string;
state_senate_district: number;
assembly_district: number;
project_image: string | null;
additional_information: string | null;
key_development_milestones: object | null;
}

export default function Home() {
const [projects, setProjects] = useState<Project[] | null>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
queryProjects()
.then(data => {
setProjects(data.projects);
})
.catch(err => setError(err));
}, []);

return (
<main style={mainStyles}>
<Image style={imageStyles} src={BPLogo} alt="Blueprint Logo" />
<p>Open up app/page.tsx to get started!</p>
<p>
<b>Projects:</b>
</p>
{projects ? (
projects?.map(project => {
return <div key={project.id}>{project.project_name}</div>;
})
) : (
<div>Loading...</div>
)}
{error ? <div style={errorStyles}>{error}</div> : null}
</main>
);
}

// CSS styles

const mainStyles: CSSProperties = {
width: '100%',
height: '100vh',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
};

const imageStyles: CSSProperties = {
width: '80px',
height: '80px',
marginBottom: '0.5rem',
};

const errorStyles: CSSProperties = {
color: '#D22B2B',
};
7 changes: 6 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
compiler: {
// Enables the styled-components SWC transform
styledComponents: true,
},
};

export default nextConfig;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"pre-commit": "(pnpm run tsc || true) && (pnpm run lint || true) && pnpm run prettier"
},
"dependencies": {
"next": "^14.2.10",
"@supabase/supabase-js": "^2.45.4",
"dotenv": "^16.4.5",
"next": "^14.2.13",
"react": "^18",
"react-dom": "^18",
"styled-components": "^6.1.13"
Expand Down
Loading