Skip to content

Commit

Permalink
Merge branch 'subevents' into updatePost
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Tønnessen authored Oct 13, 2020
2 parents 0c88b58 + 3c3e3e6 commit a02ddc5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/BackOffice/AddPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const AddPost = ({
});

const [id] = useState(post.id);
const [timeOnEveryPost] = useState(post.timeOnEveryPost);
const [title, setTitle] = useState(post.title);
const [startGroup, setGroup] = useState(post.startGroup);
const [address, setAddress] = useState(post.address);
Expand All @@ -40,7 +39,6 @@ const AddPost = ({
startGroup: startGroup,
address: address,
googleMaps: googleMaps,
timeOnEveryPost: timeOnEveryPost,
}),
[
id,
Expand Down
7 changes: 6 additions & 1 deletion src/BackOffice/CreateNewEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const CreateNewEvent = ({
}
]
);
const [postTime, setPostTime] = useState(0);


/** *************************************************************************** */

Expand Down Expand Up @@ -154,7 +156,8 @@ const CreateNewEvent = ({
from_EN: isMentorBoard ? "the mentor board" : "group leader",
start_time: `${startTimeHour}:${startTimeMinute}`,
groups: groups.sort(groupComparator),
posts: posts
posts: posts,
post_time: postTime,
};

if (address.length >= 3) {
Expand Down Expand Up @@ -348,6 +351,8 @@ const CreateNewEvent = ({
setPosts={setPosts}
errors={errors}
setErrors={setErrors}
postTime={postTime}
setPostTime={setPostTime}
/>
)}

Expand Down
11 changes: 3 additions & 8 deletions src/BackOffice/EventWithPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import AddEventButton from "./AddEventButton";
import uuid from "react-uuid";
import { Form, Input } from "semantic-ui-react";

const EventWithPosts = ({ selectedGroups, posts, setPosts }) => {
const [timeOnEveryPost, setTimeOnEveryPost] = useState(""); // need to change that i it only can be numbers,
// isteden for at den blir med inni til addpost kan tiden bli lagt på objektene når alle er lagt til altså på sumit
const EventWithPosts = ({ selectedGroups, posts, setPosts, setPostTime, postTime }) => {

const newPost = {
id: uuid(),
Expand Down Expand Up @@ -42,12 +40,9 @@ const EventWithPosts = ({ selectedGroups, posts, setPosts }) => {
<Input
className="time-input"
placeholder="00"
value={timeOnEveryPost}
value={postTime }
onChange={(_, data) => {
setTimeOnEveryPost(data.value);
posts.forEach(element => {
element.timeOnEveryPost = data.value;
});
setPostTime(data.value);
}}
type="number"
autoComplete="off"
Expand Down
10 changes: 7 additions & 3 deletions src/Frontend/Mainscreen/Event.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as SolidIcons from '@fortawesome/free-solid-svg-icons';
import IconLabel from './IconLabel';
import { AppContext } from '../App';
import { eventTimeComparator, selectField, selectTime, selectGroups } from '../utils';
import { eventTimeComparator, selectField, selectTime, selectGroups, mapTimeOnPosts } from '../utils';
import Posts from "./Posts";
import './event.scss';

Expand Down Expand Up @@ -43,7 +43,11 @@ const Event = ({ data, group }) => {
const link = data.link;
const linkText = selectField(event, 'linkText', lang);
const chevron = open ? SolidIcons["faChevronUp"] : SolidIcons["faChevronDown"];


const sortedPosts = !posts ? [] : posts.sort((p1, p2) => p1.order.indexOf(group.value) - p2.order.indexOf(group.value));

const postsWithTime = mapTimeOnPosts(event, sortedPosts);

return (
<div className="event-wrapper">
<div className="event">
Expand All @@ -67,7 +71,7 @@ const Event = ({ data, group }) => {

{ open && posts && (
<div className="sub-event-wrapper">
{ event.posts.map( e => <Posts key={e.id} post={e} lang={lang}/>) }
{ postsWithTime.map( e => <Posts key={e.id} post={e} lang={lang}/>) }
</div>
)}
<div className="event-chevron" onClick={() => setOpen(!open)}>
Expand Down
7 changes: 5 additions & 2 deletions src/Frontend/Mainscreen/Posts.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import { selectTime } from "../utils";

const Posts = ({ post, lang }) => {

const showUrl = post.googleMaps && post.googleMaps.startsWith('https');
const google_maps = post.googleMaps;



return (
<div className="sub-event">
<div className="sub-event-time-and-title">
<p className="sub-event-time"> rrrrrrr </p>
<p className="sub-event-time"> { selectTime(post) } </p>
<p className="sub-event-title"> { post.title } </p>
</div>
{ showUrl && <a className="sub-event-address" href={google_maps} rel="noopener noreferrer" target="_blank"> { lang === 'NO' ? '(kart)' : '(map)' } </a> }
{ showUrl && <a className="sub-event-address" href={google_maps} rel="noopener noreferrer" target="_blank"> { lang === 'NO' ? '(kart)' : '(map)' } </a> }

</div>
)
Expand Down
31 changes: 31 additions & 0 deletions src/Frontend/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,34 @@ export const selectGroups = ({ groups }, lang) => {
const prefix = language === "NO" ? "Gruppe " : "Group ";
return `${prefix} ${groups.join(", ")}`;
};

const calculateEndTime = (startTime, minUsed) => {
const arr = startTime.split(":");
let hours = Math.floor(parseInt(minUsed) / 60);

let min = parseInt(arr[1]) + parseInt(minUsed);
if (!(min < 60)) {
min -= 60;
}
if (min < 10){
min = "0" + min
}

const final_hours = parseInt(arr[0]) + hours;
const final = final_hours + ":" + min;

return final;

}

export const mapTimeOnPosts = (event, sortedPosts) => {
let start_time = event.start_time;
const post_time = event.post_time;

return sortedPosts.map(post => {
const end_time = calculateEndTime(start_time, post_time);
const updatedPost = { ...post, start_time: start_time, end_time: end_time }
start_time = end_time;
return updatedPost
})
}

0 comments on commit a02ddc5

Please sign in to comment.