Skip to content

Commit

Permalink
supabaseからhospitalsを取得
Browse files Browse the repository at this point in the history
  • Loading branch information
naoya7076 committed Mar 18, 2024
1 parent 11d21fc commit e2039b8
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions app/routes/hospitals.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import { Hospital } from "@/components/hospital";
const Hospitals = () => {
const hospitals = [
{
id: 1,
name: "医療法人つとむ会 澤田内科医院",
postal_code: "530-0001",
address: "大阪府大阪市北区梅田1―2―2―200",
},
import { json } from "@remix-run/cloudflare";
import { createServerClient } from "@supabase/auth-helpers-remix";
import type { LoaderFunctionArgs } from "@remix-run/cloudflare";
import { useLoaderData } from "@remix-run/react";
export const loader = async ({ request }: LoaderFunctionArgs) => {
const response = new Response();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error("Supabase URL or Supabase Anon Key is missing.");
}
const supabaseClient = createServerClient(supabaseUrl, supabaseAnonKey, {
request,
response,
});

const { data } = await supabaseClient.from("hospitals").select("*");
return json(
{ hospitals: data },
{
id: 2,
name: "医療法人渡辺医学会桜橋渡辺病院",
postal_code: "530-0001",
address: "大阪府大阪市北区梅田2―4―32",
headers: response.headers,
},
];
);
};
const Hospitals = () => {
const { hospitals } = useLoaderData<typeof loader>();
return (
<>
{hospitals.map((hospital) => (
{hospitals?.map((hospital) => (
<Hospital
key={hospital.id}
name={hospital.name}
Expand Down

0 comments on commit e2039b8

Please sign in to comment.