Skip to content

Commit

Permalink
Urls, 404, upgrade react! introduce react-three-fiber (ZcashFoundatio…
Browse files Browse the repository at this point in the history
  • Loading branch information
skyl authored Dec 4, 2022
1 parent f9f1f40 commit 0d153b1
Show file tree
Hide file tree
Showing 29 changed files with 4,001 additions and 2,708 deletions.
9 changes: 9 additions & 0 deletions docs/styles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## MUI themes all the way

## Further

https://www.welcomedeveloper.com/react-mui-theme

https://mui.com/material-ui/customization/palette/

https://m2.material.io/resources/color/#!/?view.left=0&view.right=0&primary.color=3f41cb&secondary.color=cdaefb
26 changes: 25 additions & 1 deletion py/dj/apps/g12f/views/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import requests
# from django.core.exceptions import ValidationError
from django.conf import settings
from django.db import models
from rest_framework import status, viewsets, mixins
from rest_framework.generics import get_object_or_404
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated

from dj.apps.g12f.models import Creator, Subscription
from dj.apps.g12f.models import Creator, Subscription, zPage
from dj.apps.g12f.serializers.creator import (
RegistrationSerializer,
CreatorDetailSerializer,
Expand Down Expand Up @@ -206,3 +207,26 @@ def post(self, request, *args, **kwargs):
star.save()

return Response("OK")


# TODO: this is a stopgap that may last a while:
# returns either "zpage" or "creator" based on id
# this allows us to serve pages and creators at the root
# over time we will remove the pages at the root
class GetTypeAPI(APIView):
def get(self, request, *args, **kwargs):
id = kwargs.get('id')

try:
Creator.objects.get(username__iexact=id)
return Response("creator")
except Creator.DoesNotExist:
pass

try:
zpage: zPage = zPage.objects.get(
models.Q(vanity__iexact=id) | models.Q(free2zaddr__iexact=id)
)
return Response("zpage")
except zPage.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
4 changes: 4 additions & 0 deletions py/dj/free2z/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def e404(request):
views.Donate2Z.as_view(),
name='donate2z'),

path('api/get-type/<str:id>',
views.GetTypeAPI.as_view(),
name='get-type'),

# maybe TODO later
# https://dj-rest-auth.readthedocs.io/en/latest/api_endpoints.html
path('api/auth/password/reset/', e404),
Expand Down
2,162 changes: 1,591 additions & 571 deletions ts/react/free2z/package-lock.json

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions ts/react/free2z/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,34 @@
"@dytesdk/react-web-core": "^1.15.0",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@mui/icons-material": "^5.10.15",
"@mui/material": "^5.10.15",
"@mui/styles": "^5.10.15",
"@mui/icons-material": "^5.10.16",
"@mui/material": "^5.10.16",
"@mui/styles": "^5.10.16",
"@react-three/cannon": "^6.5.0",
"@react-three/drei": "^9.46.1",
"@react-three/fiber": "^8.9.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.3",
"@types/react": "^17.0.52",
"@types/react-dom": "^17.0.18",
"@types/node": "^16.18.4",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@uiw/react-md-editor": "^3.19.7",
"axios": "^0.26.1",
"buffer": "^6.0.3",
"clipboard-copy": "^4.0.1",
"js-cookie": "^3.0.1",
"mui-markdown": "^0.5.6",
"prism-theme-night-owl": "^1.4.0",
"query-string": "^7.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"query-string": "^7.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-google-recaptcha": "^2.1.0",
"react-hooks-global-state": "^2.0.0",
"react-markdown": "^8.0.3",
"react-markdown": "^8.0.4",
"react-qr-code": "^2.0.8",
"react-router-dom": "^6.4.3",
"react-router-dom": "^6.4.4",
"react-scripts": "5.0.0",
"react-swipeable-views": "^0.14.0",
"react-tiny-oembed": "^1.1.0",
Expand All @@ -45,6 +48,7 @@
"remark-math": "^5.1.1",
"remark-oembed": "^1.2.2",
"slugify": "^1.6.5",
"three": "^0.147.0",
"typescript": "^4.9.3",
"url": "^0.11.0",
"web-vitals": "^2.1.4"
Expand Down
1 change: 1 addition & 0 deletions ts/react/free2z/public/Roboto_Regular.json

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion ts/react/free2z/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useStoreState } from "./state/persist"
import CreatorLive from "./CreatorLive"
import GlobalCreator from "./state/GlobalCreator"
import getTheme from "./Theme"
import RootSplitter from "./RootSplitter"

function App() {
const darkMode = useStoreState("darkmode")
Expand Down Expand Up @@ -104,6 +105,7 @@ function App() {
</NormalPage>
}
/>
{/* deprecated */}
<Route
path="/creator/:id"
element={
Expand All @@ -118,11 +120,18 @@ function App() {
<CreatorLive />
}
/>
{/* end deprecated */}
<Route
path="/:id/live"
element={
<CreatorLive />
}
/>
<Route
path="/:id"
element={
<NormalPage>
<PageDetail />
<RootSplitter />
</NormalPage>
}
/>
Expand Down
2 changes: 1 addition & 1 deletion ts/react/free2z/src/CreatorLive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function CreatorLive() {
setRedirect(location.pathname)
navigate("/begin")
}
if (!creator.can_stream && creator.username == owner) {
if (!creator.can_stream && creator.username.toLowerCase() === owner?.toLowerCase()) {
setSnackbarState({
message: "Live streaming is not enabled for your account",
severity: "warning",
Expand Down
144 changes: 144 additions & 0 deletions ts/react/free2z/src/Global404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// https://www.youtube.com/watch?v=9ZEjSxDRIik
import { Canvas } from '@react-three/fiber'
import { KeyboardControls, KeyboardControlsEntry, OrbitControls, Sphere, Stars, Text3D, Torus } from "@react-three/drei";
import { Physics, usePlane, useBox, useSphere } from "@react-three/cannon";
import { useMemo } from 'react';


function Toruso() {
const [ref, api] = useSphere(() => ({ mass: 1, position: [0, 80, -3] }));

return (
<mesh
ref={ref}
position={[0, 80, -3]}
>
<Torus key={undefined} position={undefined} material={undefined} userData={undefined} rotation={undefined} attach={undefined} onUpdate={undefined} up={undefined} scale={undefined} matrix={undefined} quaternion={undefined} layers={undefined} dispose={undefined} clear={undefined} geometry={undefined} raycast={undefined} onClick={undefined} onContextMenu={undefined} onDoubleClick={undefined} onPointerUp={undefined} onPointerDown={undefined} onPointerOver={undefined} onPointerOut={undefined} onPointerEnter={undefined} onPointerLeave={undefined} onPointerMove={undefined} onPointerMissed={undefined} onPointerCancel={undefined} onWheel={undefined} type={undefined} visible={undefined} id={undefined} uuid={undefined} name={undefined} parent={undefined} modelViewMatrix={undefined} normalMatrix={undefined} matrixWorld={undefined} matrixAutoUpdate={undefined} matrixWorldNeedsUpdate={undefined} castShadow={undefined} receiveShadow={undefined} frustumCulled={undefined} renderOrder={undefined} animations={undefined} customDepthMaterial={undefined} customDistanceMaterial={undefined} isObject3D={undefined} onBeforeRender={undefined} onAfterRender={undefined} applyMatrix4={undefined} applyQuaternion={undefined} setRotationFromAxisAngle={undefined} setRotationFromEuler={undefined} setRotationFromMatrix={undefined} setRotationFromQuaternion={undefined} rotateOnAxis={undefined} rotateOnWorldAxis={undefined} rotateX={undefined} rotateY={undefined} rotateZ={undefined} translateOnAxis={undefined} translateX={undefined} translateY={undefined} translateZ={undefined} localToWorld={undefined} worldToLocal={undefined} lookAt={undefined} add={undefined} remove={undefined} removeFromParent={undefined} getObjectById={undefined} getObjectByName={undefined} getObjectByProperty={undefined} getWorldPosition={undefined} getWorldQuaternion={undefined} getWorldScale={undefined} getWorldDirection={undefined} traverse={undefined} traverseVisible={undefined} traverseAncestors={undefined} updateMatrix={undefined} updateMatrixWorld={undefined} updateWorldMatrix={undefined} toJSON={undefined} clone={undefined} copy={undefined} addEventListener={undefined} hasEventListener={undefined} removeEventListener={undefined} dispatchEvent={undefined} morphTargetInfluences={undefined} morphTargetDictionary={undefined} isMesh={undefined} updateMorphTargets={undefined}>
{/* <meshBasicMaterial color="rebeccapurple" /> */}
<meshLambertMaterial attach="material" color="rebeccapurple" />

</Torus>
</mesh>
)
}


function Sphero() {
const [ref, api] = useSphere(() => ({ mass: 1, position: [0, 50, -7] }));

return (
<mesh
ref={ref}
position={[0, 50, -7]}
>
<Sphere key={undefined} position={undefined} material={undefined} userData={undefined} rotation={undefined} attach={undefined} onUpdate={undefined} up={undefined} scale={undefined} matrix={undefined} quaternion={undefined} layers={undefined} dispose={undefined} onClick={undefined} onContextMenu={undefined} onDoubleClick={undefined} onPointerUp={undefined} onPointerDown={undefined} onPointerOver={undefined} onPointerOut={undefined} onPointerEnter={undefined} onPointerLeave={undefined} onPointerMove={undefined} onPointerMissed={undefined} onPointerCancel={undefined} onWheel={undefined} visible={undefined} type={undefined} id={undefined} uuid={undefined} name={undefined} parent={undefined} modelViewMatrix={undefined} normalMatrix={undefined} matrixWorld={undefined} matrixAutoUpdate={undefined} matrixWorldNeedsUpdate={undefined} castShadow={undefined} receiveShadow={undefined} frustumCulled={undefined} renderOrder={undefined} animations={undefined} customDepthMaterial={undefined} customDistanceMaterial={undefined} isObject3D={undefined} onBeforeRender={undefined} onAfterRender={undefined} applyMatrix4={undefined} applyQuaternion={undefined} setRotationFromAxisAngle={undefined} setRotationFromEuler={undefined} setRotationFromMatrix={undefined} setRotationFromQuaternion={undefined} rotateOnAxis={undefined} rotateOnWorldAxis={undefined} rotateX={undefined} rotateY={undefined} rotateZ={undefined} translateOnAxis={undefined} translateX={undefined} translateY={undefined} translateZ={undefined} localToWorld={undefined} worldToLocal={undefined} lookAt={undefined} add={undefined} remove={undefined} removeFromParent={undefined} clear={undefined} getObjectById={undefined} getObjectByName={undefined} getObjectByProperty={undefined} getWorldPosition={undefined} getWorldQuaternion={undefined} getWorldScale={undefined} getWorldDirection={undefined} raycast={undefined} traverse={undefined} traverseVisible={undefined} traverseAncestors={undefined} updateMatrix={undefined} updateMatrixWorld={undefined} updateWorldMatrix={undefined} toJSON={undefined} clone={undefined} copy={undefined} addEventListener={undefined} hasEventListener={undefined} removeEventListener={undefined} dispatchEvent={undefined} geometry={undefined} morphTargetInfluences={undefined} morphTargetDictionary={undefined} isMesh={undefined} updateMorphTargets={undefined}>
{/* <meshBasicMaterial color="salmon" /> */}
<meshLambertMaterial attach="material" color="salmon" />

</Sphere>
</mesh>
)
}

function Box() {
const [ref, api] = useBox(() => ({ mass: 1, position: [0, 20, -5] }));
return (
<mesh
onClick={() => {
api.velocity.set(Math.random(), 2, Math.random());
}}
ref={ref}
position={[0, 20, -2]}
// rotation={[1, Math.PI / 3, 2]}
// quaternion={THREE.Quarternion}
>
<boxBufferGeometry attach="geometry" />
<meshLambertMaterial attach="material" color="hotpink" />
</mesh>
);
}

function Text404() {
const [ref, api] = useSphere(() => ({ mass: 1000, position: [-1, 10, -30] }));

return (
// <mesh
// // ref={ref}
// >


<Text3D
key={undefined} material={undefined} userData={undefined} attach={undefined} args={undefined} onUpdate={undefined} clear={undefined} geometry={undefined} raycast={undefined} type={undefined} visible={undefined} id={undefined} uuid={undefined} name={undefined} parent={undefined} modelViewMatrix={undefined} normalMatrix={undefined} matrixWorld={undefined} matrixAutoUpdate={undefined} matrixWorldNeedsUpdate={undefined} castShadow={undefined} receiveShadow={undefined} frustumCulled={undefined} renderOrder={undefined} animations={undefined} customDepthMaterial={undefined} customDistanceMaterial={undefined} isObject3D={undefined} onBeforeRender={undefined} onAfterRender={undefined} applyMatrix4={undefined} applyQuaternion={undefined} setRotationFromAxisAngle={undefined} setRotationFromEuler={undefined} setRotationFromMatrix={undefined} setRotationFromQuaternion={undefined} rotateOnAxis={undefined} rotateOnWorldAxis={undefined} rotateX={undefined} rotateY={undefined} rotateZ={undefined} translateOnAxis={undefined} translateX={undefined} translateY={undefined} translateZ={undefined} localToWorld={undefined} worldToLocal={undefined} lookAt={undefined} add={undefined} remove={undefined} removeFromParent={undefined} getObjectById={undefined} getObjectByName={undefined} getObjectByProperty={undefined} getWorldPosition={undefined} getWorldQuaternion={undefined} getWorldScale={undefined} getWorldDirection={undefined} traverse={undefined} traverseVisible={undefined} traverseAncestors={undefined} updateMatrix={undefined} updateMatrixWorld={undefined} updateWorldMatrix={undefined} toJSON={undefined} clone={undefined} copy={undefined} addEventListener={undefined} hasEventListener={undefined} removeEventListener={undefined} dispatchEvent={undefined} morphTargetInfluences={undefined} morphTargetDictionary={undefined} isMesh={undefined} updateMorphTargets={undefined}
position={[-1, 10, -10]}
// https://www.fontsquirrel.com/fonts/list/popular
// http://gero3.github.io/facetype.js/
// https://panzoid.com/community/5802
font={"/Roboto_Regular.json"}
ref={ref}
>
{"404"}
<meshNormalMaterial />
</Text3D>
// </mesh>
)
}

function Plane() {
const [ref] = usePlane(() => ({
rotation: [-Math.PI / 2 + 0.08, 0, 0],
position: [0, -2, 0]
}));
return (
<mesh
ref={ref}
rotation={[-Math.PI / 2 + 0.08, 0, 0]}
position={[0, -2, 0]}
>
<planeBufferGeometry attach="geometry" args={[100, 100]} />
<meshLambertMaterial attach="material" color="lightblue" />
</mesh>
);
}

enum Controls {
forward = 'forward',
back = 'back',
left = 'left',
right = 'right',
jump = 'jump',
}


export default function Global404() {
const map = useMemo<KeyboardControlsEntry<Controls>[]>(() => [
{ name: Controls.forward, keys: ['ArrowUp', 'w', 'W'] },
{ name: Controls.back, keys: ['ArrowDown', 's', 'S'] },
{ name: Controls.left, keys: ['ArrowLeft', 'a', 'A'] },
{ name: Controls.right, keys: ['ArrowRight', 'd', 'D'] },
{ name: Controls.jump, keys: ['Space'] },
], [])

return (
// <KeyboardControls map={map}>
<Canvas style={{
height: "100vh",
backgroundColor: "black",
}}>


<OrbitControls />

<Stars />
<ambientLight intensity={0.5} />
<spotLight position={[10, 15, 10]} angle={0.3} />
<Physics>
<Text404 />
<Toruso />
<Box />
<Sphero />
<Plane />
</Physics>
</Canvas>
// </KeyboardControls>
)
}
8 changes: 0 additions & 8 deletions ts/react/free2z/src/PageDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ export default function PageDetail() {
} as PageInterface)

const params = useParams()
if (!params.id) {
setSnackbarState({
open: true,
severity: "error" as AlertColor,
message: "404",
duration: null,
})
}

useEffect(() => {
setLoading(true)
Expand Down
6 changes: 3 additions & 3 deletions ts/react/free2z/src/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function Profile() {
<IconButton
color="success"
onClick={() => {
navigate(`/creator/${creator.username}/live`)
navigate(`/${creator.username}/live`)
}}
>
<LiveTv />
Expand All @@ -122,11 +122,11 @@ export default function Profile() {
color="primary"
onClick={() => {
handleSubmit()
// const url = `/creator/${creator.username}`
// const url = `/${creator.username}`
// window.open(url, '_blank')
// hrm .. need to keep that global state
// persist?
navigate(`/creator/${creator.username}`)
navigate(`/${creator.username}`)
}}
>
<TravelExplore />
Expand Down
44 changes: 44 additions & 0 deletions ts/react/free2z/src/RootSplitter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from "axios"
import { lazy, useEffect, useState } from "react"
import { useParams } from "react-router"
import CreatorDetail from "./CreatorDetail"
import PageDetail from "./PageDetail"
// https://reactjs.org/docs/code-splitting.html
// import Global404 from "./Global404"
const Global404 = lazy(() => import('./Global404'))

export default function RootSplitter() {
const [_404, set404] = useState(false)
const params = useParams()

const [type, setType] = useState("" as "" | "zpage" | "creator")

useEffect(() => {
axios.get(`/api/get-type/${params.id}`).then((res) => {
console.log(res)
setType(res.data)
// TODO: maybe not global? yeah, probably not
set404(false)
}).catch(() => {
set404(true)
})
}, [params.id])

if (_404) {
return <Global404 />
// return null
}
if (!type) {
return null
}

if (type == "zpage") {
return <PageDetail />
}

if (type == "creator") {
return <CreatorDetail />
}

return null
}
Loading

0 comments on commit 0d153b1

Please sign in to comment.