Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualizando branch com botões de conteúdo e material #245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
614 changes: 614 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build-storybook": "storybook build"
},
"dependencies": {
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-switch": "^1.0.3",
"@types/youtube": "^0.0.47",
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Group/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

async function refreshGroupData() {
const data = await fetchGroupPageData({ groupPath: page.group?.path });
setContext(makeContext(data));
const newContext = makeContext(data);
setContext(newContext);
return newContext;

Check warning on line 52 in src/pages/Group/Group.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/Group.tsx#L50-L52

Added lines #L50 - L52 were not covered by tests
}

function makeContext(data: GroupPageLoaderResponse): NonNullable<GroupContextType> {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Group/GroupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type GroupContextType = null | {
groups: Group[];
};

refreshData: () => Promise<any>;
refreshData: () => Promise<NonNullable<GroupContextType>>;
};

export const GroupContext = createContext<GroupContextType>(null);
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,88 @@
text-align: justify;
}
}

.material-options-button {
margin-right: 1rem;
margin-left: auto;

display: flex;
padding-bottom: 3px;
align-items: center;
justify-content: center;

border: none;
border-radius: 50%;
background-color: transparent;

font-size: 1.5rem;
height: 2rem;
aspect-ratio: 1;

will-change: background-color;
cursor: pointer;

&:hover {
background-color: #C1C1C1;
}
}

.material-options {
background-color: @card-background-color;
border-radius: .625rem;
padding: .25rem .5rem;

min-width: 7rem;

.material-options-arrow {
fill: @card-background-color;
}

.dropdown-options-item {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;

padding: .25rem .5rem;
border-radius: .625rem;

font-size: .9rem;

cursor: pointer;

&:hover {
background-color: @button-hover-color;
outline: none;

&.delete {
background-color: @alert-color;
color: @font-color-v1;
}
}

&[data-disabled] {
color: @font-disabled-color;

&:hover {
background-color: transparent;
}
}

&:not(:last-child) {
margin-bottom: .25rem;
}

.right-slot {
width: fit-content;
margin-left: auto;

&.bi {
font-size: 1.2em;
}
}
}
}
}
}
}
}
69 changes: 67 additions & 2 deletions src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useContext, useEffect, useState } from "react";
import { Link } from "react-router-dom";
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import UniversimeApi from "@/services/UniversimeApi";
import * as SwalUtils from "@/utils/sweetalertUtils";
import { EMPTY_LIST_CLASS, GroupContext } from "@/pages/Group";
import { setStateAsValue } from "@/utils/tsxUtils";
import { ContentStatusEnum, type Content, ContentStatus, ContentType } from "@/types/Capacity";
import YouTube from "react-youtube";
import { ContentStatusEnum, type Content } from "@/types/Capacity";

import "./GroupContentMaterials.less";
import { VideoPopup } from "@/components/VideoPopup/VideoPopup";
import { ContentStatusEdit_RequestDTO } from "@/services/UniversimeApi/Capacity";
import { renderOption, type OptionInMenu, hasAvailableOption } from "@/utils/dropdownMenuUtils";

export function GroupContentMaterials() {
const groupContext = useContext(GroupContext);
Expand All @@ -33,6 +34,26 @@

const groupName = <div onClick={() => groupContext.setCurrentContent(undefined)} style={{cursor: "pointer", display: "inline"}}>{groupContext.group.name}</div>

const OPTIONS_DEFINITION: OptionInMenu<Content>[] = [

Check warning on line 37 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L37

Added line #L37 was not covered by tests
{
text: "Editar",
biIcon: "pencil-fill",
disabled() { return true; },
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;

Check warning on line 43 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L41-L43

Added lines #L41 - L43 were not covered by tests
},
},
{
text: "Excluir",
biIcon: "trash-fill",
className: "delete",
onSelect: handleDeleteMaterial,
hidden() {
return groupContext?.group.admin.id !== groupContext?.loggedData.profile.id;

Check warning on line 52 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L51-L52

Added lines #L51 - L52 were not covered by tests
},
}
];

return (
<section id="materials" className="group-tab">
<div className="heading top-container">
Expand Down Expand Up @@ -133,6 +154,21 @@
}
<p className="material-description">{material.description}</p>
</div>

{ !hasAvailableOption(OPTIONS_DEFINITION) ? null :
<DropdownMenu.Root>

Check warning on line 159 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L159

Added line #L159 was not covered by tests
<DropdownMenu.Trigger asChild>
<button className="material-options-button">
<i className="bi bi-three-dots-vertical" />
</button>
</DropdownMenu.Trigger>

<DropdownMenu.Content className="material-options" side="left">
{ OPTIONS_DEFINITION.map(def => renderOption(material, def)) }

Check warning on line 167 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L167

Added line #L167 was not covered by tests
<DropdownMenu.Arrow className="material-options-arrow" height=".5rem" width="1rem" />
</DropdownMenu.Content>
</DropdownMenu.Root>
}
</div>
);
}
Expand Down Expand Up @@ -248,6 +284,35 @@

}

function handleDeleteMaterial(material: Content) {
SwalUtils.fireModal({

Check warning on line 288 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L287-L288

Added lines #L287 - L288 were not covered by tests
showCancelButton: true,

cancelButtonText: "Cancelar",
confirmButtonText: "Remover",
confirmButtonColor: "var(--alert-color)",

text: "Tem certeza que deseja remover este conteúdo deste grupo?",
icon: "warning",
}).then(res => {

Check warning on line 297 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L297

Added line #L297 was not covered by tests
if (res.isConfirmed) {
const folderId = groupContext?.currentContent?.id!;

Check warning on line 299 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L299

Added line #L299 was not covered by tests

UniversimeApi.Capacity.removeContentFromFolder({ folderId, contentIds: material.id })
.then(res => {

Check warning on line 302 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L301-L302

Added lines #L301 - L302 were not covered by tests
if (!res.success)
return;

Check warning on line 304 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L304

Added line #L304 was not covered by tests

groupContext?.refreshData()
.then(data => {
setTimeout(() => {
data.setCurrentContent(data.folders.find(c => c.id === folderId));

Check warning on line 309 in src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupContents/GroupContentMaterials.tsx#L306-L309

Added lines #L306 - L309 were not covered by tests
}, 0);
});
});
}
});
}
}


Expand Down
100 changes: 94 additions & 6 deletions src/pages/Group/GroupTabs/GroupContents/GroupContents.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,104 @@
}

.info {
width: 100%;
margin-left: 3rem;

color: @font-color-v2;
.content-name {
color: inherit;
text-decoration: none;
font-weight: @font-weight-semibold;
font-size: 1.5rem;

cursor: pointer;
.content-name-wrapper {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;

.content-name {
color: inherit;
text-decoration: none;
font-weight: @font-weight-semibold;
font-size: 1.5rem;

cursor: pointer;
}

.content-options-button {
display: flex;
padding-bottom: 3px;
align-items: center;
justify-content: center;

border: none;
border-radius: 50%;
background-color: transparent;

font-size: 1.5rem;
height: 2rem;
aspect-ratio: 1;

will-change: background-color;
cursor: pointer;
&:hover {
background-color: #C1C1C1;
}
}

.content-options {
background-color: @card-background-color;
border-radius: .625rem;
padding: .25rem .5rem;

min-width: 7rem;

.content-options-arrow {
fill: @card-background-color;
}

.dropdown-options-item {
display: flex;
flex-direction: row;
align-items: center;
width: 100%;

padding: .25rem .5rem;
border-radius: .625rem;

font-size: .9rem;

cursor: pointer;

&:hover {
background-color: @button-hover-color;
outline: none;

&.delete {
background-color: @alert-color;
color: @font-color-v1;
}
}

&[data-disabled] {
color: @font-disabled-color;

&:hover {
background-color: transparent;
}
}

&:not(:last-child) {
margin-bottom: .25rem;
}

.right-slot {
width: fit-content;
margin-left: auto;

&.bi {
font-size: 1.2em;
}
}
}
}
}

.content-description {
Expand Down
Loading
Loading