Skip to content

Commit

Permalink
Double quotes less disruptive
Browse files Browse the repository at this point in the history
jamesdaniels committed Sep 10, 2024
1 parent 27171b6 commit 3cc2f61
Showing 31 changed files with 465 additions and 463 deletions.
5 changes: 1 addition & 4 deletions nextjs-end/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"trailingComma": "all",
"semi": true,
"tabWidth": 2,
"singleQuote": true,
"jsxSingleQuote": true,
"plugins": []
"tabWidth": 2
}
34 changes: 17 additions & 17 deletions nextjs-end/auth-service-worker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { initializeApp } from 'firebase/app';
import { getAuth, getIdToken, onAuthStateChanged } from 'firebase/auth';
import { initializeApp } from "firebase/app";
import { getAuth, getIdToken, onAuthStateChanged } from "firebase/auth";

// extract firebase config from query string
const serializedFirebaseConfig = new URLSearchParams(self.location.search).get(
'firebaseConfig',
"firebaseConfig",
);
if (!serializedFirebaseConfig) {
throw new Error(
'Firebase Config object not found in service worker query string.',
"Firebase Config object not found in service worker query string.",
);
}

@@ -16,50 +16,50 @@ const firebaseConfig = JSON.parse(serializedFirebaseConfig);
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

self.addEventListener('install', () => {
console.log('Service worker installed with Firebase config', firebaseConfig);
self.addEventListener("install", () => {
console.log("Service worker installed with Firebase config", firebaseConfig);
self.skipWaiting();
});

self.addEventListener('activate', (event) => {
self.addEventListener("activate", (event) => {
event.waitUntil(self.clients.claim());
});

self.addEventListener('fetch', (event) => {
self.addEventListener("fetch", (event) => {
const { origin, pathname } = new URL(event.request.url);
if (origin !== self.location.origin) return;
// Use a magic url to ensure that auth state is in sync between
// the client and the sw, this helps with actions such as router.refresh();
if (pathname.startsWith('/__/auth/wait/')) {
const uid = pathname.split('/').at(-1);
if (pathname.startsWith("/__/auth/wait/")) {
const uid = pathname.split("/").at(-1);
event.respondWith(waitForMatchingUid(uid));
return;
}
if (pathname.startsWith('/_next/')) return;
if (pathname.startsWith("/_next/")) return;
// Don't add headers to non-get requests or those with an extension—this
// helps with css, images, fonts, json, etc.
if (event.request.method === 'GET' && pathname.includes('.')) return;
if (event.request.method === "GET" && pathname.includes(".")) return;
event.respondWith(fetchWithFirebaseHeaders(event.request));
});

async function fetchWithFirebaseHeaders(request) {
const authIdToken = await getAuthIdToken();
if (authIdToken) {
const headers = new Headers(request.headers);
headers.append('Authorization', `Bearer ${authIdToken}`);
headers.append("Authorization", `Bearer ${authIdToken}`);
request = new Request(request, { headers });
}
return await fetch(request).catch((reason) => {
console.error(reason);
return new Response('Fail.', {
return new Response("Fail.", {
status: 500,
headers: { 'content-type': 'text/html' },
headers: { "content-type": "text/html" },
});
});
}

async function waitForMatchingUid(_uid) {
const uid = _uid === 'undefined' ? undefined : _uid;
const uid = _uid === "undefined" ? undefined : _uid;
await auth.authStateReady();
await new Promise((resolve) => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
@@ -71,7 +71,7 @@ async function waitForMatchingUid(_uid) {
});
return new Response(undefined, {
status: 200,
headers: { 'cache-control': 'no-store' },
headers: { "cache-control": "no-store" },
});
}

16 changes: 8 additions & 8 deletions nextjs-end/src/app/actions.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use server';
"use server";

import { addReviewToRestaurant } from '@/src/lib/firebase/firestore.js';
import { getAuthenticatedAppForUser } from '@/src/lib/firebase/serverApp.js';
import { getFirestore } from 'firebase/firestore';
import { addReviewToRestaurant } from "@/src/lib/firebase/firestore.js";
import { getAuthenticatedAppForUser } from "@/src/lib/firebase/serverApp.js";
import { getFirestore } from "firebase/firestore";

// This is a Server Action
// https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
export async function handleReviewFormSubmission(data) {
const { firebaseServerApp } = await getAuthenticatedAppForUser();
const db = getFirestore(firebaseServerApp);

await addReviewToRestaurant(db, data.get('restaurantId'), {
text: data.get('text'),
rating: data.get('rating'),
await addReviewToRestaurant(db, data.get("restaurantId"), {
text: data.get("text"),
rating: data.get("rating"),

// This came from a hidden form field
userId: data.get('userId'),
userId: data.get("userId"),
});
}
14 changes: 7 additions & 7 deletions nextjs-end/src/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import '@/src/app/styles.css';
import Header from '@/src/components/Header.jsx';
import { getAuthenticatedAppForUser } from '@/src/lib/firebase/serverApp';
import "@/src/app/styles.css";
import Header from "@/src/components/Header.jsx";
import { getAuthenticatedAppForUser } from "@/src/lib/firebase/serverApp";
// Force next.js to treat this route as server-side rendered
// Without this line, during the build process, next.js will treat this route as static and build a static HTML file for it
export const dynamic = 'force-dynamic';
export const dynamic = "force-dynamic";

export const metadata = {
title: 'FriendlyEats',
title: "FriendlyEats",
description:
'FriendlyEats is a restaurant review website built with Next.js and Firebase.',
"FriendlyEats is a restaurant review website built with Next.js and Firebase.",
};

export default async function RootLayout({ children }) {
const { currentUser } = await getAuthenticatedAppForUser();
return (
<html lang='en'>
<html lang="en">
<body>
<Header initialUser={currentUser?.toJSON()} />

12 changes: 6 additions & 6 deletions nextjs-end/src/app/page.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import RestaurantListings from '@/src/components/RestaurantListings.jsx';
import { getRestaurants } from '@/src/lib/firebase/firestore.js';
import { getAuthenticatedAppForUser } from '@/src/lib/firebase/serverApp.js';
import { getFirestore } from 'firebase/firestore';
import RestaurantListings from "@/src/components/RestaurantListings.jsx";
import { getRestaurants } from "@/src/lib/firebase/firestore.js";
import { getAuthenticatedAppForUser } from "@/src/lib/firebase/serverApp.js";
import { getFirestore } from "firebase/firestore";

// Force next.js to treat this route as server-side rendered
// Without this line, during the build process, next.js will treat this route as static and build a static HTML file for it

export const dynamic = 'force-dynamic';
export const dynamic = "force-dynamic";

// This line also forces this route to be server-side rendered
// export const revalidate = 0;
@@ -20,7 +20,7 @@ export default async function Home({ searchParams }) {
searchParams,
);
return (
<main className='main__home'>
<main className="main__home">
<RestaurantListings
initialRestaurants={restaurants}
searchParams={searchParams}
4 changes: 2 additions & 2 deletions nextjs-end/src/app/restaurant/[id]/error.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'; // Error components must be Client Components
"use client"; // Error components must be Client Components

import { useEffect } from 'react';
import { useEffect } from "react";

export default function Error({ error, reset }) {
useEffect(() => {
20 changes: 10 additions & 10 deletions nextjs-end/src/app/restaurant/[id]/page.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Restaurant from '@/src/components/Restaurant.jsx';
import { Suspense } from 'react';
import { getRestaurantById } from '@/src/lib/firebase/firestore.js';
import Restaurant from "@/src/components/Restaurant.jsx";
import { Suspense } from "react";
import { getRestaurantById } from "@/src/lib/firebase/firestore.js";
import {
getAuthenticatedAppForUser,
getAuthenticatedAppForUser as getUser,
} from '@/src/lib/firebase/serverApp.js';
} from "@/src/lib/firebase/serverApp.js";
import ReviewsList, {
ReviewsListSkeleton,
} from '@/src/components/Reviews/ReviewsList';
} from "@/src/components/Reviews/ReviewsList";
import {
GeminiSummary,
GeminiSummarySkeleton,
} from '@/src/components/Reviews/ReviewSummary';
import { getFirestore } from 'firebase/firestore';
} from "@/src/components/Reviews/ReviewSummary";
import { getFirestore } from "firebase/firestore";

export default async function Home({ params }) {
const { currentUser } = await getUser();
@@ -23,11 +23,11 @@ export default async function Home({ params }) {
);

return (
<main className='main__restaurant'>
<main className="main__restaurant">
<Restaurant
id={params.id}
initialRestaurant={restaurant}
initialUserId={currentUser?.uid || ''}
initialUserId={currentUser?.uid || ""}
>
<Suspense fallback={<GeminiSummarySkeleton />}>
<GeminiSummary restaurantId={params.id} />
@@ -36,7 +36,7 @@ export default async function Home({ params }) {
<Suspense
fallback={<ReviewsListSkeleton numReviews={restaurant.numRatings} />}
>
<ReviewsList restaurantId={params.id} userId={currentUser?.uid || ''} />
<ReviewsList restaurantId={params.id} userId={currentUser?.uid || ""} />
</Suspense>
</main>
);
14 changes: 7 additions & 7 deletions nextjs-end/src/app/styles.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,500;0,700;1,800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
@import url("https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,500;0,700;1,800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");

* {
box-sizing: border-box;
@@ -8,7 +8,7 @@

body {
font-family:
'Roboto',
"Roboto",
ui-sans-serif,
system-ui,
-apple-system;
@@ -289,9 +289,9 @@ a {
}

.restaurant__review_summary {
max-width: '50vw';
height: '75px';
padding-top: '10px';
max-width: "50vw";
height: "75px";
padding-top: "10px";
}

.img__section {
@@ -419,7 +419,7 @@ a {
}

.radio-label:before {
content: '★';
content: "★";
display: inline-block;
font-size: 32px;
}
@@ -454,7 +454,7 @@ a {

.average-rating::before {
--percent: calc(4.3 / 5 * 100%);
content: '★★★★★';
content: "★★★★★";
position: absolute;
top: 0;
left: 0;
Loading

0 comments on commit 3cc2f61

Please sign in to comment.