Skip to content

Commit

Permalink
Deploy Beta (#317)
Browse files Browse the repository at this point in the history
* save ui state for filters and searching

* fixed game id

* filters state is saved but resets within the filters menu

* added pagination and saved in routes

* if all filters are selected, with only one post, filter box extends out too far

* Unnecessary semicolon

* fixed some issues with page state, simplified query string build

* fixed bug when filters are applied when not on page 1

* made new post users list compinent

* updated card style and post page

* fix code review points

* ran formatter

* added value to selectors, still a problem objects matching IDs

* fixed filter swap

* put view button on bottom of card

* fixed theming issues

* dynamically highlight discover/social tab while on post page

* ran formatter

* fix

* added working game selector to create post

* Revert "added working game selector to create post"

This reverts commit 36935bc.

* Small fix in SignUp, probably needs to be more descriptive

* restrcict post time and small fix

* Fix post page css not found

* Encapsulate date logic in date picker component

* Move date filter to new file and setup radio buttons

* Remove erroneous console.log

* Fix naming issue

* Add radio button to date filter

* Move SelectTimeRangeFilter to Filters file

* Delete date params when null

* Fix end date update logic

* switched to useSearchParams. Fixed filter problem.

* fixed filter problem

* fixed some small errors

* combined useEffect for search params, correctly saves date and time in URL

* ran formatter

* Time range filter radio buttons

* Typo

* Styling

* seperate games and tags with commas

* Move DateRangePicker urlParam management to Discover

* Fix flicker on page load

* Formatting

* Move TimeRangePicker urlParam management to Discover

* Refactor

* 231: UI: page redirection for unauthenticated (#279)

* 231: Add redirection

* remove console.logs

* remove println

* apply hacky fix for create too

* fix bug on refresh social/create

* small fix

* fix code review points

* Delete Post When Last Member Leaves (#285)

* Add PostService.DeletePost

* Remove post when leaving as last member

* Allow underscores in C# functions

* Remove owner logic in PostPage

* Go to previous page after leaving post

* Leave post confirmation dialog

* small fix to still include sender even when the user has left the chat

---------

Co-authored-by: evan-scales <[email protected]>

* Create Component Initial cleanup (#199)

* Initial cleanup

* Change default values to null and change description style

* Fix linting and Prettier issues

* Fixed end time default behavior

* add game selector

* show game as required

---------

Co-authored-by: evan-scales <[email protected]>

* 57: List Friends UI  (#286)

* 57: Updated RelationsControler and made SPA relationService

* ran formatter

* 57: Created inital user card

* 57: Created UserCard and able to view friends/requested/pending

* Added label and fixed broken build

* fix underline

* ran formatter

* Added comments

* fix broken create post

* Fixed bug

* Removed unnessecary comment

* Fixed formatting issue

* Friend button (#292)

* Refactor relation service

* Add friend request/accept/unfriend button

* small fixes

---------

Co-authored-by: evan-scales <[email protected]>

* Use MUI Theming (#312)

* Remove hardcoded header colors

* Use MUI CssBaseline

* Remove styleComponents.js

* Setup MUI palette

* Navbar use primary palette color

* Post card use palette colors

* User card use palette colors

* Use Pallete colors instead of hardcoded

* Formatting

* Set default MUI Chip style

* fix signup theme

* Extract colors to const

* Set background colors to purple

* fix undefined PRIMARY_MAIN

---------

Co-authored-by: evan-scales <[email protected]>

* Basic user search (#313)

* 57: Updated RelationsControler and made SPA relationService

* ran formatter

* 57: Created inital user card

* 57: Created UserCard and able to view friends/requested/pending

* Added label and fixed broken build

* fix underline

* ran formatter

* added user search page

* created player discover page

* player cards

* already created in branch 57

* use user card

* build user query string

* api request

* puts users on page and can search

* added widget

* clean up

* fixed tabs to save state

* added pagination for users

* got rid of player discover page

* clean up

* fixed pagination while switching from upcoming posts to users

* ran formatter

* changed labels, added conditional statement to post filters, moved tab selector to the top

* remove not needed function call (caused flicker on inital page load)

* changed to select

---------

Co-authored-by: evan-scales <[email protected]>

* Merge pull request #273 from SCCapstone/main (#315)

---------

Co-authored-by: Jackson Williams <[email protected]>
Co-authored-by: epadams <[email protected]>
Co-authored-by: James Pretorius <[email protected]>
Co-authored-by: James Pretorius <[email protected]>
Co-authored-by: Ethan Adams <[email protected]>
Co-authored-by: Jackson Williams <[email protected]>
  • Loading branch information
7 people authored Feb 24, 2024
1 parent 82d315b commit 5feb2fa
Show file tree
Hide file tree
Showing 48 changed files with 1,938 additions and 501 deletions.
3 changes: 3 additions & 0 deletions FU.API/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ dotnet_diagnostic.SA1201.severity = none
# Disabled for long condition clarity
dotnet_diagnostic.SA1009.severity = none

# Disable remove underscores in funciton name for xUnit naming conventions
dotnet_diagnostic.CA1707.severity = none

dotnet_diagnostic.SA1309.severity = none
dotnet_diagnostic.SA1101.severity = none
dotnet_diagnostic.SA1600.severity = none
Expand Down
3 changes: 1 addition & 2 deletions FU.API/FU.API.Tests/RelationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public async void HandleRelationAction_WithValidUsersAndAction_CantRemoveBlocked

private static RelationService CreateRelationService(AppDbContext context)
{
var searchService = new SearchService(context);
return new RelationService(context, searchService);
return new RelationService(context);
}
}
10 changes: 6 additions & 4 deletions FU.API/FU.API/Controllers/PostsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public async Task<IActionResult> LeavePost(int postId)
return NotFound();
}

if (user.UserId == post.CreatorId)
await _postService.LeavePost(post.Id, user);

// Delete post if there are no other users in the post
var postMembers = await _postService.GetPostUsers(postId);
if (!postMembers.Any())
{
return Forbid("Creator cannot leave post");
await _postService.DeletePost(postId);
}

await _postService.LeavePost(post.Id, user);

return NoContent();
}

Expand Down
8 changes: 8 additions & 0 deletions FU.API/FU.API/Controllers/RelationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public async Task<IActionResult> GetRelationStatus(int userId)

var relation = await _relationService.GetRelation(currentUser.UserId, userId);

if (relation is null)
{
relation = new UserRelation
{
Status = UserRelationStatus.None
};
}

var response = relation.ToDto();
return Ok(response);
}
Expand Down
2 changes: 0 additions & 2 deletions FU.API/FU.API/DTOs/User/UserRelationDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

public class UserRelationDTO
{
public UserProfile User { get; set; } = new UserProfile();

public string Status { get; set; } = string.Empty;
}
3 changes: 1 addition & 2 deletions FU.API/FU.API/Helpers/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static PostQuery ToPostQuery(this PostSearchRequestDTO dto)
query.SortType = arr[0] switch
{
"players" => PostSortType.NumberOfPlayers,
"soonest" => PostSortType.NewestCreated,
"soonest" => PostSortType.EarliestToScheduledTime,
"newest" => PostSortType.NewestCreated,
"title" => PostSortType.Title,
_ => PostSortType.NewestCreated
Expand Down Expand Up @@ -246,7 +246,6 @@ public static UserRelationDTO ToDto(this UserRelation relation)
{
return new UserRelationDTO()
{
User = relation.User1.ToProfile(),
Status = relation.Status.ToString(),
};
}
Expand Down
2 changes: 2 additions & 0 deletions FU.API/FU.API/Interfaces/IPostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface IPostService : ICommonService

Task LeavePost(int postId, ApplicationUser user);

Task DeletePost(int postId);

Task<IEnumerable<ApplicationUser>> GetPostUsers(int postId);
}
2 changes: 1 addition & 1 deletion FU.API/FU.API/Interfaces/IRelationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface IRelationService : ICommonService

Task RemoveRelation(int initiatedById, int otherUserId);

Task<UserRelation> GetRelation(int initiatedById, int otherUserId);
Task<UserRelation?> GetRelation(int initiatedById, int otherUserId);
}
5 changes: 5 additions & 0 deletions FU.API/FU.API/Models/UserRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public enum UserRelationStatus
/// User1 is blocked by User2
/// </summary>
BlockedBy,

/// <summary>
/// No relation.
/// </summary>
None,
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions FU.API/FU.API/Services/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public async Task<Chat> CreateChat(ApplicationUser user, ChatType chatType, stri
.Where(c => c.Id == chatId)
.SelectMany(c => c.Messages)
.OrderByDescending(m => m.CreatedAt)
.Include(m => m.Sender)
.Skip((offset - 1) * limit)
.Take(limit)
.Reverse()
Expand Down
42 changes: 42 additions & 0 deletions FU.API/FU.API/Services/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public async Task<Post> CreatePost(Post post)
throw new PostException("Start time cannot be after end time", HttpStatusCode.UnprocessableEntity);
}

// Find how long the post will last
if (post.StartTime is not null && post.EndTime is not null)
{
var duration = post.EndTime - post.StartTime;
if (duration.Value.TotalMinutes < 30)
{
throw new PostException("Post must last at least 30 minutes", HttpStatusCode.UnprocessableEntity);
}

if (duration.Value.TotalHours > 24)
{
throw new PostException("Post must last at most 24 hours", HttpStatusCode.UnprocessableEntity);
}
}

var postTagIds = post.Tags.Select(t => t.TagId);
var tags = await _dbContext.Tags
.Where(t => postTagIds.Contains(t.Id))
Expand Down Expand Up @@ -201,4 +216,31 @@ public async Task LeavePost(int postId, ApplicationUser user)

return;
}

public async Task DeletePost(int postId)
{
// Find everything associated with a post
var post = _dbContext.Posts.Find(postId) ?? throw new PostNotFoundException();
var postMessages = _dbContext.Messages.Where(m => m.ChatId == post.ChatId).ToList();
var chatMemberships = _dbContext.ChatMemberships.Where(cm => cm.ChatId == post.ChatId).ToList();
var chat = _dbContext.Chats.Find(post.ChatId);

// Delete everything found
if (chat is not null)
{
// Break dependency on last message to allow for deletion
chat.LastMessageId = null;
_dbContext.Chats.Update(chat);
await _dbContext.SaveChangesAsync();

// Delete Chat
_dbContext.Chats.Remove(chat);
}

_dbContext.Posts.Remove(post);
_dbContext.Messages.RemoveRange(postMessages);
_dbContext.ChatMemberships.RemoveRange(chatMemberships);

await _dbContext.SaveChangesAsync();
}
}
11 changes: 2 additions & 9 deletions FU.API/FU.API/Services/RelationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
public class RelationService : CommonService, IRelationService
{
private readonly AppDbContext _dbContext;
private readonly ISearchService _searchService;

public RelationService(AppDbContext dbContext, ISearchService searchService)
public RelationService(AppDbContext dbContext)
: base(dbContext)
{
_dbContext = dbContext;
_searchService = searchService;
}

public async Task<UserRelation> GetRelation(int initiatedById, int otherUserId)
public async Task<UserRelation?> GetRelation(int initiatedById, int otherUserId)
{
if (initiatedById == otherUserId)
{
Expand All @@ -31,11 +29,6 @@ public async Task<UserRelation> GetRelation(int initiatedById, int otherUserId)

var relation = await _dbContext.UserRelations.Where(r => r.User1Id == initiatedById && r.User2Id == otherUserId).FirstOrDefaultAsync();

if (relation is null)
{
throw new NotFoundException("Relation not found", "The requested relation was not found");
}

return relation;
}

Expand Down
1 change: 0 additions & 1 deletion FU.SPA/src/App.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#root {
/* background-color: #23194f; */
height: 100vh;
}
9 changes: 6 additions & 3 deletions FU.SPA/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import SignIn from './components/pages/SignIn';
import SignUp from './components/pages/SignUp';
import PostPage from './components/pages/PostPage';
import UserProfile from './components/pages/UserProfile';

import { ThemeProvider } from '@mui/material/styles';
import Theme from './Theme';
import CssBaseline from '@mui/material/CssBaseline';
import { Route, Routes } from 'react-router-dom';
import { ProtectedRoute } from './components/ProtectedRoute';
import UserProvider from './context/userProvider';
import './App.css';

function App() {
return (
<>
<ThemeProvider theme={Theme}>
<CssBaseline />
<UserProvider>
<Navbar />
<div className="container">
Expand Down Expand Up @@ -48,7 +51,7 @@ function App() {
</Routes>
</div>
</UserProvider>
</>
</ThemeProvider>
);
}

Expand Down
40 changes: 40 additions & 0 deletions FU.SPA/src/Theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createTheme } from '@mui/material/styles';

const COLORS = {
PRIMARY_MAIN: '#e354dc',
SECONDARY_MAIN: '#4290f5',
BACKGROUND_PAPER: '#31084a',
BACKGROUND_DEFAULT: '#23194f',
};

const Theme = createTheme({
palette: {
mode: 'dark',
primary: {
main: COLORS.PRIMARY_MAIN,
},
secondary: {
main: COLORS.SECONDARY_MAIN,
},
background: {
paper: COLORS.BACKGROUND_PAPER,
default: COLORS.BACKGROUND_DEFAULT,
},
},
components: {
MuiChip: {
defaultProps: {
variant: 'outlined',
},
styleOverrides: {
root: {
color: COLORS.PRIMARY_MAIN,
borderColor: COLORS.PRIMARY_MAIN,
border: '2px solid ${COLORS.PRIMARY_MAIN}',
},
},
},
},
});

export default Theme;
6 changes: 1 addition & 5 deletions FU.SPA/src/components/Chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
gap: 10px;

input {
border: 1px solid #e340dc;
border-radius: 4px;
color: #fff;
/* Set width to 800px to takeup whole width */
width: 800px;
}

button {
background-color: #23194f;
/* background-color: #23194f; */
height: 100%;
color: #e340dc;
width: 100px;
}
}
Expand Down
18 changes: 12 additions & 6 deletions FU.SPA/src/components/Chat.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useState, useContext } from 'react';
import {
TextField,
Card,
CardActions,
Button,
CardContent,
TextField,
} from '@mui/material';
import {
joinChatGroup,
Expand Down Expand Up @@ -32,8 +32,8 @@ export default function Chat({ chatId }) {
try {
const chat = await getChat(chatId);
setChat(chat);
// sleep to allow the signalr connection to be established
await new Promise((resolve) => setTimeout(resolve, 40));
// See #281: We need to wait for the signalR connection to be started before joining the chat
await new Promise((resolve) => setTimeout(resolve, 80));
await joinChatGroup(chatId);
const messages = await getMessages(chatId, 1, limit);
setMessages(messages);
Expand Down Expand Up @@ -110,7 +110,9 @@ export default function Chat({ chatId }) {

useEffect(() => {
// Scroll to the bottom when messages are updated
const chatContainer = document.querySelector('.MuiCardContent-root');
const chatContainer = document
.querySelector('.chat-card')
.querySelector('.MuiCardContent-root');
const scrollDifference = chatContainer.scrollHeight - prevScrollHeight;

if (scrollDifference > 0) {
Expand All @@ -123,9 +125,9 @@ export default function Chat({ chatId }) {

return (
<Card
className="chat-card"
style={{
textAlign: 'left',
backgroundColor: '#31084A',
width: '700px',
height: '90%',
display: 'flex',
Expand Down Expand Up @@ -168,7 +170,11 @@ export default function Chat({ chatId }) {
}
}}
/>
<Button onClick={handleSendMessage} className="send-button">
<Button
variant="outlined"
onClick={handleSendMessage}
className="send-button"
>
Send
</Button>
</CardActions>
Expand Down
8 changes: 5 additions & 3 deletions FU.SPA/src/components/ChatLocked.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ export default function ChatLocked({ chatType, reason, onResolutionClick }) {
};

const renderResolution = () => {
// get the current path
var path = window.location.pathname;
let resolutionMessage = reason === 'no-user' ? 'Sign In' : 'Join';
return (
<Button
style={{ backgroundColor: '#E340DC', color: '#FFF', width: '95%' }}
variant="contained"
style={{ width: '95%' }}
onClick={() => {
if (reason === 'no-user') {
navigate('/signin');
navigate('/signin?returnUrl=' + encodeURIComponent(path));
}

if (onResolutionClick) {
Expand All @@ -53,7 +56,6 @@ export default function ChatLocked({ chatType, reason, onResolutionClick }) {
<Card
style={{
textAlign: 'left',
backgroundColor: '#31084A',
width: '700px',
height: '90%',
minHeight: '100px',
Expand Down
9 changes: 6 additions & 3 deletions FU.SPA/src/components/ChatMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { useNavigate } from 'react-router-dom';
export default function ChatMessage({ chatMessage, userIsSender }) {
const user = chatMessage.sender;
const navigate = useNavigate();
const defaultPfp = user?.pfpUrl.includes(
'https://tr.rbxcdn.com/38c6edcb50633730ff4cf39ac8859840/420/420/Hat/Png',
);
const defaultPfp =
!user.pfpUrl ||
(user.pfpUrl !== null &&
user.pfpUrl.includes(
'https://tr.rbxcdn.com/38c6edcb50633730ff4cf39ac8859840/420/420/Hat/Png',
));

const timeDifference = (timestamp) => {
const messageDate = new Date(timestamp);
Expand Down
Loading

0 comments on commit 5feb2fa

Please sign in to comment.