1
+ 'use client'
2
+
3
+ import usePageContext from "@/store/usePageContext" ;
4
+ import { ProductList } from "@/server/types" ;
5
+ import { useEffect , useState } from "react" ;
6
+ import { Button } from "@mantine/core" ;
7
+ import { RepoApi } from "@/server/RepoApi" ;
8
+ import ReactMarkdown from "react-markdown" ;
9
+ import rehypeRaw from "rehype-raw" ;
10
+ import dayjs from "dayjs"
11
+ import relativeTime from "dayjs/plugin/relativeTime"
12
+ import { useRouter } from "next/navigation" ;
13
+ dayjs . extend ( relativeTime )
14
+ export default function MarketPage ( ) {
15
+ const context = usePageContext ( ) ;
16
+ const [ Product , setProduct ] = useState < ProductList | undefined > ( ) ;
17
+ const [ Readme , setReadme ] = useState < string > ( "" )
18
+ const repo_api = new RepoApi ( ) ;
19
+ const nav = useRouter ( ) . replace ;
20
+
21
+ useEffect ( ( ) => {
22
+ if ( context . productCTX ) {
23
+ const ctx = context . productCTX ;
24
+ setProduct ( ctx ) ;
25
+ repo_api . File (
26
+ ctx . owner . username ,
27
+ ctx . repo . name ,
28
+ "README.md" ,
29
+ ctx . data . hash ,
30
+ )
31
+ . then ( res => {
32
+ if ( res . status === 200 ) {
33
+ setReadme ( res . data . toString ( ) )
34
+ }
35
+ } )
36
+ }
37
+ } , [ ] ) ;
38
+
39
+ return (
40
+ < >
41
+ {
42
+ Product && < div className = { 'market-page' } >
43
+ < div className = "market-page-title" >
44
+ < div style = { {
45
+ display : "flex"
46
+ } } >
47
+ < img src = { Product . owner . avatar || "" } alt = { Product . data . name } />
48
+ < div >
49
+ < h1 > { Product . data . name } </ h1 >
50
+ < span > { Product . data . description } </ span >
51
+ </ div >
52
+ </ div >
53
+
54
+
55
+ </ div >
56
+ < div className = { 'market-page-body' } >
57
+ < div className = { 'market-page-markdown' } >
58
+ < ReactMarkdown
59
+ rehypePlugins = { [ rehypeRaw ] }
60
+ components = { {
61
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
62
+ // @ts -expect-error
63
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
+ code : ( { node, inline, className, children, ...props } ) => {
65
+ const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' ) ;
66
+ return ! inline && match ? (
67
+ < div className = "code-block" >
68
+ < code className = { className } > { children } </ code >
69
+ </ div >
70
+ ) : (
71
+ < code className = { className } { ...props } >
72
+ { children }
73
+ </ code >
74
+ ) ;
75
+ }
76
+ } }
77
+ >
78
+ { Readme }
79
+ </ ReactMarkdown >
80
+ </ div >
81
+ < div className = "market-page-info" >
82
+ < div style = { {
83
+ display : "flex" ,
84
+ alignItems : "center" ,
85
+ justifyContent : "space-between" ,
86
+ flexDirection : "row"
87
+ } } >
88
+ Price: {
89
+ Product . data . price === 0 ? < a style = { {
90
+ color : "green"
91
+ } } > Free</ a > : < a style = { {
92
+ color : "red"
93
+ } } > { Product . data . price } </ a >
94
+ }
95
+ < div className = "access" >
96
+ < Button > Get Access</ Button >
97
+ </ div >
98
+ </ div >
99
+
100
+ < div >
101
+ License: { Product . data . license }
102
+ </ div >
103
+ < div className = "hover" onClick = { ( ) => {
104
+ nav ( `/r/${ Product ?. owner . username } /${ Product ?. repo . name } ?tab=intro` )
105
+ } } >
106
+ Repo: { Product . owner . username } / { Product . repo . name }
107
+ </ div >
108
+ < div className = "hover" onClick = { ( ) => {
109
+ nav ( `/u/${ Product ?. owner . username } ` )
110
+ } } >
111
+ Owner: { Product . owner . username }
112
+ </ div >
113
+ < div >
114
+ Created At: { Product . data . created_at . toString ( ) . split ( "." ) [ 0 ] }
115
+ </ div >
116
+ < div style = { {
117
+ display : 'flex' ,
118
+ gap : '5px'
119
+ } } >
120
+ Tags: {
121
+ Product . data . type . split ( "," ) . map ( ( value , index ) => {
122
+ return < span style = { {
123
+ color : "black" ,
124
+ backgroundColor : "orangered" ,
125
+ borderRadius : "5px" ,
126
+ padding : "0 5px" ,
127
+ } } key = { index } > { value } </ span >
128
+ } )
129
+ }
130
+ </ div >
131
+ </ div >
132
+ </ div >
133
+ </ div >
134
+ }
135
+ </ >
136
+ )
137
+ }
0 commit comments