Skip to content

Commit

Permalink
nå regnes tidene til de nye subeventene ut, og det viseses
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasSJacobsen committed Oct 12, 2020
1 parent cf02a7f commit 802807d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
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 802807d

Please sign in to comment.