From f47ee0e2d428c8cd53b2ab8cfc0370cd161e664f Mon Sep 17 00:00:00 2001 From: Kastan Day Date: Wed, 20 Dec 2023 11:55:41 -0800 Subject: [PATCH] On new course creation, properly redirect to /materials page (#86) --- .../UIUC-Components/LargeDropzone.tsx | 9 ++++- .../UIUC-Components/MakeNewCoursePage.tsx | 33 ++----------------- src/components/UIUC-Components/WebScrape.tsx | 16 +++------ 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/src/components/UIUC-Components/LargeDropzone.tsx b/src/components/UIUC-Components/LargeDropzone.tsx index ebdce9216..cdfa51649 100644 --- a/src/components/UIUC-Components/LargeDropzone.tsx +++ b/src/components/UIUC-Components/LargeDropzone.tsx @@ -77,11 +77,18 @@ export function LargeDropzone({ // console.log("in LargeDropzone.tsx ALL emailAddresses: ", user?.emailAddresses ) const refreshOrRedirect = async (redirect_to_gpt_4: boolean) => { + if (is_new_course) { + // refresh current page + await new Promise((resolve) => setTimeout(resolve, 200)) + router.push(`/${courseName}/materials`) + return + } + if (redirect_to_gpt_4) { router.push(`/${courseName}/chat`) } // refresh current page - await new Promise((resolve) => setTimeout(resolve, 700)) + await new Promise((resolve) => setTimeout(resolve, 200)) router.reload() } const uploadToS3 = async (file: File | null, uniqueFileName: string) => { diff --git a/src/components/UIUC-Components/MakeNewCoursePage.tsx b/src/components/UIUC-Components/MakeNewCoursePage.tsx index 630122cf5..ee6bf4ed6 100644 --- a/src/components/UIUC-Components/MakeNewCoursePage.tsx +++ b/src/components/UIUC-Components/MakeNewCoursePage.tsx @@ -1,26 +1,6 @@ import Head from 'next/head' -// import { -// Card, -// Text, -// Flex, -// Group, -// Checkbox, -// Col, -// Paper, -// Input, -// Textarea, -// FileInput, -// MediaQuery, -// type CheckboxProps, -// Title, -// } from '@mantine/core' - import React, { useState } from 'react' -// import GlobalHeader from './GlobalHeader' -// import GlobalFooter from './GlobalFooter' -// import EmailChipsComponent from './EmailChipsComponent' -// import { type CourseMetadata } from '~/types/courseMetadata' -// import LargeDropzone from './LargeDropzone' + import PlainNavbar from '~/components/UIUC-Components/navbars/PlainNavbar' import { useMediaQuery } from '@mantine/hooks' import EditCourseCard from '~/components/UIUC-Components/EditCourseCard' @@ -32,15 +12,6 @@ const MakeNewCoursePage = ({ course_name: string current_user_email: string }) => { - const [introMessage, setIntroMessage] = useState('') - const [courseName, setCourseName] = useState(course_name || '') - const [isCourseAvailable, setIsCourseAvailable] = useState< - boolean | undefined - >(undefined) - const [allExistingCourseNames, setAllExistingCourseNames] = useState< - string[] - >([]) - const isSmallScreen = useMediaQuery('(max-width: 960px)') return ( <> @@ -49,7 +20,7 @@ const MakeNewCoursePage = ({ {course_name} diff --git a/src/components/UIUC-Components/WebScrape.tsx b/src/components/UIUC-Components/WebScrape.tsx index 55e940e1e..67a7c1d17 100644 --- a/src/components/UIUC-Components/WebScrape.tsx +++ b/src/components/UIUC-Components/WebScrape.tsx @@ -133,11 +133,7 @@ export const WebScrape = ({ showToast() if (is_new_course) { - // Make course exist in kv store - // Removing this for kv refactor - // await setCourseExistsAPI(courseName) - - // set course exists in new metadata endpoint. Works great. + // set course exists in new metadata endpoint const response = callSetCourseMetadata(courseName, { course_owner: current_user_email, // Don't set properties we don't know about. We'll just upsert and use the defaults. @@ -153,7 +149,7 @@ export const WebScrape = ({ if (!response) { throw new Error('Error while setting course metadata') } - router.replace(`/${courseName}/materials`) + router.push(`/${courseName}/materials`) } router.push(`/${courseName}/materials`) } else if (url.includes('canvas.illinois.edu/courses/')) { @@ -498,11 +494,9 @@ export const WebScrape = ({ }} size="md" radius={'xl'} - className={`rounded-s-md ${ - isUrlUpdated ? 'bg-purple-800' : 'border-purple-800' - } overflow-ellipsis text-ellipsis p-2 ${ - isUrlUpdated ? 'text-white' : 'text-gray-500' - } min-w-[5rem] -translate-x-1 transform hover:border-indigo-600 hover:bg-indigo-600 hover:text-white focus:shadow-none focus:outline-none`} + className={`rounded-s-md ${isUrlUpdated ? 'bg-purple-800' : 'border-purple-800' + } overflow-ellipsis text-ellipsis p-2 ${isUrlUpdated ? 'text-white' : 'text-gray-500' + } min-w-[5rem] -translate-x-1 transform hover:border-indigo-600 hover:bg-indigo-600 hover:text-white focus:shadow-none focus:outline-none`} w={`${isSmallScreen ? 'auto' : 'auto'}`} disabled={isDisabled} >