Skip to content

Commit

Permalink
Feature/26 add post feature (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathias Havekes <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Theo Auffeuvre <[email protected]>
  • Loading branch information
4 people authored Mar 27, 2024
1 parent caa5f07 commit 0c23345
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ For backend

```shell
# In another CLI
npm install -g @mockoon/cli
cd releaf-canopeum/canopeum_frontend
mockoon-cli start --data canopeum-mockoon.json
cd canopeum_frontend
npm run mockoon
```

### Folder Architecture
Expand Down
20 changes: 20 additions & 0 deletions canopeum_frontend/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ body {
display: flex;
text-align: center;
}

.btn-secondary {
color: #fff;
}

.btn-secondary:hover {
color: #fff;
}

.form-control::placeholder {
color: map-get($theme-colors, light-gray);
}

.form-control {
color: $default-text-color;
}

.form-control:focus {
color: $default-text-color;
}
5 changes: 3 additions & 2 deletions canopeum_frontend/src/assets/styles/theme-variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ $theme-colors: (
warning: $yellow,
danger: $red,
light: $gray-100,
dark: $gray-800
dark: $gray-800,
light-gray: #818181,
);
$colors: (
blue: $blue,
Expand All @@ -59,7 +60,7 @@ $colors: (
white: $white,
gray: $gray-600,
gray-dark: $gray-800,
cream: $cream
cream: $cream,
);
$theme-color-interval: 8%;
$table-variants: (
Expand Down
30 changes: 30 additions & 0 deletions canopeum_frontend/src/components/CreatePostWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { SiteSocial } from '../services/api'

const CreatePostWidget = (props: { readonly site: SiteSocial }) => {
/* eslint-disable @typescript-eslint/no-unused-vars -- We'll use this eventually */
// @ts-expect-error: We'll use this eventually
const { site } = props
/* eslint-enable @typescript-eslint/no-unused-vars -- We'll use this eventually */

return (
<div className='bg-white rounded-2 px-5 py-4 d-flex flex-column gap-2'>
<div className='d-flex justify-content-between'>
<h2>New Post</h2>
<button className='btn btn-secondary' type='button'>
Publish
</button>
</div>
<div className='position-relative'>
<div className='position-absolute top-0 left-0 m-3 d-flex gap-3 fs-3'>
<span className='material-symbols-outlined'>mood</span>
<span className='material-symbols-outlined'>add_a_photo</span>
<span className='material-symbols-outlined'>smart_display</span>
</div>
<textarea className='form-control pt-5' id='exampleFormControlTextarea1' placeholder='Post a New Message...'>

Check failure on line 23 in canopeum_frontend/src/components/CreatePostWidget.tsx

View workflow job for this annotation

GitHub Actions / Lint

Empty components are self-closing
</textarea>
</div>
</div>
)
}

export default CreatePostWidget
40 changes: 40 additions & 0 deletions canopeum_frontend/src/components/PostWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import canopeumLogo from '@assets/images/Canopeum_Logo.jpg'

import type { Post } from '../services/api'
import { formatDate } from '../utils/dateFormatter'

const PostWidget = (props: { readonly post: Post }) => {
const { post } = props

return (
<div className='bg-white rounded-2 px-5 py-4 d-flex flex-column gap-3'>
<div className='d-flex justify-content-start gap-2'>
<img alt='site' className='rounded-circle' src={canopeumLogo} style={{ height: '48px', width: '48px' }} />
<div className='d-flex flex-column'>
<div>{post.site.name}</div>
{post.createdAt && <div>{formatDate(post.createdAt.toISOString())}</div>}
</div>
</div>

<div>{post.body}</div>

<div className='d-flex justify-content-end gap-4'>
<div className='d-flex gap-2'>
<span className='material-symbols-outlined'>eco</span>
<div>{post.likeCount}</div>
</div>
<div className='d-flex gap-2'>
<span className='material-symbols-outlined'>sms</span>
<div>{post.commentCount}</div>
</div>
<div className='d-flex gap-2'>
<span className='material-symbols-outlined'>share</span>
<div>{post.shareCount}</div>
</div>
<div />
</div>
</div>
)
}

export default PostWidget
15 changes: 12 additions & 3 deletions canopeum_frontend/src/pages/MapSite.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { AuthenticationContext } from '@components/context/AuthenticationContext'

Check failure on line 1 in canopeum_frontend/src/pages/MapSite.tsx

View workflow job for this annotation

GitHub Actions / Lint

Run autofix to sort these imports!
import SiteSummaryCard from '@components/site/SiteSummaryCard'
import type { SiteSocial } from '@services/api'
import type { Post, SiteSocial } from '@services/api'
import api from '@services/apiInterface'
import { ensureError } from '@services/errors'
import { useContext, useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import CreatePostWidget from '../components/CreatePostWidget'
import PostWidget from '../components/PostWidget'

const MapSite = () => {
const { siteId } = useParams()
Expand Down Expand Up @@ -58,8 +60,15 @@ const MapSite = () => {
</div>
</div>
<div className='col-8'>
<div className='bg-white rounded-2 px-3 py-2'>
<h1>Right</h1>
<div className='rounded-2 d-flex flex-column gap-2'>
{site && (
<>
<CreatePostWidget site={site} />
<div className='d-flex flex-column gap-2'>
{site.posts?.map((post: Post) => <PostWidget key={post.id} post={post} />)}

Check warning on line 68 in canopeum_frontend/src/pages/MapSite.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unsafe call of an `any` typed value

Check warning on line 68 in canopeum_frontend/src/pages/MapSite.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .map on an `any` value
</div>
</>
)}
</div>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions canopeum_frontend/src/utils/dateFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const formatDate = (dateIso: string): string => {
const date = new Date(dateIso)

const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
const year = date.getFullYear()
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')

return `${day}-${month}-${year} ${hours}:${minutes}`
}

0 comments on commit 0c23345

Please sign in to comment.