-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11cf1fb
commit 767008a
Showing
7 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import styles from "@/styles/components/postfeed.module.css"; | ||
import Link from "next/link"; | ||
import {getFilePath} from "@/lib/data"; | ||
import {useEffect, useState} from "react"; | ||
import {makeCachedRequest} from "@/lib/api_tools"; | ||
import {ADMIN_USER_TYPE, EDITOR_USER_TYPE, MEMBER_USER_TYPE} from "@/lib/users"; | ||
import {getNamesInPreference, macronCodeToChar, numberDictionary} from "@/lib/plant_data"; | ||
import {InfiniteLoading} from "@/components/infinteLoading"; | ||
import {QueryClient, QueryClientProvider} from "@tanstack/react-query"; | ||
import Image from "next/image"; | ||
|
||
interface PostCardProps { | ||
post_title: string, | ||
post_image: string, | ||
post_user_id: number, | ||
post_plant_id: number, | ||
post_date: string, | ||
id: number, | ||
} | ||
|
||
export function PostFeedCard(props: PostCardProps) { | ||
|
||
const [plantName, setPlantName] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
const fetchData = async () => { | ||
|
||
// Get the plant information | ||
const plants = await makeCachedRequest('plants_names_all', '/api/plants/search?getNames=true&getUnpublished=true'); | ||
const plant = plants.find((plant: any) => plant.id === props.post_plant_id); | ||
if(plant != null) { | ||
let name = macronCodeToChar(getNamesInPreference(plant)[0], numberDictionary); | ||
|
||
// Check if the name is too long | ||
if(name.length > 15) { | ||
name = name.substring(0, 15) + ".."; | ||
} | ||
|
||
setPlantName(name); | ||
} | ||
|
||
} | ||
|
||
return ( | ||
<div onClick={ | ||
() => { | ||
window.location.href = `/plants/${props.post_plant_id}`; | ||
} | ||
} className={styles.postCard}> | ||
<Image fill src={getFilePath(props.post_user_id, props.id, props.post_image)} alt={props.post_title}/> | ||
<div className={styles.postCardText}> | ||
<h1>{props.post_title}</h1> | ||
<p>{plantName}</p> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default function PostFeed() { | ||
const queryClient = new QueryClient() | ||
|
||
return ( | ||
<> | ||
<div className={styles.postFeed}> | ||
<div className={styles.postFeedHeader}> | ||
<h1>Post Feed</h1> | ||
</div> | ||
<div className={styles.postGrid}> | ||
<QueryClientProvider client={queryClient}> | ||
<InfiniteLoading | ||
searchQuery={"/api/posts/fetch?operation=siteFeed"} | ||
display={"PostFeedCard"} | ||
/> | ||
</QueryClientProvider> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.postFeed{ | ||
width: 100%; | ||
} | ||
|
||
.postFeedHeader{ | ||
text-align: center; | ||
margin-bottom: 20px; | ||
font-weight: 500; | ||
font-size: 64px; | ||
color: var(--text-dark); | ||
padding: 5%; | ||
} | ||
|
||
/* Instagram like grid that displays the posts */ | ||
.postGrid{ | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
gap: 20px; | ||
justify-content: center; | ||
padding: 5%; | ||
align-items: center; | ||
} | ||
|
||
/*make the button span the entire width of the container */ | ||
.postGrid button{ | ||
grid-column: 1 / -1; | ||
margin-top: 20px; | ||
padding: 10px; | ||
width: 80%; | ||
margin-left: 10%; | ||
} | ||
|
||
.postCard{ | ||
background-color: var(--secondary-gray); | ||
border-radius: 10px; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
overflow: hidden; | ||
position: relative; | ||
cursor: pointer; | ||
width: 300px; | ||
height: 300px; | ||
} | ||
|
||
.postCard img{ | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
/* post card text at the bottom of the card with a gradient background fading from black to transparent */ | ||
.postCardText{ | ||
position: absolute; | ||
bottom: 0; | ||
width: 100%; | ||
padding: 10px; | ||
background: linear-gradient(0deg, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); | ||
color: white; | ||
font-size: 16px; | ||
} | ||
|
||
.postCard:hover p { | ||
opacity: 1; | ||
color: #94c47d; | ||
} | ||
|
||
.postCardText p{ | ||
opacity: 0.8; | ||
} | ||
|
||
/* On hover, the post card text will slide up to reveal the post, make sure the gradient background is still visible */ | ||
.postCard:hover .postCardText{ | ||
background: linear-gradient(0deg, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.5)); | ||
font-size: 18px; | ||
transition: 0.01s; | ||
} |