Skip to content

Commit

Permalink
task(front/home): divide aulas por secção de disciplinas na página pr…
Browse files Browse the repository at this point in the history
…incipal (#205)

* front(typescript): export interface to after usage

* front(home): divide selected classes by section

* fix(front/home): height discipline section title
  • Loading branch information
mateusvrs authored Feb 20, 2024
1 parent 007a8cc commit ed6ba7b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions web/app/contexts/ClassesToShowContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { createContext, useState } from 'react';

import { ClassValueType } from './SelectedClassesContext/types';

interface ClassesToShowContextType {
export interface ClassesToShowContextType {
classesToShow: Array<ClassValueType>,
setClassesToShow: (value: Array<ClassValueType>) => void;
}

interface ClassesToShowContextProviderPropsType {
export interface ClassesToShowContextProviderPropsType {
children: React.ReactNode
}

Expand Down
35 changes: 31 additions & 4 deletions web/app/schedules/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useEffect, useRef } from 'react';
import { Fragment, useEffect, useRef } from 'react';
import useSelectedClasses from '@/app/hooks/useSelectedClasses';
import useClassesToShow from '@/app/hooks/useClassesToShow';

Expand All @@ -13,6 +13,33 @@ import ClickOutsideHandler from './handlers/ClickOutsideHandler';

import ShowPopUpContentContextProvider from '@/app/contexts/ShowPopUpContentContext';

import { ClassValueType } from '@/app/contexts/SelectedClassesContext/types';

function DisciplineBlockJSX({ ...props }: {
index: number,
cls: ClassValueType,
classesToShow: ClassValueType[]
}) {
let classAppearance;
for (let indexInner = 0; indexInner < props.classesToShow.length; indexInner++) {
if (props.classesToShow[indexInner].discipline.code === props.cls.discipline.code) {
classAppearance = indexInner;
break;
}
}

return (
<Fragment key={props.index}>
{props.index === classAppearance &&
<span className='flex justify-center items-center text-center rounded-md font-medium bg-primary bg-opacity-80 w-10/12 p-2'>
{props.cls.discipline.name}
</span>
}
<DisciplineBox currentClass={props.cls} discipline={props.cls.discipline} />
</Fragment>
);
}

export default function Home() {
const { classesToShow, setClassesToShow } = useClassesToShow();
const { classesChange, selectedClasses } = useSelectedClasses();
Expand All @@ -31,9 +58,9 @@ export default function Home() {
<ClickOutsideHandler refs={{ divAddClassRef, buttonAddDisciplineRef }}>
<AddDisciplineButton buttonAddDisciplineRef={buttonAddDisciplineRef} />
<div className={`flex flex-col items-center ${classesToShow.length ? '' : 'justify-center text-center'} gap-5 overflow-auto min-h-full max-h-full pb-2`}>
{classesToShow.length ? classesToShow.map((cls, index) =>
<DisciplineBox key={index} currentClass={cls} discipline={cls.discipline} />
) : 'Nenhuma disciplina escolhida no momento'}
{classesToShow.length ? classesToShow.map((cls, index) => {
return DisciplineBlockJSX({ index, cls, classesToShow });
}) : 'Nenhuma disciplina escolhida no momento'}
</div>

<AsideSchedulePopUp divAddClassRef={divAddClassRef} />
Expand Down

0 comments on commit ed6ba7b

Please sign in to comment.