Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptizism committed Jun 6, 2024
2 parents b4ebd5a + 608606a commit 73728a0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
58 changes: 20 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,28 @@
# Getting Started with Create React App
# Dynamic Tier List

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Example
![POWCowXiMR](https://github.com/Cryptizism/dynamic-tier-list/assets/60571306/529dc106-42d5-4a6e-8a65-74cc63cf63e8)

## Available Scripts
## Running
1. git clone the project
2. run `npm i`
3. run `npm start`

In the project directory, you can run:
## Features
- Changing aspect ratio
- Persistent over refreshes
- On the fly drag n drop
- On the fly copy and paste
- Multiple image pasting

### `npm start`
## Purpose
Mainly meant for streamers doing tier list streams this is meant to be a quick way to create a tier list on the go dragging them in as you need with minimal UI.

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
This is meant to be run on a PC and will run on certain mobiles but it is not intended for this use case and will be hard or impossible to use

The page will reload if you make edits.\
You will also see any lint errors in the console.
This project runs on GH Pages for free and has a CI for deployments on each push.

### `npm test`
## FAQ
Q: Can I share the images and tiers

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
A: No, this is all saved and ran on ur PC
32 changes: 27 additions & 5 deletions src/components/ImageHolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,44 @@ const ImageHolder = () => {
setIsModalOpen(false);
};

const compressAndDownscaleImage = (base64: string, maxHeight: number, quality: number): Promise<string> => {
return new Promise((resolve) => {
const img = document.createElement("img");
img.src = base64;
img.onload = function () {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
const maxHeight = 5 * parseFloat(getComputedStyle(document.documentElement).fontSize);
const scale = maxHeight / img.height;
canvas.width = img.width * scale;
canvas.height = maxHeight;
ctx?.drawImage(img, 0, 0, canvas.width, canvas.height);
const compressedImageData = canvas.toDataURL("image/jpeg", quality);
resolve(compressedImageData);
};
});
};

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);
let count = 0;
files.forEach((file) => {
count++;
if (!file.type.startsWith("image/")) return;
const reader = new FileReader();
reader.onload = function (event) {
reader.onload = async function (event) {
if (event.target == null) return;
const imageData = event.target.result;
const compressedImageData = await compressAndDownscaleImage(imageData as string, 80, 1);
setImages((prevImages) => [
...prevImages,
{
id: new Date().getTime() + Math.floor(Math.random() * 1000),
url: imageData as string
id: new Date().getTime() + count,
url: compressedImageData as string
}
]);
};
Expand All @@ -65,11 +86,12 @@ const ImageHolder = () => {
const blob = item.getAsFile();
let reader = new FileReader();
reader.readAsDataURL(blob || new Blob());
reader.onloadend = function() {
reader.onloadend = async function() {
let base64data : any = reader.result;
const compressedImageData = await compressAndDownscaleImage(base64data as string, 80, 1);
setImages((prevImages) => [
...prevImages,
{ id: new Date().getTime(), url: base64data }
{ id: new Date().getTime() + i, url: compressedImageData }
]);
}
}
Expand Down

0 comments on commit 73728a0

Please sign in to comment.