import styles from './project-view.module.css' import { useState, useEffect } from 'react' import randomNotFoundImg from './random-not-found-img' import { Button, Text } from 'theme-ui' import Icon from '@hackclub/icons' import ReadmeRenderer from './readme-renderer' import YoutubeRenderer from './youtube-renderer' /** @jsxImportSource theme-ui */ function darkenColor(hex, factor) { let r = parseInt(hex.substring(1, 3), 16) let g = parseInt(hex.substring(3, 5), 16) let b = parseInt(hex.substring(5, 7), 16) r = Math.floor(r * factor) g = Math.floor(g * factor) b = Math.floor(b * factor) return ( '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2) ) } function invertColor(hex) { hex = hex.replace(/^#/, '') let r = parseInt(hex.substring(0, 2), 16) let g = parseInt(hex.substring(2, 4), 16) let b = parseInt(hex.substring(4, 6), 16) r = (255 - r).toString(16).padStart(2, '0') g = (255 - g).toString(16).padStart(2, '0') b = (255 - b).toString(16).padStart(2, '0') return `#${r}${g}${b}` } const ProjectView = ({ id, title = 'Title Not Found', description = 'Description Not Found', slack = 'Slack Not Found', scrapbook = '', playLink, images = [], githubProf, user = 'User Not Found', codeLink = '', color = '', textColor = '', screenshot = '', video = '', readMeLink = '', preview, ...props }) => { const [darkColor, setDarkColor] = useState('#000000') const [invertedColor, setInvertedColor] = useState('#000000') const codeHost = codeLink.includes('github') ? 'View on GitHub' : 'View project source' const image = screenshot.length > 1 ? screenshot : [randomNotFoundImg(id)] useEffect(() => { setDarkColor(darkenColor(color, 0.8)) setInvertedColor(invertColor(textColor)) }, [color]) // function convertToRawUrl(githubUrl) { // if (!githubUrl.includes('github.com')) { // // throw new Error('Invalid GitHub URL') // return '' // } // return githubUrl // .replace('github.com', 'raw.githubusercontent.com') // .replace('/blob/', '/') // } const [markdown, setMarkdown] = useState('') useEffect(() => { const fetchMarkdown = async () => { if (readMeLink) { try { const res = await fetch(readMeLink) const text = await res.text() setMarkdown(text) } catch (error) { console.error('Error fetching markdown:', error) setMarkdown('Failed to load markdown content') } } } fetchMarkdown() }, [readMeLink]) return ( // export a css property for each of the color and dark color

{title}

{description != 'Description Not Found' ? description : <>}

{user != 'User Not Found' ? <>By {user} : <>}

{playLink && ( )}
View all my ships
{image != '' && (
Project Image
)} {video.includes('youtube') && } {/* { video != '' && (
)} */}

) } export default ProjectView