MVP with just an ordering, but no quantitative estimates

This commit is contained in:
NunoSempere 2021-06-06 23:14:05 +02:00
commit 9cae559df3
11 changed files with 6576 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# Next.js + Tailwind CSS Example
This example shows how to use [Tailwind CSS](https://tailwindcss.com/) (v2.1) with Next.js. It follows the steps outlined in the official [Tailwind docs](https://tailwindcss.com/docs/guides/nextjs).
It uses the new [`Just-in-Time Mode`](https://tailwindcss.com/docs/just-in-time-mode) for Tailwind CSS.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss&project-name=with-tailwindcss&repository-name=with-tailwindcss)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-tailwindcss with-tailwindcss-app
# or
yarn create next-app --example with-tailwindcss with-tailwindcss-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

6317
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "with-tailwindcss",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"autoprefixer": "^10.0.4",
"postcss": "^8.1.10",
"tailwindcss": "^2.1.1"
}
}

7
pages/_app.js Normal file
View File

@ -0,0 +1,7 @@
import 'tailwindcss/tailwind.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp

5
pages/api/hello.js Normal file
View File

@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function helloAPI(req, res) {
res.status(200).json({ name: 'John Doe' })
}

146
pages/index.js Normal file
View File

@ -0,0 +1,146 @@
import Head from 'next/head'
import React, { useState } from "react";
// Utilities
Array.prototype.containsArray = function(val) {
var hash = {};
for(var i=0; i<this.length; i++) {
hash[this[i]] = i;
}
return hash.hasOwnProperty(val);
}
let checkIfListIsOrdered = (arr, comparisons) => {
let l = arr.length
let isOrdered = true
for(let i=0; i<l-1; i++){
isOrdered = isOrdered && comparisons.containsArray([arr[i], arr[i+1]])
}
return isOrdered
}
// Main
export default function Home() {
// State
let list = [1,2,3,4,5,6,7,8,9,10]
let initialComparisonPair = [9,10]
const [toComparePair, setToComparePair] = useState(initialComparisonPair)
const [comparisons, updateComparisons] = useState([])
const [isListOrdered, setIsListOrdered] = useState(false)
const [orderedList, setOrderedList] = useState(null)
// Manipulations
let compareTwoElements = (newComparisons, element1, element2) => {
let element1Greater = newComparisons.containsArray([element1, element2])
let element2Greater = newComparisons.containsArray([element2, element1])
if(element1Greater || element2Greater){
return element1Greater && !element2Greater
} else{
setToComparePair([element1, element2])
console.log(`No comparison found between ${element1} and ${element2}`)
console.log(`Comparisons:`)
console.log(JSON.stringify(newComparisons, null, 4));
return "No comparison found"
}
}
function merge(newComparisons, left, right) {
let sortedArr = []; // the sorted elements will go here
while (left.length && right.length) {
// insert the biggest element to the sortedArr
let comparison = compareTwoElements(newComparisons, left[0], right[0])
if(comparison == "No comparison found"){
return "No comparison found; unable to proceed"
}
else if (comparison) { // left[0] > right[0]
sortedArr.push(left.shift());
} else {
sortedArr.push(right.shift());
}
}
// use spread operator and create a new array, combining the three arrays
return [...sortedArr, ...left, ...right]; // if they don't have the same size, the remaining ones will be greater than the ones before
}
function mergeSort(arr, newComparisons) {
if(arr == "No comparison found; unable to proceed"){
return "No comparison found; unable to proceed"
}
const half = arr.length / 2;
// the base case is array length <=1
if (arr.length <= 1) {
return arr;
}
const left = arr.splice(0, half); // the first half of the array
const right = arr;
let orderedFirstHalf = mergeSort(left, newComparisons)
let orderedSecondHalf = mergeSort(right, newComparisons)
if(orderedFirstHalf != "No comparison found; unable to proceed" && orderedSecondHalf != "No comparison found; unable to proceed"){
let result = merge(newComparisons, orderedFirstHalf, orderedSecondHalf);
return result
}else{
return "No comparison found; unable to proceed"
}
}
let nextStep = (comparisons, element1, element2) => {
console.log("Comparisons: ")
console.log(JSON.stringify(comparisons, null, 4));
let newComparison = [element1, element2] // [element1, element2]
let newComparisons = [...comparisons, newComparison]
console.log("New comparisons: ")
console.log(JSON.stringify(newComparisons, null, 4));
updateComparisons(newComparisons)
let result = mergeSort(list, newComparisons)
console.log(result)
console.log(toComparePair)
if(result != "No comparison found; unable to proceed" && checkIfListIsOrdered(result, newComparisons)){
alert("Order complete")
console.log(result)
setIsListOrdered(true)
setOrderedList(result)
}
}
// Html
return (
<div className="flex flex-col items-center justify-center min-h-screen py-2">
<Head>
<title>Welcome to Hot Or Not</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="flex flex-col items-center justify-center w-full flex-1 px-20 text-center">
<h1 className="text-6xl font-bold">
Hot or not?
</h1>
<div className={`flex flex-wrap items-center max-w-4xl mt-6 sm:w-full mt-20 ${isListOrdered? "hidden" : ""}`}>
<button
className="flex m-auto border-gray-300 border-4 h-64 w-64"
onClick={() => nextStep(comparisons, toComparePair[0], toComparePair[1])}
>
<p className="block m-auto text-center">{toComparePair[0]}</p>
</button>
<button
className="flex m-auto border-gray-300 border-4 h-64 w-64"
onClick={() => nextStep(comparisons, toComparePair[1], toComparePair[0])}
>
<p className="block m-auto text-center">{toComparePair[1]}</p>
</button>
</div>
<div className={`mt-10 ${isListOrdered? "": "hidden" }`}>
<p>{`Ordered list: ${JSON.stringify(orderedList, null, 4)}`}</p>
<p>{`Comparisons: ${JSON.stringify(comparisons, null, 4)}`}</p>
</div>
</main>
</div>
)
}

8
postcss.config.js Normal file
View File

@ -0,0 +1,8 @@
// If you want to use other PostCSS plugins, see the following:
// https://tailwindcss.com/docs/using-with-preprocessors
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

4
public/vercel.svg Normal file
View File

@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

12
tailwind.config.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
mode: 'jit',
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}