import React from 'react' import styles from '../../public/bin/style/gallery.module.css' import PartTag from './PartTag'; import { useEffect, useRef, useState } from 'react'; const BinPost = ({title = "Bin Post", desc = "Bin Project", slack = '', link = '', id, date, parts}) => { link = link.trim(); if (!/^https?:\/\//i.test(link)) { link = 'https://' + link; } const projectID = link.split('/')[4] const imgLink = `https://thumbs.wokwi.com/projects/${projectID}/social/bin.png` function handleClick() { if (typeof window !== 'undefined'){ const currentHost = window.location.host; window.open(link, '_blank'); } } function formatDate(dateString) { const inputDate = new Date(dateString); const now = new Date(); const oneDay = 24 * 60 * 60 * 1000; // Number of milliseconds in one day // Check if the input date is within the last 24 hours if (now - inputDate < oneDay) { const hours = inputDate.getHours().toString().padStart(2, '0'); const minutes = inputDate.getMinutes().toString().padStart(2, '0'); return `Today at ${hours}:${minutes}`; } else { // Format the date to "Month day, year" const options = { year: 'numeric', month: 'long', day: 'numeric' }; return inputDate.toLocaleDateString(undefined, options); } } if (parts){ parts = parts.filter(part => part !== "recvK14pXAY1tn3HQ" && part !== "rec5TQNvkGkscsGuQ"); //Filter out breadboards and raspberry pi } return (
{desc}
{(slack ? (slack.startsWith('@') ? (slack) : (`@${slack}`)) : (""))+ " "} {formatDate(date)}