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 #319

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
4 changes: 3 additions & 1 deletion src/components/UniversiForm/UniversiForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@



function getCharLimit(object : FormObject){
function getCharLimit(object : FormObjectText){

Check warning on line 162 in src/components/UniversiForm/UniversiForm.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UniversiForm/UniversiForm.tsx#L162

Added line #L162 was not covered by tests
if(object.charLimit)
return object.charLimit;

Check warning on line 164 in src/components/UniversiForm/UniversiForm.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UniversiForm/UniversiForm.tsx#L164

Added line #L164 was not covered by tests
if(object.type == FormInputs.TEXT)
return MAX_TEXT_LENGTH;
else if(object.type == FormInputs.LONG_TEXT)
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
const groupContext = useContext(GroupContext);

if(!groupContext)
return null;

Check warning on line 23 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L23

Added line #L23 was not covered by tests

const OPTIONS_DEFINITION: OptionInMenu<GroupPost>[] = [

Check warning on line 25 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L25

Added line #L25 was not covered by tests
{
text: "Editar publicação",
biIcon: "pencil-fill",
onSelect(data) {
groupContext.setEditPost(data);

Check warning on line 30 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
},
hidden(){
return false;

Check warning on line 33 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L32-L33

Added lines #L32 - L33 were not covered by tests
},
},
{
Expand All @@ -38,30 +38,30 @@
biIcon: "trash-fill",
className: "delete",
onSelect: handleDeletePost,
hidden() {
return !groupContext?.group.canEdit;

Check warning on line 42 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L41-L42

Added lines #L41 - L42 were not covered by tests
},
}
]

function handleDeletePost(post: GroupPost){
console.log(post)
UniversimeApi.Feed.deleteGroupPost({postId: post.postId, groupId: post.groupId});
groupContext?.refreshData();

Check warning on line 50 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L47-L50

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

function canCreatePost(){

Check warning on line 53 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L53

Added line #L53 was not covered by tests
if(groupContext?.group.everyoneCanPost && groupContext.participants.some(p => p.id == groupContext.loggedData.profile.id))
return true;

Check warning on line 55 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L55

Added line #L55 was not covered by tests
else if(!groupContext?.group.everyoneCanPost && groupContext?.group.canEdit)
return true;
return false;

Check warning on line 58 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L57-L58

Added lines #L57 - L58 were not covered by tests
}

function canSeeMenu(post : GroupPost){

Check warning on line 61 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L61

Added line #L61 was not covered by tests
if(groupContext?.loggedData.profile.id != groupContext?.group.admin.id && groupContext?.loggedData.profile.id != post.author?.id)
return false;
return true;

Check warning on line 64 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L63-L64

Added lines #L63 - L64 were not covered by tests
}


Expand Down Expand Up @@ -104,9 +104,11 @@
charLimit: 3000,
value: groupContext.editPost ? groupContext.editPost.content : ""
,validation: new ValidationComposite<string>().addValidation(new RequiredValidation()).addValidation(new TextValidation())
}, {
DTOName : "postId", label : "", type : FormInputs.HIDDEN, value : groupContext.editPost?.postId
}
]}
requisition={groupContext.editPost ? UniversimeApi.Feed.createGroupPost : UniversimeApi.Feed.createGroupPost}
requisition={groupContext.editPost ? UniversimeApi.Feed.editGroupPost : UniversimeApi.Feed.createGroupPost}
callback={groupContext.refreshData}
/>
:
Expand Down Expand Up @@ -141,7 +143,7 @@
<div className="info">
<p className="group-description">{post.content}</p>
{ !hasAvailableOption(OPTIONS_DEFINITION) || !canSeeMenu(post) ? null :
<DropdownMenu.Root>

Check warning on line 146 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L146

Added line #L146 was not covered by tests
<DropdownMenu.Trigger asChild>
<button className="options-button">
<i className="bi bi-three-dots-vertical" />
Expand All @@ -149,13 +151,13 @@
</DropdownMenu.Trigger>

<DropdownMenu.Content className="options" side="left">
{ OPTIONS_DEFINITION.map(def => {

Check warning on line 154 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L154

Added line #L154 was not covered by tests
if(def.text == "Editar publicação" && post.author?.id == groupContext?.loggedData.profile.id)
return renderOption(post, def)

Check warning on line 156 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L156

Added line #L156 was not covered by tests
else if(def.text == "Editar publicação")
return null

Check warning on line 158 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L158

Added line #L158 was not covered by tests
else
return renderOption(post, def)

Check warning on line 160 in src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/Group/GroupTabs/GroupFeed/GroupFeed.tsx#L160

Added line #L160 was not covered by tests

}) }
<DropdownMenu.Arrow className="options-arrow" height=".5rem" width="1rem" />
Expand Down
21 changes: 15 additions & 6 deletions src/services/UniversimeApi/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
import {GroupPost} from "@/types/Feed"

export type CreateGroupPost_RequestDTO = {
content: string;
groupId : string;
content : string;
groupId : string;
authorId : string;
};

export type GetGroupPost_RequestDTO = {
groupId : string;
}

export type DeleteGroup_RequestDTO = {
postId : string;
export type DeleteGroupPost_RequestDTO = {
postId : string;
groupId : string;
}

export type EditGroupPost_RequestDTO = {
content : string;
postId : string;
groupId : string;
}

export type CreateGroupPostResponseDTO = ApiResponse<GroupPost>;
export type GetGroupPostsResponseDTO = ApiResponse<{posts: GroupPost[]}>;
Expand All @@ -26,10 +31,14 @@
}

export async function createGroupPost(body: CreateGroupPost_RequestDTO): Promise<CreateGroupPostResponseDTO> {
return await (await api.post<CreateGroupPostResponseDTO>(`/feed/groups/${body.groupId}/posts`, body)).data;
return (await api.post<CreateGroupPostResponseDTO>(`/feed/groups/${body.groupId}/posts`, body)).data;

Check warning on line 34 in src/services/UniversimeApi/Feed.ts

View check run for this annotation

Codecov / codecov/patch

src/services/UniversimeApi/Feed.ts#L34

Added line #L34 was not covered by tests
}

export async function editGroupPost(body : EditGroupPost_RequestDTO) : Promise<ApiResponse<string>> {
return (await api.put<ApiResponse<string>>(`/feed/groups/${body.groupId}/posts/${body.postId}`, body)).data;

Check warning on line 38 in src/services/UniversimeApi/Feed.ts

View check run for this annotation

Codecov / codecov/patch

src/services/UniversimeApi/Feed.ts#L37-L38

Added lines #L37 - L38 were not covered by tests
}

export async function deleteGroupPost(body: DeleteGroup_RequestDTO): Promise<ApiResponse<string>> {
export async function deleteGroupPost(body: DeleteGroupPost_RequestDTO): Promise<ApiResponse<string>> {
const response = await api.delete<ApiResponse<string>>(`/feed/groups/${body.groupId}/posts/${body.postId}`);

Check warning on line 42 in src/services/UniversimeApi/Feed.ts

View check run for this annotation

Codecov / codecov/patch

src/services/UniversimeApi/Feed.ts#L41-L42

Added lines #L41 - L42 were not covered by tests
return response.data;
}
Loading