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

Deploy to prod #460

Merged
merged 61 commits into from
Apr 1, 2024
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d85de02
removed description duplicate
AaronKeys Mar 2, 2024
650497d
small fixes for on enter, that got removed somehow
AaronKeys Mar 3, 2024
ed4f869
fixing the styling, so it's not as long.
AaronKeys Mar 3, 2024
860c355
added error detection, and code manipulation, but it's not catching t…
AaronKeys Mar 3, 2024
26a9f28
working on validation
AaronKeys Mar 4, 2024
028a30e
error for title showing, but not for game. gives a game is null error.
AaronKeys Mar 4, 2024
76c3981
got passed the null click, but now the game isn't showing up red, as …
AaronKeys Mar 4, 2024
dbf6ca1
not past the gamebox not showing red, but added limits on shortness a…
AaronKeys Mar 4, 2024
ef7565a
wrote a TODO comment for myself with hint at solution.
AaronKeys Mar 4, 2024
436acc0
got the game and title errors displaying
AaronKeys Mar 5, 2024
15fc8d2
removed a lot of commented out code
AaronKeys Mar 5, 2024
9cc29b7
removed more comments.
AaronKeys Mar 5, 2024
4edcdeb
removed more comments
AaronKeys Mar 5, 2024
409a48f
ran npm run format and changed config back
AaronKeys Mar 5, 2024
aa56c8e
Merge branch 'main' into CreatePostCleanUp
AaronKeys Mar 5, 2024
f7a2c76
fixed problem with creating post and error that would still create post
AaronKeys Mar 5, 2024
9f5d24d
Merge branch 'CreatePostCleanUp' of https://github.com/SCCapstone/Pal…
AaronKeys Mar 5, 2024
182b123
saving work after deleting a lot of code that almost, but didn't quit…
AaronKeys Mar 5, 2024
2ec9fa3
made it so if there were more than 3 characters, the warning text dis…
AaronKeys Mar 6, 2024
cd774dc
fixed the value to short for game on the error message, but must fix …
AaronKeys Mar 6, 2024
1e30f74
got several problems fixed with error.
AaronKeys Mar 6, 2024
225a967
removed unnessary commented out code.
AaronKeys Mar 6, 2024
4ff06a0
config fix
AaronKeys Mar 6, 2024
ad44e1a
ran npm run format
AaronKeys Mar 6, 2024
9bfae7e
small changes
AaronKeys Mar 7, 2024
c3263f6
lint format
AaronKeys Mar 7, 2024
4bd3ec3
changes to createpostcleanup
AaronKeys Mar 11, 2024
5507506
changing code to remove some errors, but there is at least one error …
AaronKeys Mar 23, 2024
df59402
fixing two errors related to game usestate not being set to null.
AaronKeys Mar 23, 2024
1bb1e85
create post cleanup seems to be working correctly.
AaronKeys Mar 23, 2024
b7ae0a0
Update config.js
AaronKeys Mar 23, 2024
86cb937
ran format
AaronKeys Mar 23, 2024
7cb0b7f
removal of unnecessary comments and code.
AaronKeys Mar 23, 2024
8f7b9b0
Update CreatePost.jsx
AaronKeys Mar 23, 2024
97d5ddc
Merge branch 'CreatePostCleanUp' of https://github.com/SCCapstone/Pal…
AaronKeys Mar 23, 2024
ad5f2a4
Merge branch 'main' into CreatePostCleanUp
AaronKeys Mar 23, 2024
e0199a7
Update CreatePost.jsx
AaronKeys Mar 23, 2024
4d1b78b
Update CreatePost.jsx
AaronKeys Mar 23, 2024
82d9eed
Update CreatePost.jsx
AaronKeys Mar 23, 2024
56a3eff
Update CreatePost.jsx
AaronKeys Mar 23, 2024
9ed4838
ran format
AaronKeys Mar 23, 2024
a28f9f2
errors dont show initially
AaronKeys Mar 23, 2024
aeb4099
disabled button
AaronKeys Mar 24, 2024
2f05074
Delete FU.SPA/src/config.js
AaronKeys Mar 24, 2024
92e988f
Delete FU.SPA/src/components/Selectors.jsx
AaronKeys Mar 24, 2024
6633766
trying to fix bug
AaronKeys Mar 24, 2024
62e8c28
merge
AaronKeys Mar 24, 2024
56738dd
run format
AaronKeys Mar 24, 2024
f5ec819
lint and format
AaronKeys Mar 24, 2024
2f7f7f4
npm run lint and format
AaronKeys Mar 24, 2024
63719aa
changed config
AaronKeys Mar 24, 2024
9ab1660
added starttime error and tried to check for it, but it doesn't appea…
AaronKeys Mar 31, 2024
3192e1c
small changes to starttime and error message
AaronKeys Mar 31, 2024
1b6cad7
Finished error checking for start end time, cleaned up state management
epadams Apr 1, 2024
38efd03
Cleaned up formatting and linting
epadams Apr 1, 2024
7292dbe
Merge from main
epadams Apr 1, 2024
147d023
Remove config.js changes
epadams Apr 1, 2024
ac74eac
Merge pull request #358 from SCCapstone/CreatePostCleanUp
epadams Apr 1, 2024
21a7478
hotfix
epadams Apr 1, 2024
bc510d3
Merge pull request #459 from SCCapstone/hotfix
AaronKeys Apr 1, 2024
09b13db
Merge branch 'prod' into main
evan-scales Apr 1, 2024
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
176 changes: 147 additions & 29 deletions FU.SPA/src/components/pages/CreatePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,93 @@ export default function CreatePost() {
const { user } = useContext(UserContext);
const [game, setGame] = useState(null);
const [title, setTitle] = useState('');
const [startTime, setStartTime] = useState(dayjs().add(30, 'minute'));
const [endTime, setEndTime] = useState(dayjs().add(35, 'minute'));
const [startTime, setStartTime] = useState(dayjs().add(5, 'minute'));
const [endTime, setEndTime] = useState(dayjs().add(15, 'minute'));
const [description, setDescription] = useState('');
const [tags, setTags] = useState([]);
const navigate = useNavigate();

const [gameError, setGameError] = useState('');
const [titleError, setTitleError] = useState('');
const [startDateError, setStartDateError] = useState('');
const [endDateError, setEndDateError] = useState('');

const [isEnabled, setIsEnabled] = useState(false);

// Checks for the length
useEffect(() => {
if (title.length >= 3 && game?.name.length >= 3) {
setIsEnabled(true);
} else {
setIsEnabled(false);
}
}, [title, game, isEnabled]);

// Handles title state error
const handleTitleChange = (e) => {
if (e.target.value < 3) {
setTitleError('Title must be longer than 3 characters');
setTitle(e.target.value);
} else {
setTitle(e.target.value);
setTitleError('');
}
};

// Handles game state error
const handleGameChange = (e) => {
if (e.length < 3) {
setGameError('Game must be longer than 3 characters');
setGame(e);
} else {
setGameError('');
setGame(e);
}
};

// Handles start date state error
const handleStartDateChange = (e) => {
if (e.isBefore(dayjs())) {
setStartDateError('Time cannot be before current time');
setStartTime(e);
} else if (e.isAfter(endTime)) {
setStartDateError('Time cannot be after end time');
setStartTime(e);
} else {
setStartDateError('');
setStartTime(e);
}
};

// Handles end date state error
const handleEndDateChange = (e) => {
if (e.isAfter(dayjs().add(24, 'hours'))) {
setEndDateError('Time cannot exceed 24 hours');
setEndTime(e);
} else if (e.isBefore(startTime)) {
setEndDateError('Time cannot be before start time');
setEndTime(e);
} else {
setEndDateError('');
setEndTime(e);
}
};

const handleSubmit = async (e) => {
e.preventDefault();

let tagIds = [];

// Gets tags from API or creates them
for (const tag of tags) {
const newTag = await TagService.findOrCreateTagByName(tag.name);
tagIds.push(newTag.id);
}

// Gets game from API or creates it
var findGame = await GameService.findOrCreateGameByTitle(game.name);

// Form payload
const post = {
title: title,
description: description,
Expand All @@ -57,7 +126,7 @@ export default function CreatePost() {
const newPost = await PostService.createPost(post);
navigate(`/posts/${newPost.id}`);
} catch (e) {
window.alert('Error creating post');
window.alert(e);
console.error(e);
}
};
Expand Down Expand Up @@ -97,7 +166,7 @@ export default function CreatePost() {
<Box
sx={{
marginTop: 1,
m: 4,
m: 0,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
Expand All @@ -117,59 +186,78 @@ export default function CreatePost() {
sx={{
display: 'flex',
flexDirection: 'column',
mt: 3,
gap: 2,
mt: 0,
gap: 1,
}}
>
<TextField
required
fullWidth
error={title?.length < 3}
id="searchGames"
label="Title"
helperText={titleError}
minLength={3}
maxLength={25}
label="Title *"
autoFocus
value={title}
onChange={(e) => setTitle(e.target.value)}
onChange={handleTitleChange}
/>
<Grid item xs={12}>
<GameSelector onChange={setGame} />
<Grid item xs={0}>
<GameSelector
onChange={handleGameChange}
helperText={gameError}
error={game?.length < 3}
/>
</Grid>
<br />
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateTimePicker
label="Start Time"
value={startTime}
onChange={(newValue) => setStartTime(newValue)}
onChange={handleStartDateChange}
slotProps={{
textField: {
fullWidth: true,
error:
startTime.isBefore(dayjs()) || startTime.isAfter(endTime),
helperText: startDateError,
},
}}
/>
<DateTimePicker
label="End Time"
value={endTime}
onChange={(newValue) => setEndTime(newValue)}
helperText={endDateError}
onChange={handleEndDateChange}
slotProps={{
textField: {
fullWidth: true,
error:
endTime.isAfter(dayjs().add(24, 'hours')) ||
endTime.isBefore(startTime),
helperText: endDateError,
},
}}
/>
</LocalizationProvider>
<TagsSelector onChange={setTags} />
<Box
sx={{
display: 'flex',
}}
>
<Typography component="h1" variant="h6">
{' '}
{/* Need to have 2 radius buttons below for 'Any' and 'Between' */}
Description
</Typography>
</Box>
></Box>
<TextField
label="Description"
value={description}
onChange={(e) => setDescription(e.target.value)}
multiline
></TextField>

<Button
type="submit"
fullWidth
variant="contained"
sx={{ mt: 3, mb: 2 }}
sx={{ mt: 0, mb: 0 }}
disabled={!isEnabled}
>
Create Post
</Button>
Expand All @@ -183,15 +271,37 @@ const checkboxIconBlank = <CheckBoxOutlineBlankIcon fontSize="small" />;
const checkboxIconChecked = <CheckBoxIcon fontSize="small" />;
const filter = createFilterOptions();

// Game selector that displays a drop down and lets you choose a game
// or create one
const GameSelector = ({ onChange }) => {
const [gammeOptions, setGameOptions] = useState([]);
const [gameOptions, setGameOptions] = useState([]);
const [value, setValue] = useState('');
const [error, setError] = useState(false);

useEffect(() => {
GameService.searchGames('').then((games) => setGameOptions(games));
const fetchGameOptions = async () => {
try {
GameService.searchGames('').then((games) => setGameOptions(games));
GameService.searchGames('').then((games) => setGameOptions(games));
} catch (err) {
console.error(err);
}
};
fetchGameOptions();
}, []);

const onInputChange = (event, newValue) => {
try {
setValue(newValue);
if (newValue && newValue.name && newValue.name.length < 3) {
setError(true);
} else {
setError(false);
}
onChange(newValue);
} catch (err) {
setError(true);
}
setValue(newValue);
onChange(newValue);
};
Expand All @@ -215,27 +325,34 @@ const GameSelector = ({ onChange }) => {

return (
<Autocomplete
autoHighlight
clearOnBlur
value={value}
onChange={onInputChange}
options={gammeOptions}
disableCloseOnSelect
options={gameOptions}
filterOptions={onFilterOptions}
getOptionLabel={(o) => (o ? o.name : '')}
isOptionEqualToValue={(option, value) => option.name === value.name}
renderOption={(props, option) => <li {...props}>{option.name}</li>}
renderInput={(params) => (
<TextField
{...params}
label="Game"
required
placeholder="Select or create a game"
fullWidth
error={error}
label="Game *"
minLength={3}
maxLength={25}
helperText={
error || value === null ? 'Must be at least 3 characters' : ''
}
/>
)}
/>
);
};

// Tag selector that displays a drop down and lets you choose a tag
// or create one
const TagsSelector = ({ onChange }) => {
const [tagOptions, setTagOptions] = useState([]);
const [value, setValue] = useState([]);
Expand Down Expand Up @@ -278,6 +395,7 @@ const TagsSelector = ({ onChange }) => {

return (
<Autocomplete
autoHighlight
multiple
clearOnBlur
value={value}
Expand Down
Loading