-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: type-safing the application, incomplete
- Loading branch information
1 parent
7564000
commit 4fa073f
Showing
21 changed files
with
375 additions
and
44 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
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,8 @@ | ||
import { Footer as Foot } from '@/components/templates/index' | ||
|
||
export const Footer = () => { | ||
return ( | ||
<> | ||
</> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,21 +1,64 @@ | ||
import { CustomButtonProps } from '../../utils'; | ||
import { ShareIcon } from '../icons/components'; | ||
import { ShareIcon } from '@/components/icons/components'; | ||
import { Button, Link } from '@nextui-org/react'; | ||
import { cn } from '@/lib/utils'; | ||
import React, { ElementType } from 'react' | ||
import { CustomButtonProps } from '@/types/frontend/custom-component'; | ||
|
||
const Button = ({title, containerStyles, link, textStyles, isDisabled, share}: CustomButtonProps) => { | ||
const handleClick = () => { | ||
if (link) { | ||
window.open(link, '_blank'); | ||
} | ||
}; | ||
const classes = { | ||
button: '', | ||
content: '', | ||
label: '', | ||
} | ||
|
||
return ( | ||
<button disabled={isDisabled} type="button" className={`custom-btn ${containerStyles}`} onClick={handleClick}> | ||
<span className={`button-text ${textStyles}`}> | ||
{title} | ||
</span> | ||
{share ? <ShareIcon/> : null} | ||
</button> | ||
); | ||
}; | ||
export const CustomButton: React.FC<CustomButtonProps> = ({ | ||
className: classNameFromProps, | ||
disabled, | ||
el: elFromProps = 'link', | ||
href, | ||
label, | ||
newTab, | ||
onClick, | ||
share, | ||
type = 'button', | ||
}) => { | ||
let el = elFromProps | ||
|
||
const newTabProps = newTab ? { target: '_blank', rel: 'noopener noreferrer' } : {} | ||
|
||
const className = [ | ||
classes, | ||
classNameFromProps, | ||
] | ||
.filter(Boolean) | ||
.join(' ') | ||
|
||
export default Button; | ||
const content = ( | ||
<Button className={cn(`${classes.content}`, '')}> | ||
<span className={cn(`${classes.label}`, '')}>{label}</span> | ||
{share && <ShareIcon />} | ||
</Button> | ||
) | ||
|
||
if (onClick || type === 'submit') el = 'button' | ||
|
||
if (el === 'link') { | ||
return ( | ||
<Link href={href || ''} className={cn(className, '')} {...newTabProps} onClick={onClick} target={`_blank`}> | ||
{content} | ||
</Link> | ||
) | ||
} | ||
const Element: ElementType = el | ||
return ( | ||
<Element | ||
href={href} | ||
className={cn(className, '')} | ||
type={type} | ||
{...newTabProps} | ||
onClick={onClick} | ||
disabled={disabled} | ||
> | ||
{content} | ||
</Element> | ||
) | ||
} |
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,16 @@ | ||
import { Card, CardBody, CardFooter, CardHeader, CardProvider, CardSlots, CardVariantProps } from "@nextui-org/react" | ||
export const CustomCard = () => { | ||
return ( | ||
<Card> | ||
<CardHeader> | ||
|
||
</CardHeader> | ||
<CardBody> | ||
|
||
</CardBody> | ||
<CardFooter> | ||
|
||
</CardFooter> | ||
</Card> | ||
) | ||
} |
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,24 @@ | ||
import React, { ElementType, Fragment } from 'react' | ||
|
||
import { CustomImage as Image } from './image/Image' | ||
import { Props } from '@/types/frontend/custom-component' | ||
import { Video } from './video/Video' | ||
|
||
export const Media: React.FC<Props> = props => { | ||
const { className, resource, htmlElement = 'div' } = props | ||
|
||
const isVideo = typeof resource !== 'string' && resource?.mimeType?.includes('video') | ||
const Tag = (htmlElement as ElementType) || Fragment | ||
|
||
return ( | ||
<Tag | ||
{...(htmlElement !== null | ||
? { | ||
className, | ||
} | ||
: {})} | ||
> | ||
{isVideo ? <Video {...props} /> : <Image {...props} />} | ||
</Tag> | ||
) | ||
} |
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,71 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
|
||
import { Props as MediaProps, StaticImageData } from '@/types/frontend/custom-component' | ||
import { Image } from '@nextui-org/react' | ||
import classes from './index.module.scss' | ||
import { cssVariables } from '@/styles/css/cssVariables' | ||
|
||
const { breakpoints } = cssVariables | ||
|
||
export const CustomImage: React.FC<MediaProps> = props => { | ||
const { | ||
imgClassName, | ||
onClick, | ||
onLoad: onLoadFromProps, | ||
resource, | ||
fill, | ||
src: srcFromProps, | ||
alt: altFromProps, | ||
} = props | ||
|
||
const [isLoading, setIsLoading] = React.useState(true) | ||
|
||
let width: number | undefined | ||
let height: number | undefined | ||
let alt = altFromProps | ||
let src: string | StaticImageData = srcFromProps || '' | ||
|
||
if (!src && resource && typeof resource !== 'string') { | ||
const { | ||
width: fullWidth, | ||
height: fullHeight, | ||
filename: fullFilename, | ||
alt: altFromResource, | ||
} = resource | ||
|
||
width = fullWidth | ||
height = fullHeight | ||
alt = altFromResource | ||
|
||
const filename = fullFilename | ||
|
||
src = `${import.meta.env.BASE_URL}/assets/images/${filename}` | ||
} | ||
|
||
// NOTE: this is used by the browser to determine which image to download at different screen sizes | ||
const sizes = Object.entries(breakpoints) | ||
.map(([, value]) => `(max-width: ${value}px) ${value}px`) | ||
.join(', ') | ||
|
||
return ( | ||
<Image | ||
className={[isLoading && classes.placeholder, classes.image, imgClassName] | ||
.filter(Boolean) | ||
.join(' ')} | ||
src={typeof src === 'string' ? src : src.src} | ||
alt={alt || ''} | ||
onClick={onClick} | ||
onLoad={() => { | ||
setIsLoading(false) | ||
if (typeof onLoadFromProps === 'function') { | ||
onLoadFromProps() | ||
} | ||
}} | ||
width={!fill ? width : undefined} | ||
height={!fill ? height : undefined} | ||
sizes={sizes} | ||
/> | ||
) | ||
} |
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,7 @@ | ||
.placeholder-color-light { | ||
background-color: rgba(0, 0, 0, 0.05); | ||
} | ||
|
||
.placeholder { | ||
background-color: rgb(8, 8, 8) | ||
} |
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,45 @@ | ||
'use client' | ||
|
||
import React, { useEffect, useRef } from 'react' | ||
|
||
import { Props as MediaProps } from '@/types/frontend/custom-component'; | ||
|
||
import classes from './index.module.scss' | ||
|
||
export const Video: React.FC<MediaProps> = props => { | ||
const { videoClassName, resource, onClick } = props | ||
|
||
const videoRef = useRef<HTMLVideoElement>(null) | ||
// const [showFallback] = useState<boolean>() | ||
|
||
useEffect(() => { | ||
const { current: video } = videoRef | ||
if (video) { | ||
video.addEventListener('suspend', () => { | ||
// setShowFallback(true); | ||
// console.warn('Video was suspended, rendering fallback image.') | ||
}) | ||
} | ||
}, []) | ||
|
||
if (resource && typeof resource !== 'string') { | ||
const { filename } = resource | ||
|
||
return ( | ||
<video | ||
playsInline | ||
autoPlay | ||
muted | ||
loop | ||
controls={false} | ||
className={[classes.video, videoClassName].filter(Boolean).join(' ')} | ||
onClick={onClick} | ||
ref={videoRef} | ||
> | ||
<source src={`${process.env.NEXT_PUBLIC_SERVER_URL}/media/${filename}`} /> | ||
</video> | ||
) | ||
} | ||
|
||
return null | ||
} |
11 changes: 11 additions & 0 deletions
11
frontend/src/components/custom/media/video/index.module.scss
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,11 @@ | ||
.video { | ||
max-width: 100%; | ||
width: 100%; | ||
background-color: var(--theme-elevation-50); | ||
} | ||
|
||
.cover { | ||
object-fit: cover; | ||
width: 100%; | ||
height: 100%; | ||
} |
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,4 @@ | ||
import FadeIn from "./FadeIn"; | ||
import { ScaleBackground } from './Scale' | ||
|
||
export { FadeIn, ScaleBackground } |
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,13 @@ | ||
import { PropsWithChildren } from 'react' | ||
import { Toaster } from 'sonner' | ||
|
||
export const Events = ({children}:PropsWithChildren) =>{ | ||
return ( | ||
<> | ||
<Toaster /> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export default Events |
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,15 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_APIKEY: string, | ||
readonly VITE_AUTHDOMAIN: string, | ||
readonly VITE_PROJECTID: string, | ||
readonly VITE_STORAGEBUCKET: string, | ||
readonly VITE_MESSAGINGSENDERID: string, | ||
readonly VITE_APPID: string, | ||
readonly VITE_MEASUREMENTID: string | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
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,15 @@ | ||
import { initializeApp } from "firebase/app"; | ||
import { getAnalytics } from "firebase/analytics"; | ||
|
||
const firebaseConfig = { | ||
apiKey: import.meta.env.VITE_APIKEY as string, | ||
authDomain: import.meta.env.VITE_AUTHDOMAIN as string, | ||
projectId: import.meta.env.VITE_PROJECTID as string, | ||
storageBucket: import.meta.env.VITE_STORAGEBUCKET as string, | ||
messagingSenderId: import.meta.env.VITE_MESSAGINGSENDERID as string, | ||
appId: import.meta.env.VITE_APPID as string, | ||
measurementId: import.meta.env.VITE_MEASUREMENTID as string | ||
}; | ||
|
||
const app = initializeApp(firebaseConfig); | ||
const analytics = getAnalytics(app); |
Oops, something went wrong.