Skip to content

Commit

Permalink
feat(homeworks) : add better homeworks with ony session content handl…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
saumon-brule committed Sep 8, 2024
1 parent 8811f40 commit 3851f09
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 73 deletions.
13 changes: 7 additions & 6 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@
--background-color-warning-2: 255, 51, 0;

/* success */

--background-color-success: 0, 255, 56;
--border-color-success: 98, 207, 122;

/* - Others - */
--background-color-selection: 4, 98, 210;

--background-color-streak-0: 255, 15, 0;
--background-color-streak-1: 255, 150, 0;

Expand All @@ -190,7 +190,7 @@
--box-shadow-element: 0 0 15px rgba(0, 0, 0, 0.25);
--color-shadow-window: rgba(0, 0, 0, 0.4);
--color-shadow-element: rgba(0, 0, 0, 0.25);

--text-color-main: 0, 0, 0;
--text-color-main-reverse: 255, 255, 255;
--text-color-alt: 76, 76, 184;
Expand All @@ -202,14 +202,15 @@
/* --background-color-3: 94, 94, 136; */
--background-color-focus: 75, 72, 217, 0.1;
--background-color-header: 187, 187, 255;

--background-color-strength-li-1: 36, 186, 22;
--background-color-strength-li-2: 27, 155, 22;
--background-color-strength-li-3: 17, 123, 21;

--border-color-0: 109, 106, 251;
--border-color-1: 75, 72, 217;

--border-color-contrast: 100, 100, 180;

/* error */

--text-color-error: 255, 66, 66;
Expand Down
9 changes: 4 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,10 @@ export default function App() {
const upcomingAssignments = []
const sortedHomeworks = Object.fromEntries(Object.entries(homeworks).map((day) => {
return [day[0], day[1].map((homework, i) => {
const { codeMatiere, donneLe, effectue, idDevoir, interrogation, matiere, /* rendreEnLigne, documentsAFaire // I don't know what to do with that for now */ } = homework;
const { codeMatiere, aFaire, donneLe, effectue, idDevoir, interrogation, matiere, /* rendreEnLigne, documentsAFaire // I don't know what to do with that for now */ } = homework;
const task = {
id: idDevoir,
type: aFaire ? "task" : "sessionContent",
subjectCode: codeMatiere,
subject: matiere,
addDate: donneLe,
Expand Down Expand Up @@ -1108,6 +1109,7 @@ export default function App() {

return {
id: id,
type: "task",
subjectCode: codeMatiere,
subject: matiere,
addDate: donneLe,
Expand All @@ -1124,14 +1126,11 @@ export default function App() {
// This handles the case where there is no homework but there is a session content. I think it can be improved but for now it's fine
return {
id: id,
type: "sessionContent",
subjectCode: codeMatiere,
subject: matiere,
addDate: day[0],
isInterrogation: false,
isDone: false,
teacher: nomProf,
content: "Ti9B",
files: [],
sessionContent: contenuDeSeance.contenu,
sessionContentFiles: contenuDeSeance.documents.map((e) => (new File(e.id, e.type, e.libelle)))
}
Expand Down
149 changes: 149 additions & 0 deletions src/components/app/Homeworks/DetailedSessionContent.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
.detailed-session-content {
display: flex;
flex-direction: column;
gap: 5px;
flex-shrink: 0;
}

.session-content-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}

.session-content-header h4 {
font-size: var(--font-size-16);
}

.session-content-subtitle {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
}

.detailed-session-content .add-date {
display: inline-block;
color: rgb(var(--text-color-alt));
font-size: var(--font-size-14);
}

.detailed-session-content .session-content-content {
margin-block: 5px;
padding: 15px;
padding-right: 45px;
border-radius: 10px;
position: relative;
max-height: 120px;
transition: .2s;
overflow: hidden;
cursor: pointer;
}

.detailed-session-content .session-content-content:is(:hover, :focus-visible) {
max-height: 150px;
}

.detailed-session-content .session-content-content::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.dark .detailed-session-content .session-content-content {
background-color: rgba(var(--text-color-main-reverse), 0.15);
}

.dark .detailed-session-content .session-content-content::after{
background-image: linear-gradient(0deg, #333350, transparent 60px);
}

.light .detailed-session-content .session-content-content {
background-color: rgba(var(--text-color-main-reverse), 0.3);
}

.light .detailed-session-content .session-content-content::after{
background-image: linear-gradient(0deg, #b0b0e1, transparent 60px);
}

.detailed-session-content .session-content-content .copy-button {
position: absolute;
top: 7px;
right: 7px;
opacity: 0;
transition: .1s;
}

.detailed-session-content .session-content-content:is(:hover, :focus-within) .copy-button {
opacity: 1;
}

/* change session-content content items appearance */
.detailed-session-content .session-content-content a {
word-break: break-all;
}

.detailed-session-content .session-content-content a:is(:hover, :focus-visible) {
opacity: .8;
}

.detailed-session-content .session-content-content a:active {
opacity: .6;
}

.session-content-footer {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
gap: 10px;
}

.session-content-footer .session-content-footer-button {
padding: 8px;
border-radius: 10px;
flex: 1;
background-color: rgba(var(--background-color-3), .5);
color: rgb(var(--text-color-alt));

display: flex;
align-items: center;
transition: .1s;
cursor: pointer;
text-decoration: none;
}

.session-content-footer .session-content-footer-button.disabled {
pointer-events: none;
filter: brightness(0.6);
}

.light .session-content-footer .session-content-footer-button.disabled {
pointer-events: none;
filter: opacity(0.4);
}

.session-content-footer .session-content-footer-button:is(:hover, :focus-visible) {
background-color: rgb(var(--background-color-3));
}

.session-content-footer .session-content-footer-button:active {
background-color: rgb(var(--background-color-3), .7);
}

.session-content-footer .session-content-footer-button .download-icon {
height: 20px;
margin-right: 10px;
}
.session-content-footer .session-content-footer-button .session-content-icon {
height: 20px;
scale: 1.5;
margin-right: 7px;
}
.session-content-footer .session-content-footer-button svg * {
stroke: rgb(var(--text-color-alt));
}

80 changes: 80 additions & 0 deletions src/components/app/Homeworks/DetailedSessionContent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useEffect, useRef, useContext } from "react"
import ContentLoader from "react-content-loader"
import EncodedHTMLDiv from "../../generic/CustomDivs/EncodedHTMLDiv"
import CheckBox from "../../generic/UserInputs/CheckBox"
import { AppContext } from "../../../App"
import { applyZoom } from "../../../utils/zoom";
import { Link, useLocation, useNavigate } from "react-router-dom"
import DownloadIcon from "../../graphics/DownloadIcon"

import { clearHTML } from "../../../utils/html"

import "./DetailedSessionContent.css"

export default function DetailedSessionContent({ sessionContent, userHomeworks, day, sessionContentIndex, ...props }) {
const navigate = useNavigate()

const detailedTaskRef = useRef(null);
const { actualDisplayTheme, fetchHomeworksDone, useUserSettings } = useContext(AppContext)
const settings = useUserSettings();
const homeworks = userHomeworks.get()

const contentLoadersRandomValues = useRef({ labelWidth: Math.floor(Math.random() * 100) + 200, contentHeight: Math.floor(Math.random() * 200) + 50 })
const location = useLocation();
const oldLocationHash = useRef(null);

function scrollIntoViewNearestParent(element) {
const parent = element.parentElement;
const parentBounds = parent.getBoundingClientRect();
const bounds = element.getBoundingClientRect();

parent.scrollTo(0, bounds.y - parentBounds.y + parent.scrollTop - 20)
}

useEffect(() => {
if (oldLocationHash.current === location.hash) {
return;
}

oldLocationHash.current = location.hash;

if (["#patch-notes", "#policy", "#feedback"].includes(location.hash)) {
return;
}

const anchors = location.hash.split(";");

if (anchors.length < 2) {
return;
}

const sessionContentId = parseInt(anchors[1]);

if (isNaN(sessionContentId)) {
return;
}

if (sessionContentId === sessionContent.id && detailedTaskRef.current) {
setTimeout(() => scrollIntoViewNearestParent(detailedTaskRef.current), 200);
}

}, [location, detailedTaskRef.current, homeworks])

return <div ref={detailedTaskRef} onClick={(e) => { navigate(`#${day};${sessionContent.id}`); e.stopPropagation() }} className={`detailed-session-content ${sessionContent.isDone ? "done" : ""}`} id={"session-content-" + sessionContent.id} {...props} >
<div className="session-content-header">
<h4>
{sessionContent.subject.replace(". ", ".").replace(".", ". ")}
</h4>
</div>
<div className="session-content-subtitle">
{sessionContent.addDate && <span className="add-date">Donné le {(new Date(sessionContent.addDate)).toLocaleDateString()} par {settings.get("isStreamerModeEnabled") ? "M. -------" : sessionContent.teacher}</span>}
{sessionContent.isInterrogation && <span className="interrogation-alert">évaluation</span>}
</div>
<Link to={`#${day};${sessionContent.id};s`} onClick={(e) => e.stopPropagation()} replace={true} >
<EncodedHTMLDiv className="session-content-content" backgroundColor={actualDisplayTheme === "dark" ? "#40405b" : "#e4e4ff"} >{sessionContent.sessionContent}</EncodedHTMLDiv>
</Link>
<div className="session-content-footer">
<Link to={`#${day};${sessionContent.id};f`} onClick={(e) => e.stopPropagation()} replace={true} className={`session-content-footer-button ${sessionContent.sessionContentFiles.length === 0 ? "disabled" : ""}`}><DownloadIcon className="download-icon" />Fichiers</Link>
</div>
</div>
}
2 changes: 1 addition & 1 deletion src/components/app/Homeworks/Homeworks.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
height: 100%;
}

.session-content {
.bottomsheet-session-content {
margin-bottom: 15px;
}

Expand Down
Loading

0 comments on commit 3851f09

Please sign in to comment.