Skip to content

Commit

Permalink
Having image issues with NextJS images
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanobaz committed Jun 7, 2023
1 parent 1c89a77 commit e9ef970
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
@media (prefers-color-scheme: light) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
Expand Down
47 changes: 44 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';
import React from 'react';
import Head from 'next/head';
import { Quicksand } from 'next/font/google';
import Image from 'next/image';
import ImageComponent from '@/components/ImageComponent';
import headshot from '../public/finalheadshotedit.png';
import styles from '../styles/Main.module.css';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand All @@ -11,6 +11,9 @@ import {
faLinkedinIn,
faTwitter,
} from '@fortawesome/free-brands-svg-icons';
import Project from '@/components/Project';
import books from '../public/books.png';
import books2 from '../public/books.jpeg';

export default function Home() {
const today = new Date();
Expand Down Expand Up @@ -68,9 +71,47 @@ export default function Home() {
</ul>
</main>
</div>
<h3 className="mt-10 mb-5 flex justify-center text-xl font-semibold">
Projects
</h3>
<div className="flex justify-center">
<Project
projectId={1}
projectTitle="Books & More"
purpose="Website that keeps track of your books"
techUsed="Python (Flask) on the backend.
HTML, CSS, JavaScript on the frontend. Jinja as Flask's templating
language. Bootstrap as the CSS framework for styling. Heroku for
hosting."
imageComponent={
<ImageComponent
src={books}
alt="headshot"
className={styles['card-image']}
width={100}
height={100}
/>
}
/>
<Project
projectId={2}
projectTitle="Portfolio Page"
purpose="Website to showcase my projects and skills in tech"
techUsed="React (NextJS). Deployed on Vercel."
imageComponent={
<ImageComponent
src={books2}
alt="headshot"
className={styles['card-image']}
width={100}
height={100}
/>
}
/>
</div>
<footer className="my-10">
<div className="w-100 flex justify-center">
<hr className="h-0.5 my-8 bg-blue-200 w-1/2 rounded" />
<hr className="h-0.5 my-7 bg-blue-200 w-1/2 rounded" />
</div>
<ul className="flex justify-center" id="social">
<li className={styles.socialLink}>
Expand All @@ -90,7 +131,7 @@ export default function Home() {
</a>
</li>
</ul>
<p className="flex justify-center mt-5">
<p className="flex justify-center mt-7">
&copy; {year} Urbano Baz. All rights reserved.
</p>
</footer>
Expand Down
15 changes: 15 additions & 0 deletions components/ImageComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

const ImageComponent = ({ src, ...props }) => {
try {
return React.createElement(require.resolve('next/image').default, {
src: typeof src === 'string' ? src : src.src,
...props,
});
} catch {
console.log('Not using Next.js');
return React.createElement('img', { src, ...props });
}
};

export default ImageComponent;
39 changes: 39 additions & 0 deletions components/Project.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';

import React from 'react';
import styles from '../styles/Main.module.css';

type projectProps = {
projectId: number;
projectTitle: string;
purpose: string;
techUsed: string;
imageComponent: any;
};

export default function Project({
projectId,
projectTitle,
purpose,
techUsed,
imageComponent,
}: projectProps) {
return (
<div className={styles.card}>
{imageComponent}
<div className={styles.container}>
<h2>
<b>
Project {projectId}: {projectTitle}
</b>
</h2>
<p>
<strong>Info:</strong> {purpose}
</p>
<p>
<strong>Technologies used:</strong> {techUsed}
</p>
</div>
</div>
);
}
Binary file added public/books.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/books.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 4 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -24,18 +20,9 @@
}
],
"paths": {
"@/*": [
"./*"
]
"@/*": ["./*"]
}
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
]
"exclude": ["node_modules"],
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"]
}

2 comments on commit e9ef970

@vercel
Copy link

@vercel vercel bot commented on e9ef970 Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e9ef970 Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.