spaceshiptrip / saratorres-portfolio

0 stars 0 forks source link

Convert to a single page react site #1

Open spaceshiptrip opened 1 month ago

spaceshiptrip commented 1 month ago

You have a few options for converting your website into a single-page application (SPA), and whether to stick with React or switch to plain HTML/CSS depends on your goals and preferences. Let’s break down the choices:

Option 1: Keep Using React and Refactor to a Single Page

Option 2: Convert to Static HTML/CSS

Steps to Refactor the Current React App into a Single Page:

  1. Create a New Main Component (Main.js):
    • Combine the content from Home.js, Resume.js, and Papers.js into this new component.
// src/components/Main.js
import React, { useState } from 'react';

const Main = () => {
  const [section, setSection] = useState('home');

  return (
    <div>
      <header>
        <nav>
          <ul>
            <li><a href="#home" onClick={() => setSection('home')}>Home</a></li>
            <li><a href="#resume" onClick={() => setSection('resume')}>Resume</a></li>
            <li><a href="#papers" onClick={() => setSection('papers')}>Papers</a></li>
          </ul>
        </nav>
      </header>
      <main>
        {section === 'home' && (
          <div id="home">
            <h1>Welcome to My Environmental Biology Portfolio</h1>
            <p>Hello! I am a college student passionate about Environmental Biology...</p>
          </div>
        )}
        {section === 'resume' && (
          <div id="resume">
            <h1>My Resume</h1>
            <iframe src={`${process.env.PUBLIC_URL}/assets/resume.pdf`} width="100%" height="600px"></iframe>
            <p>Here is my professional resume...</p>
          </div>
        )}
        {section === 'papers' && (
          <div id="papers">
            <h1>My Research Papers</h1>
            <ul>
              <li><a href={`${process.env.PUBLIC_URL}/assets/paper1.pdf`} target="_blank">Paper 1</a></li>
              <li><a href={`${process.env.PUBLIC_URL}/assets/paper2.pdf`} target="_blank">Paper 2</a></li>
            </ul>
          </div>
        )}
      </main>
    </div>
  );
};

export default Main;
  1. Update App.js:
    • Replace the Routes with a single Main component, as routing is no longer necessary.
// src/App.js
import React from 'react';
import Main from './components/Main';
import './styles.css';

function App() {
  return (
    <div className="App">
      <Main />
    </div>
  );
}

export default App;
  1. Deploy the Refactored App:
    • After making these changes, deploy the app again using npm run deploy.

Conclusion:

If you foresee adding more features or interactivity in the future, keeping React and refactoring into a single-page app is a good move. If simplicity and speed are more important, then converting to static HTML/CSS might be the way to go.

To create a responsive and visually appealing single-page application using React, here’s a basic styles.css that you can use as a starting point. This CSS file will include styles for the layout, typography, and responsiveness.

styles.css

/* General Styles */
body {
  font-family: 'Arial', sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #333;
}

p {
  margin: 0 0 15px;
  color: #555;
}

ul {
  list-style-type: none;
  padding: 0;
}

a {
  color: #4CAF50;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout Styles */
.App {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header and Navigation */
header {
  background-color: #4CAF50;
  padding: 10px 0;
  color: white;
}

header nav ul {
  display: flex;
  justify-content: center;
  gap: 15px;
}

header nav ul li {
  margin: 0;
}

header nav ul li a {
  color: white;
  font-weight: bold;
}

header nav ul li a:hover {
  text-decoration: underline;
}

/* Main Content */
main {
  padding: 20px;
}

main div {
  margin-bottom: 40px;
}

/* Section Styling */
#home, #resume, #papers {
  padding: 20px;
  border-radius: 8px;
  background-color: #f9f9f9;
  box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
}

#resume iframe, #papers iframe {
  width: 100%;
  height: 600px;
  border: none;
}

/* Responsive Styles */
@media (max-width: 768px) {
  .App {
    padding: 10px;
  }

  header nav ul {
    flex-direction: column;
    align-items: center;
  }

  #resume iframe, #papers iframe {
    height: 400px;
  }
}

@media (max-width: 480px) {
  header nav ul {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  h1 {
    font-size: 1.5rem;
  }

  #resume iframe, #papers iframe {
    height: 300px;
  }
}

Explanation of the CSS:

  1. General Styles:

    • Basic styles for body, headings, paragraphs, and links.
    • Links have a color that matches the theme and change on hover.
  2. Layout Styles:

    • .App: Centers the content and adds padding around the main container.
  3. Header and Navigation:

    • The header has a background color and the navigation links are styled to match the theme.
    • Navigation links are centered and spaced out.
  4. Main Content:

    • Padding and margin settings for the main content and individual sections.
    • Each section (Home, Resume, Papers) has a distinct background color and slight shadow to differentiate them.
  5. Responsive Styles:

    • Adjustments are made for different screen sizes using media queries:
      • For tablets and small screens, padding is reduced and the layout is adjusted.
      • For mobile devices, the font sizes and iframe heights are reduced to fit the smaller screen.

Usage:

If you later decide to switch to plain HTML/CSS, you can easily transfer these styles with minor adjustments.

spaceshiptrip commented 1 month ago

Here’s an example of what your package.json file would look like for the React app we're working on, now refactored into a single-page application:

{
  "name": "saratorres-portfolio",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://spaceshiptrip.github.io/saratorres-portfolio",
  "dependencies": {
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-scripts": "5.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "gh-pages": "^4.0.0"
  }
}

Key Points:

  1. Name and Version:

    • "name": "saratorres-portfolio": This is the name of your project.
    • "version": "0.1.0": The version number of your project.
  2. Homepage:

    • "homepage": "https://spaceshiptrip.github.io/saratorres-portfolio": This specifies the URL where your app will be hosted on GitHub Pages. Make sure this matches your actual GitHub Pages URL.
  3. Dependencies:

    • The dependencies section includes react, react-dom, and react-scripts which are necessary for your React app.
    • If you removed react-router-dom because you're not using routing anymore, it wouldn't be listed here.
  4. Scripts:

    • "start": "react-scripts start": Runs the app in development mode.
    • "build": "react-scripts build": Builds the app for production.
    • "test": "react-scripts test": Runs tests.
    • "eject": "react-scripts eject": Ejects the app configuration (use with caution).
    • "predeploy": "npm run build" and "deploy": "gh-pages -d build": These are for deploying your app to GitHub Pages.
  5. ESLint Configuration:

    • "eslintConfig" specifies the linting rules for your app.
  6. Browserslist:

    • "browserslist" defines the browser versions that your app supports for production and development.
  7. DevDependencies:

    • "gh-pages": This package is necessary for deploying your app to GitHub Pages.

Next Steps:

  1. Install Dependencies:

    • Make sure to run npm install to install all the dependencies.
  2. Build and Deploy:

    • Once your app is ready, deploy it to GitHub Pages with:
      npm run deploy

This package.json is tailored for your React-based single-page portfolio site, making it easy to develop, build, and deploy.