Skip to content

Commit

Permalink
Remix from public activities
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharles committed Apr 5, 2023
1 parent e63c073 commit b7dca89
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
13 changes: 12 additions & 1 deletion public/api/getPortfolioActivityData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'doenetId' => $doenetId,
'imagePath' => '/activity_default.jpg',
'label' => '',
'userCanViewSource' => '',
// 'learningOutcomes' => '',
'public' => false, //default to private
'isNew' => true,
Expand Down Expand Up @@ -90,11 +91,20 @@
$sql = "
SELECT imagePath,
label,
userCanViewSource,
isPublic
FROM course_content
WHERE doenetId='$doenetId'
AND courseId = (SELECT courseId FROM course WHERE portfolioCourseForUserId = '$userId')
";
// $sql = "
// SELECT imagePath,
// label,
// userCanViewSource,
// isPublic
// FROM course_content
// WHERE doenetId='$doenetId'
// AND courseId = (SELECT courseId FROM course WHERE portfolioCourseForUserId = '$userId')
// ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
Expand All @@ -103,6 +113,7 @@
'doenetId' => $doenetId,
'imagePath' => $row['imagePath'],
'label' => $row['label'],
'userCanViewSource' => $row['userCanViewSource'],
// 'learningOutcomes' => $row['learningOutcomes'],
'public' => $row['isPublic'],
'isNew' => false,
Expand Down
58 changes: 44 additions & 14 deletions src/Tools/_framework/Panels/NewSupportPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ import {
useRecoilValue,
} from 'recoil';
import Button from '../../../_reactComponents/PanelHeaderComponents/Button';
import { useLoaderData, useNavigate } from 'react-router';
import { redirect, useLoaderData, useNavigate } from 'react-router';
import { pageToolViewAtom, searchParamAtomFamily } from '../NewToolRoot';
import { useCourse } from '../../../_reactComponents/Course/CourseActions';
import { Form } from 'react-router-dom';

// export async function action({ request, params }) {
// const formData = await request.formData();
// let formObj = Object.fromEntries(formData);
// console.log("formObj",formObj)
// return true;
// }
export async function loader({ request }){
const url = new URL(request.url);
const doenetId = url.searchParams.get("doenetId");
const response = await fetch(`/api/getPortfolioActivityData.php?doenetId=${doenetId}`);
const data = await response.json();

return data.activityData;
}

export async function action({ request }) {
const formData = await request.formData();
let formObj = Object.fromEntries(formData);
if (formObj._action == "Remix"){
let response = await fetch(`/api/duplicatePortfolioActivity.php?doenetId=${formObj.doenetId}`);
let respObj = await response.json();

const { nextActivityDoenetId, nextPageDoenetId } = respObj;
return redirect(`/portfolioeditor/${nextActivityDoenetId}?tool=editor&doenetId=${nextActivityDoenetId}&pageId=${nextPageDoenetId}`);
}
return true;
}

const SupportWrapper = styled.div`
overflow: auto;
Expand Down Expand Up @@ -42,7 +58,12 @@ export default function SupportPanel({ hide, children }) {
const recoilPageToolView = useRecoilValue(pageToolViewAtom);
const { compileActivity, updateAssignItem } = useCourse(data?.courseId);


let canRemix = false;
if (recoilPageToolView?.page == 'public' &&
data?.userCanViewSource == '1'
){
canRemix = true;
}
return (
<>
<ControlsWrapper $hide={hide} aria-label="complementary controls" data-test="Support Panel Controls">
Expand All @@ -55,6 +76,7 @@ export default function SupportPanel({ hide, children }) {
// addToast('Activity Assigned.', toastType.INFO);
// },
});

updateAssignItem({
doenetId,
isAssigned: true,
Expand All @@ -63,10 +85,18 @@ export default function SupportPanel({ hide, children }) {
},
});
}}/> : null }
{recoilPageToolView?.page == 'portfolioeditor' ? <Button value="Settings" onClick={()=>navigate(`/portfolio/${doenetId}/settings?referrer=portfolioeditor`)}/> : null }
<Button value="Documentation" onClick={()=>window.open("/public?tool=editor&doenetId=_DG5JOeFNTc5rpWuf2uA-q")}/>

{canRemix ? <Form method="post">
<Button style={{marginTop:"8px"}} value="Remix" />
<input type="hidden" name="_action" value="Remix" />
<input type="hidden" name="doenetId" value={doenetId} />
</Form>
: null }

{recoilPageToolView?.page == 'portfolioeditor' ? <Button value="Settings" onClick={()=>navigate(`/portfolio/${doenetId}/settings?referrer=portfolioeditor`)}/> : null }
<Button value="Documentation" onClick={()=>window.open("/public?tool=editor&doenetId=_DG5JOeFNTc5rpWuf2uA-q")}/>
</ControlsWrapper>
<SupportWrapper $hide={hide} role="complementary" data-test="Support Panel">{children}</SupportWrapper>
</>
);
}
<SupportWrapper $hide={hide} role="complementary" data-test="Support Panel">{children}</SupportWrapper>
</>
);
}
2 changes: 0 additions & 2 deletions src/Tools/_framework/Paths/PortfolioActivityViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export async function action({params}){
let response = await fetch(`/api/duplicatePortfolioActivity.php?doenetId=${params.doenetId}`);
let respObj = await response.json();

console.log("respObj",respObj)
const { nextActivityDoenetId, nextPageDoenetId } = respObj;
return redirect(`/portfolioeditor/${nextActivityDoenetId}?tool=editor&doenetId=${nextActivityDoenetId}&pageId=${nextPageDoenetId}`);
// return true;
}

export async function loader({params}){
Expand Down
19 changes: 18 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { loader as portfolioEditorMenuCapLoader } from "./Tools/_framework/MenuP
import { loader as publicPortfolioLoader, PublicPortfolio } from "./Tools/_framework/Paths/PublicPortfolio";
import { loader as portfolioActivityViewerLoader, action as portfolioActivityViewerAction, PortfolioActivityViewer } from "./Tools/_framework/Paths/PortfolioActivityViewer";
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
// import { action as portfolioEditorSupportPanelAction } from "./Tools/_framework/Panels/NewSupportPanel";
import { action as editorSupportPanelAction, loader as editorSupportPanelLoader } from "./Tools/_framework/Panels/NewSupportPanel";

import '@fontsource/jost';

Expand Down Expand Up @@ -128,6 +128,23 @@ const router = createBrowserRouter([
</DarkmodeController>
),
},
{
path: "/public",
loader: editorSupportPanelLoader,
action: editorSupportPanelAction,
// errorElement: <div>Error!</div>,
element: (
<DarkmodeController>
<MathJaxContext
version={2}
config={mathjaxConfig}
onStartup={(mathJax) => (mathJax.Hub.processSectionDelay = 0)}
>
<ToolRoot />
</MathJaxContext>
</DarkmodeController>
),
},
{
path: "*",
// errorElement: <div>Error!</div>,
Expand Down

0 comments on commit b7dca89

Please sign in to comment.