Skip to content

Commit

Permalink
[feat] testing page for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
deenasun committed Oct 5, 2024
1 parent ec87a5a commit be0b532
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import { CSSProperties, useEffect } from 'react';
import Image from 'next/image';
import BPLogo from '@/assets/images/bp-logo.png';
import queryProjects from './queries/query';
import queryProjects from '../queries/query';

// TODO: build some sort of testing page
export default function Home() {
useEffect(() => {
queryProjects();
Expand Down
78 changes: 78 additions & 0 deletions src/app/testing/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use client';

import { CSSProperties, useEffect, useState } from 'react';
import Image from 'next/image';
import BPLogo from '@/assets/images/bp-logo.png';
import queryProjects from '../../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;
}

// TODO: build some sort of testing page
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',
};
8 changes: 3 additions & 5 deletions src/app/queries/query.ts → src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string;
const supabase = createClient(supabaseUrl, supabaseKey);

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

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

return { Projects, error };
return { projects, error };
}

0 comments on commit be0b532

Please sign in to comment.