Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptizism committed Aug 9, 2023
1 parent bdcdb7b commit ff73e20
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 483 deletions.
Binary file removed public/favicon.ico
Binary file not shown.
32 changes: 3 additions & 29 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,16 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="A dynamic tier list for on the fly quick and slick tier lists, no need to premake tierlists or use Photoshop! (This is mainly targeted to content creators)"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Dynamic Tier List</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
17 changes: 17 additions & 0 deletions public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

13 changes: 0 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
// src/App.tsx
import React, {useState} from 'react';
import './index.css';
import TierList from './components/TierList';
import ImageHolder from './components/ImageHolder';
import Modal from './components/Modal';

const App = () => {
const [modalOpen, setModalOpen] = useState(true);

const openModal = () => {
setModalOpen(true);
};

const closeModal = () => {
setModalOpen(false);
};

return (
<div className="p-8 min-h-[100vh] bg-stone-800">
<TierList />
Expand Down
184 changes: 94 additions & 90 deletions src/components/ImageHolder.tsx
Original file line number Diff line number Diff line change
@@ -1,106 +1,110 @@
import React, { useState, useEffect } from 'react';
import { ReactSortable } from 'react-sortablejs';
import { useState, useEffect } from "react";
import { ReactSortable } from "react-sortablejs";

interface ImageItem {
id: number;
url: string;
id: number;
url: string;
}

const ImageHolder = () => {
const [images, setImages] = useState<ImageItem[]>([]);
const [images, setImages] = useState<ImageItem[]>([]);

const handleDrop = (event: DragEvent) => {
event.preventDefault();
if (event.dataTransfer == null) return;
if (
event.dataTransfer.getData('application/x-tier') !== "true"
) {
if (event.dataTransfer.files.length > 0){
const files = Array.from(event.dataTransfer.files)
files.forEach(file => {
if (!file.type.startsWith('image/')) return
const reader = new FileReader();
reader.onload = function(event) {
if(event.target == null) return
const imageData = event.target.result;
setImages(prevImages => [
...prevImages,
{ id: new Date().getTime() + Math.floor(Math.random() * 1000), url: imageData as string},
]);
}
reader.readAsDataURL(file);
});
}
}
};
const handleDrop = (event: DragEvent) => {
event.preventDefault();
if (event.dataTransfer == null) return;
if (event.dataTransfer.getData("application/x-tier") !== "true") {
if (event.dataTransfer.files.length > 0) {
const files = Array.from(event.dataTransfer.files);
files.forEach((file) => {
if (!file.type.startsWith("image/")) return;
const reader = new FileReader();
reader.onload = function (event) {
if (event.target == null) return;
const imageData = event.target.result;
setImages((prevImages) => [
...prevImages,
{
id: new Date().getTime() + Math.floor(Math.random() * 1000),
url: imageData as string
}
]);
};
reader.readAsDataURL(file);
});
}
}
};

const dragStart = (event: DragEvent) =>{
if(event.dataTransfer == null) return
event.dataTransfer.setData('application/x-tier', 'true');
}
const dragStart = (event: DragEvent) => {
if (event.dataTransfer == null) return;
event.dataTransfer.setData("application/x-tier", "true");
};

useEffect(() => {
const handlePaste = (event: ClipboardEvent) => {
const items = event.clipboardData?.items;
if (items) {
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type.indexOf('image') !== -1) {
const blob = item.getAsFile();
if (blob) {
const imageUrl = URL.createObjectURL(blob);
setImages(prevImages => [
...prevImages,
{ id: new Date().getTime(), url: imageUrl },
]);
}
}
}
}
};
useEffect(() => {
const handlePaste = (event: ClipboardEvent) => {
const items = event.clipboardData?.items;
if (items) {
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type.indexOf("image") !== -1) {
const blob = item.getAsFile();
if (blob) {
const imageUrl = URL.createObjectURL(blob);
setImages((prevImages) => [
...prevImages,
{ id: new Date().getTime(), url: imageUrl }
]);
}
}
}
}
};

// Attach paste event listener
document.addEventListener('paste', handlePaste);
document.addEventListener("paste", handlePaste);

const dragOver = (event: DragEvent) => {
event.preventDefault();
};
const dragOver = (event: DragEvent) => {
event.preventDefault();
};

const drop = (event: DragEvent) => {
event.preventDefault();
handleDrop(event);
};
const drop = (event: DragEvent) => {
event.preventDefault();
handleDrop(event);
};

// Attach global dragover and drop event listeners
document.addEventListener('dragstart', dragStart);
document.addEventListener('dragover', dragOver);
document.addEventListener('drop', drop);
document.addEventListener("dragstart", dragStart);
document.addEventListener("dragover", dragOver);
document.addEventListener("drop", drop);

return () => {
document.removeEventListener("paste", handlePaste);
document.removeEventListener("dragover", dragOver);
document.removeEventListener("drop", drop);
};
}, []);

// Clean up the event listeners on unmount
return () => {
document.removeEventListener('paste', handlePaste);
document.removeEventListener('dragover', dragOver);
document.removeEventListener('drop', drop);
};
}, []);

return (
<ReactSortable
list={images}
setList={setImages}
tag="div"
group="shared"
className="react-sortablejs flex space-x-4 p-4 bg-stone-700 min-h-[7rem] flex-wrap mt-8"
filter=".ignore-elements"
>
{images.length === 0 ? (
<p className='text-gray-400 text-center w-full ignore-elements'>Drag & Drop or Copy and Paste images in here!<br/>If this is your first time using this you can right click tiers to edit them and drag them about, clicking the plus will add more tiers</p>
) :
images.map((image) => (
<img src={image.url} key={image.id} className="h-20 w-auto" />
))}
</ReactSortable>
);
return (
<ReactSortable
list={images}
setList={setImages}
tag="div"
group="shared"
className="react-sortablejs flex space-x-4 p-4 bg-stone-700 min-h-[7rem] flex-wrap mt-8"
filter=".ignore-elements"
>
{images.length === 0 ? (
<p className="text-gray-400 text-center w-full ignore-elements">
Drag & Drop or Copy and Paste images in here!
<br />
If this is your first time using this you can right click tiers to
edit them and drag them about, clicking the plus will add more tiers
</p>
) : (
images.map((image) => (
<img src={image.url} key={image.id} className="h-20 w-auto" />
))
)}
</ReactSortable>
);
};

export default ImageHolder;
Loading

0 comments on commit ff73e20

Please sign in to comment.