chore: refactor components

This commit is contained in:
swve 2023-04-08 15:54:02 +02:00
parent ca5110e4f7
commit d6289edb29
21 changed files with 13 additions and 165 deletions

View file

@ -5,10 +5,10 @@ import React, { useMemo } from "react";
import Layout from "@components/UI/Layout"; import Layout from "@components/UI/Layout";
import { getActivity } from "@services/courses/activities"; import { getActivity } from "@services/courses/activities";
import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config/config"; import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config/config";
import Canva from "@components/ActivityViews/DynamicCanva/DynamicCanva"; import Canva from "@components/Pages/Activities/DynamicCanva/DynamicCanva";
import styled from "styled-components"; import styled from "styled-components";
import { getCourse } from "@services/courses/courses"; import { getCourse } from "@services/courses/courses";
import VideoActivity from "@components/ActivityViews/Video/Video"; import VideoActivity from "@components/Pages/Activities/Video/Video";
import useSWR, { mutate } from "swr"; import useSWR, { mutate } from "swr";
import { Check } from "lucide-react"; import { Check } from "lucide-react";
import { swrFetcher } from "@services/utils/requests"; import { swrFetcher } from "@services/utils/requests";

View file

@ -2,23 +2,19 @@
import React from "react"; import React from "react";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { Header } from "@components/UI/Header";
import Layout from "@components/UI/Layout";
import { Title } from "@components/UI/Elements/Styles/Title"; import { Title } from "@components/UI/Elements/Styles/Title";
import { DragDropContext, Droppable } from "react-beautiful-dnd"; import { DragDropContext, Droppable } from "react-beautiful-dnd";
import { initialData, initialData2 } from "@components/Drags/data"; import { initialData, initialData2 } from "@components/Pages/CourseEdit/Draggables/data";
import Chapter from "@components/Drags/Chapter"; import Chapter from "@components/Pages/CourseEdit/Draggables/Chapter";
import { createChapter, deleteChapter, getCourseChaptersMetadata, updateChaptersMetadata } from "@services/courses/chapters"; import { createChapter, deleteChapter, getCourseChaptersMetadata, updateChaptersMetadata } from "@services/courses/chapters";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import NewChapterModal from "@components/Modals/CourseEdit/NewChapter"; import NewChapterModal from "@components/Pages/CourseEdit/NewChapter";
import NewActivityModal from "@components/Modals/CourseEdit/NewActivity"; import NewActivityModal from "@components/Pages/CourseEdit/NewActivity";
import { createActivity, createFileActivity } from "@services/courses/activities"; import { createActivity, createFileActivity } from "@services/courses/activities";
import { getOrganizationContextInfo } from "@services/organizations/orgs"; import { getOrganizationContextInfo } from "@services/organizations/orgs";
import Modal from "@components/UI/Modal/Modal"; import Modal from "@components/UI/Modal/Modal";
function CourseEdit(params: any) { function CourseEdit(params: any) {
const router = useRouter();
// Initial Course State // Initial Course State
const [data, setData] = useState(initialData2) as any; const [data, setData] = useState(initialData2) as any;
@ -33,8 +29,6 @@ function CourseEdit(params: any) {
const courseid = params.params.courseid; const courseid = params.params.courseid;
const orgslug = params.params.orgslug; const orgslug = params.params.orgslug;
async function getCourseChapters() { async function getCourseChapters() {
const courseChapters = await getCourseChaptersMetadata(courseid); const courseChapters = await getCourseChaptersMetadata(courseid);
setData(courseChapters); setData(courseChapters);
@ -107,9 +101,7 @@ function CourseEdit(params: any) {
}; };
/* /*
Modals Modals
*/ */
const openNewActivityModal = async (chapterId: any) => { const openNewActivityModal = async (chapterId: any) => {

View file

@ -1,6 +1,6 @@
"use client"; "use client";
import "../styles/globals.css"; import "../styles/globals.css";
import StyledComponentsRegistry from "../components/lib/styled-registry"; import StyledComponentsRegistry from "../components/UI/libs/styled-registry";
import { motion } from "framer-motion"; import { motion } from "framer-motion";
export default function RootLayout({ children }: { children: React.ReactNode }) { export default function RootLayout({ children }: { children: React.ReactNode }) {

View file

@ -1,6 +1,5 @@
"use client"; "use client";
import React from "react"; import React from "react";
import Layout from "../../../components/UI/Layout";
import { Title } from "../../../components/UI/Elements/Styles/Title"; import { Title } from "../../../components/UI/Elements/Styles/Title";
import { createNewOrganization } from "../../../services/organizations/orgs"; import { createNewOrganization } from "../../../services/organizations/orgs";
@ -34,7 +33,7 @@ const Organizations = () => {
}; };
return ( return (
<Layout> <div>
<Title>New Organization</Title> <Title>New Organization</Title>
Name: <input onChange={handleNameChange} type="text" /> Name: <input onChange={handleNameChange} type="text" />
<br /> <br />
@ -45,7 +44,7 @@ const Organizations = () => {
Email Address: <input onChange={handleEmailChange} type="text" /> Email Address: <input onChange={handleEmailChange} type="text" />
<br /> <br />
<button onClick={handleSubmit}>Create</button> <button onClick={handleSubmit}>Create</button>
</Layout> </div>
); );
}; };

View file

@ -1,7 +1,5 @@
"use client"; "use client";
import React from "react"; import React from "react";
import { Header } from "../../components/UI/Header";
import Layout from "../../components/UI/Layout";
import { Title } from "../../components/UI/Elements/Styles/Title"; import { Title } from "../../components/UI/Elements/Styles/Title";
import { signup } from "../../services/auth/auth"; import { signup } from "../../services/auth/auth";
@ -31,8 +29,7 @@ const SignUp = () => {
return ( return (
<div> <div>
<Layout title="Sign up"> <div title="Sign up">
<Header></Header>
<Title>Sign up </Title> <Title>Sign up </Title>
<form> <form>
@ -43,7 +40,7 @@ const SignUp = () => {
Sign up Sign up
</button> </button>
</form> </form>
</Layout> </div>
</div> </div>
); );
}; };

View file

@ -1,54 +0,0 @@
import React from "react";
import styled from "styled-components";
import { motion, AnimatePresence } from "framer-motion";
function Modal(props: any) {
return (
<div>
<Overlay>
<AnimatePresence>
<motion.div
initial={{ opacity: 0, left: "50%", top: "50%", scale: 0.9, backdropFilter: "blur(10px)", y: -1, position: "absolute" }}
animate={{ opacity: 1, left: "50%", top: "50%", scale: 1, backdropFilter: "blur(10px)", y: 0, position: "absolute" }}
key="modal"
transition={{
type: "spring",
stiffness: 360,
damping: 70,
delay: 0.02,
}}
exit={{ opacity: 0, left: "50%", top: "46%", backdropFilter: "blur(10px)", y: -1, position: "absolute" }}
>
<Content>{props.children}</Content>
</motion.div>
</AnimatePresence>
</Overlay>
</div>
);
}
const Overlay = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
background-color: #00000029;
backdrop-filter: blur(1px);
`;
const Content = styled.div`
background-color: white;
border-radius: 5px;
padding: 20px;
width: 500px;
height: 500px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0px 64px 84px 15px rgb(0 0 0 / 10%);
`;
export default Modal;

View file

@ -1,6 +1,5 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { ArrowLeftIcon, Cross1Icon } from "@radix-ui/react-icons"; import { ArrowLeftIcon, Cross1Icon } from "@radix-ui/react-icons";
import Modal from "../Modal";
import styled from "styled-components"; import styled from "styled-components";
import DynamicCanvaModal from "./NewActivityModal/DynamicCanva"; import DynamicCanvaModal from "./NewActivityModal/DynamicCanva";
import VideoModal from "./NewActivityModal/Video"; import VideoModal from "./NewActivityModal/Video";

View file

@ -1,5 +1,4 @@
import React, { useState } from "react"; import React, { useState } from "react";
import Modal from "../Modal";
function NewChapterModal({ submitChapter , closeModal }: any) { function NewChapterModal({ submitChapter , closeModal }: any) {
const [chapterName, setChapterName] = useState(""); const [chapterName, setChapterName] = useState("");

View file

@ -6,13 +6,9 @@ import learnhouseIcon from "public/learnhouse_icon.png";
import learnhouseLogo from "public/learnhouse_logo.png"; import learnhouseLogo from "public/learnhouse_logo.png";
import Link from "next/link"; import Link from "next/link";
import Image from "next/image"; import Image from "next/image";
import { useRouter, useSearchParams, usePathname } from "next/navigation"; import { getUriWithOrg } from "@services/config/config";
import { headers } from "next/headers";
import { getOrgFromUri, getUriWithOrg } from "@services/config/config";
export const Menu = (props : any ) => { export const Menu = (props : any ) => {
const router = useRouter();
const pathname = usePathname();
const orgslug = props.orgslug; const orgslug = props.orgslug;

View file

@ -1,13 +0,0 @@
import React from "react";
import Link from 'next/link'
import styled from "styled-components";
export const Header = () => {
return (
<div>
</div>
);
};

View file

@ -1,66 +0,0 @@
"use client";
import React from "react";
import Head from "next/head";
import styled from "styled-components";
import AuthProvider from "../Security/AuthProvider";
import { motion } from "framer-motion";
import { Menu } from "./Elements/Menu";
const Layout = (props: any) => {
const variants = {
hidden: { opacity: 0, x: 0, y: 0 },
enter: { opacity: 1, x: 0, y: 0 },
exit: { opacity: 0, x: 0, y: 0 },
};
return (
<AuthProvider>
<ProjectPhaseLabel>🚧 Dev Phase</ProjectPhaseLabel>
<Menu orgslug={props.orgslug}></Menu>
<motion.main
variants={variants} // Pass the variant object into Framer Motion
initial="hidden" // Set the initial state to variants.hidden
animate="enter" // Animated state to variants.enter
exit="exit" // Exit state (used later) to variants.exit
transition={{ type: "linear" }} // Set the transition to linear
className=""
>
<Main className="min-h-screen">{props.children}</Main>
</motion.main>
<Footer>
<p>LearnHouse © 2021 - {new Date().getFullYear()} - All rights reserved</p>
</Footer>
</AuthProvider>
);
};
const Main = styled.main`
min-height: 100vh;
`;
const Footer = styled.footer`
display: flex;
justify-content: center;
margin: 20px;
font-size: 16px;
img {
width: 20px;
opacity: 0.4;
display: inline;
}
`;
export const ProjectPhaseLabel = styled.div`
position: fixed;
bottom: 0;
right: 0;
padding: 9px;
background-color: #080501;
color: white;
font-size: 19px;
font-weight: bold;
border-radius: 5px 0 0 0px;
`;
export default Layout;

View file

@ -2,7 +2,6 @@ import React from 'react';
import * as Dialog from '@radix-ui/react-dialog'; import * as Dialog from '@radix-ui/react-dialog';
import { styled, keyframes } from '@stitches/react'; import { styled, keyframes } from '@stitches/react';
import { violet, blackA, mauve, green } from '@radix-ui/colors'; import { violet, blackA, mauve, green } from '@radix-ui/colors';
import { Cross2Icon } from '@radix-ui/react-icons';
type ModalParams = { type ModalParams = {
dialogTitle: string; dialogTitle: string;

View file

@ -1,4 +1,4 @@
import { initialData } from "../../components/Drags/data"; import { initialData } from "../../components/Pages/CourseEdit/Draggables/data";
import { getAPIUrl } from "@services/config/config"; import { getAPIUrl } from "@services/config/config";
import { RequestBody } from "@services/utils/requests"; import { RequestBody } from "@services/utils/requests";