From 3365d3b38b2afc11fd5344e85dfa4baaaa5d9ad7 Mon Sep 17 00:00:00 2001 From: Lloyd Richards Date: Fri, 26 Jun 2020 16:40:30 +0200 Subject: [PATCH] feat: Add Notification Animation --- components/utils/array-utils.tsx | 14 ++++ pages/experiment/013.tsx | 15 ++++ pages/experiment/015.tsx | 117 +++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 components/utils/array-utils.tsx create mode 100644 pages/experiment/015.tsx diff --git a/components/utils/array-utils.tsx b/components/utils/array-utils.tsx new file mode 100644 index 0000000..f7aa2e7 --- /dev/null +++ b/components/utils/array-utils.tsx @@ -0,0 +1,14 @@ +export const remove = (arr: string[], item: number) => { + const newArr = [...arr]; + newArr.splice( + newArr.findIndex((i) => i === item), + 1 + ); + return newArr; +}; + +let newIndex = 0; +export const add = (arr: string[]) => { + newIndex++; + return [...arr, newIndex]; +}; diff --git a/pages/experiment/013.tsx b/pages/experiment/013.tsx index e77a09e..517dd82 100644 --- a/pages/experiment/013.tsx +++ b/pages/experiment/013.tsx @@ -86,6 +86,21 @@ const Experiment013: React.FC = () => { const [tutorial, setTutorial] = React.useState(true); const [mode, setMode] = React.useState(true); + //lifeofplastic/code?='PETBin','PETGrinder' + + //['petBin', 'PETGrinder'] + + const buildInitialSystems = ( + sysytemObject: SystemList, + queryCode: Array + ): SystemList => { + // Array is only Systems + + //Turn array + const overwrites = {}; + return { ...sysytemObject, ...overwrites }; + }; + React.useEffect(() => { console.log(garbagePile); if (garbagePile >= 2) { diff --git a/pages/experiment/015.tsx b/pages/experiment/015.tsx new file mode 100644 index 0000000..560f2e1 --- /dev/null +++ b/pages/experiment/015.tsx @@ -0,0 +1,117 @@ +import Layout from "../../components/Layout"; +import React from "react"; +import { motion, AnimatePresence } from "framer-motion"; +import { nanoid } from "nanoid"; + +interface TaskProps { + task: string; + id: string; +} + +const Experiment014 = () => { + const [formData, updateFormData] = React.useState(""); + const [tasks, updateTasks] = React.useState>([]); + + React.useEffect(() => { + if (tasks.length > 4) { + console.log("OVER"); + updateTasks([...tasks.slice(1)]); + } + }, [tasks]); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + + if (formData) { + const newArr = { task: formData, id: nanoid() }; + updateTasks([...tasks, newArr]); + console.log(tasks); + updateFormData(""); + } + }; + + const handleChange = (e: React.ChangeEvent) => { + updateFormData(e.target.value); + }; + + return ( + +

015 - Animated Notifications

+

Date: June 26th 2020

+

+ One of the missing features of Life of Plastic was a notification system + that created a log of evertime a piece of plastic went through a system. + I wanted to be able to show all the different processes and keep track + of how plastic moved. In the code there were many times that I could + have added a addNotification() that would build a string of + the evernt and save it to the state. Then based on this array of string + I could use Framer Motion to add and remove notifications through an + animating feed. This will be my attempt to create this: +

+

Steps to take:

+
    +
  1. Add a State and buttons to ADD and REMOVE items
  2. +
  3. Render the state in a stylized component
  4. +
  5. Automatically remove the last item when list is too long
  6. +
  7. Animate the rendering so it ticks items in
  8. +
  9. + Limit the visible size of the list so it can be scrolled up to find + logs +
  10. +
+
+ + + +
+
+
    + + {tasks?.map((task) => ( + +

    {task.task}

    +
    + ))} +
    +
+
+

+ Took a little longer than I expected but I got everything in place. Can + now export this as a styalized component that will take in the array of + notifications. +

+
+ ); +}; + +export default Experiment014;