Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Drag and Drop for logos #21

Merged
merged 10 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,406 changes: 1,924 additions & 482 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"@testing-library/user-event": "^13.2.1",
"eslint": "^8.40.0",
"eslint-plugin-react": "^7.32.2",
"react": "^18.3.1",

"husky": "^9.1.6",
"react": "^18.2.0",

"react-dom": "^18.2.0",
"react-dropzone": "^14.2.6",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.0"
},
Expand Down Expand Up @@ -43,11 +47,6 @@
},
"devDependencies": {
"eslint-config-prettier": "^8.8.0",
"prettier": "2.8.8",
"husky": "^8.0.0",
"lint-staged": "^13.0.0"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
"prettier": "2.8.8"
}
}
16 changes: 8 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState } from "react";
import "./App.css";
import AddSkillForm from "./components/skills/AddSkillForm";
import SkillView from "./components/skills/SkillView";
import SkillEditPage from "./components/skills/SkillEditPage";
import User from "./components/User/page";
import EducationEditPage from "./components/education/EducationEditPage";
import EducationForm from "./components/education/EducationForm";
import EducationView from "./components/education/EducationView";
import EducationEditPage from "./components/education/EducationEditPage";
import ExperienceForm from "./components/experience/ExperienceForm";
import ViewExperience from "./components/experience/ViewExperience";
import User from "./components/User/page";

import AddSkillForm from "./components/skills/AddSkillForm";
import SkillEditPage from "./components/skills/SkillEditPage";
import SkillView from "./components/skills/SkillView";


function App() {
const [showEducationForm, setShowEducationForm] = useState(false);
Expand Down Expand Up @@ -141,4 +141,4 @@ function App() {
);
};

export default App;
export default App;
1 change: 1 addition & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,4 @@ describe("ExperienceForm", () => {
expect(mockSubmit).not.toHaveBeenCalled();
});
});

42 changes: 42 additions & 0 deletions src/components/Dropzone.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useCallback, useState } from "react";
import { useDropzone } from "react-dropzone";

const Dropzone = () => {
const [files, setFiles] = useState([]);
const [rejected, setRejected] = useState([]);
const onDrop = useCallback((acceptedFiles, rejectedFiles) => {
if (acceptedFiles?.length) {
setFiles((previousFiles) => [
...previousFiles,
...acceptedFiles.map((file) =>
Object.assign(file, { preview: URL.createObjectURL(file) })
),
]);
}

if (rejectedFiles?.length) {
setRejected((previousFiles) => [...previousFiles, ...rejectedFiles]);
}
}, []);
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

return (
<form>
<div {...getRootProps()}>
<input {...getInputProps()} />
{isDragActive ? (
<p>Drop the files here ...</p>
) : (
<p>Drag 'n' drop some files here, or click to select files</p>
)}
</div>
{/* Preview */}
<ul>
{files.map((file) => (
<li key={file.name}>{file.name}</li>
))}
</ul>
</form>
);
};
export default Dropzone;
11 changes: 4 additions & 7 deletions src/components/education/EducationForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from "react";
import Dropzone from "../Dropzone";

const EducationForm = () => {
const [formData, setFormData] = useState({
Expand Down Expand Up @@ -93,13 +94,9 @@ const EducationForm = () => {
%
</label>
<label>
<h2>Logo URL</h2>
<input
type="text"
value={formData.logo}
placeholder="Logo URL"
onChange={handleChange("logo")}
/>
<h2>Logo</h2>
<Dropzone/>

</label>

<button onSubmit={handleSubmit}>Submit Education</button>
Expand Down
13 changes: 4 additions & 9 deletions src/components/skills/SkillEditPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import React, { useEffect, useState } from "react";
import Dropzone from "../Dropzone";
import "./SkillEditPage.css";

function SkillEditPage() {
Expand Down Expand Up @@ -135,14 +136,8 @@ function SkillEditPage() {
/>
</div>
<div className="form-field">
<label htmlFor="logo">Logo URL:</label>
<input
id="logo"
name="logo"
value={formData.logo}
onChange={handleInputChange}
required
/>
<label htmlFor="logo">Logo:</label>
<Dropzone/>
</div>
<button
type="submit"
Expand Down
Loading
Loading