-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
16 changed files
with
1,134 additions
and
187 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
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,56 @@ | ||
import { | ||
Collapse, | ||
LinearProgress, | ||
List, | ||
ListItem, | ||
ListItemSecondaryAction, | ||
ListItemText, | ||
Stack, | ||
Typography, | ||
} from "@mui/material"; | ||
import dayjs from "dayjs"; | ||
import useUser from "../../hooks/useUser"; | ||
import useVideoHistory from "../../hooks/useVideoHistory"; | ||
|
||
interface Props { | ||
video: any; | ||
} | ||
|
||
export default function VideoHistoryPage({ video }: Props) { | ||
const histories = useVideoHistory(video); | ||
|
||
console.log("histories", histories); | ||
|
||
return ( | ||
<List> | ||
<Collapse in={histories.isLoading} mountOnEnter unmountOnExit> | ||
<LinearProgress /> | ||
</Collapse> | ||
{histories.data?.map((history, index) => ( | ||
<ListItem key={`${index}`}> | ||
<ListItemText | ||
primary={ | ||
<Stack direction={"row"} spacing={1}> | ||
<TransactionText userRef={history.from} /> | ||
<Typography>Purchased from</Typography> | ||
<TransactionText userRef={history.to} /> | ||
</Stack> | ||
} | ||
secondary={`HKD $${history.amount}`} | ||
/> | ||
<ListItemSecondaryAction> | ||
<Typography> | ||
{dayjs(history.created_at.seconds * 1000).format("YYYY-MM-DD")} | ||
</Typography> | ||
</ListItemSecondaryAction> | ||
</ListItem> | ||
))} | ||
</List> | ||
); | ||
} | ||
|
||
function TransactionText({ userRef }: { userRef: any }) { | ||
const user = useUser(userRef); | ||
|
||
return <Typography>{user.data?.display_name}</Typography>; | ||
} |
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,30 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Comment } from "client"; | ||
import { | ||
collection, | ||
getFirestore, | ||
query, | ||
where, | ||
getDocs, | ||
} from "firebase/firestore"; | ||
import React from "react"; | ||
|
||
const firestore = getFirestore(); | ||
|
||
export default function useComents(video: any) { | ||
const comments = useQuery(["comments", video], async () => { | ||
const commentRef = query( | ||
collection(firestore, "Comment"), | ||
where("video", "==", video) | ||
); | ||
|
||
const querySnapshot = await getDocs(commentRef); | ||
const comments = querySnapshot.docs.map((doc) => ({ | ||
id: doc.id, | ||
...doc.data(), | ||
})); | ||
return comments as Comment[]; | ||
}); | ||
|
||
return comments; | ||
} |
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,18 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import React from "react"; | ||
import { getDoc, doc, getFirestore } from "firebase/firestore"; | ||
|
||
const firestore = getFirestore(); | ||
|
||
export default function useUser(userId: any) { | ||
const user = useQuery(["user", userId], async () => { | ||
const document = await getDoc(userId); | ||
if (document.exists()) { | ||
return document.data() as any; | ||
} else { | ||
return undefined; | ||
} | ||
}); | ||
|
||
return user; | ||
} |
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,29 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Video } from "client"; | ||
import { | ||
collection, | ||
doc, | ||
getDoc, | ||
getFirestore, | ||
limit, | ||
query, | ||
} from "firebase/firestore"; | ||
|
||
const firestore = getFirestore(); | ||
|
||
export default function useVideo(id: string) { | ||
/** | ||
* Get video by id | ||
*/ | ||
const video = useQuery([id], async () => { | ||
const docRef = doc(firestore, "Video", id); | ||
const document = await getDoc(docRef); | ||
if (document.exists()) { | ||
return { id: id, ...document.data() } as Video; | ||
} else { | ||
return undefined; | ||
} | ||
}); | ||
|
||
return video; | ||
} |
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,26 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { collection, getDocs, query, where } from "firebase/firestore"; | ||
import React from "react"; | ||
|
||
import { getFirestore } from "firebase/firestore"; | ||
import { Transaction } from "client"; | ||
|
||
const firestore = getFirestore(); | ||
|
||
export default function useVideoHistory(video: any) { | ||
const histories = useQuery(["histories", video], async () => { | ||
const historyRef = query( | ||
collection(firestore, "Transaction"), | ||
where("video", "==", video) | ||
); | ||
|
||
const querySnapshot = await getDocs(historyRef); | ||
const histories = querySnapshot.docs.map((doc) => ({ | ||
id: doc.id, | ||
...doc.data(), | ||
})); | ||
return histories as Transaction[]; | ||
}); | ||
|
||
return histories; | ||
} |
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,31 @@ | ||
import React from "react"; | ||
|
||
import { Video } from "client"; | ||
import { | ||
collection, | ||
getDocs, | ||
getFirestore, | ||
limit, | ||
query, | ||
} from "firebase/firestore"; | ||
|
||
const firestore = getFirestore(); | ||
|
||
export default function useVideos() { | ||
const [videos, setVideos] = React.useState<Video[]>([]); | ||
|
||
React.useEffect(() => { | ||
const getVideos = async () => { | ||
const q = query(collection(firestore, "Video"), limit(10)); | ||
const querySnapshot = await getDocs(q); | ||
const videos = querySnapshot.docs.map((doc) => ({ | ||
id: doc.id, | ||
...doc.data(), | ||
})); | ||
setVideos(videos as Video[]); | ||
}; | ||
getVideos(); | ||
}, []); | ||
|
||
return videos; | ||
} |
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
Oops, something went wrong.
13a1d2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
video-trading – ./apps/video-trading
video-trading.vercel.app
video-trading-git-main-etherdata-blockchain.vercel.app
video-trading-etherdata-blockchain.vercel.app
www.video2.trade
video2.trade
13a1d2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
codeblock – ./apps/codeblock
codeblock-git-main-etherdata-blockchain.vercel.app
codeblock-etherdata-blockchain.vercel.app
codeblock.vercel.app