Skip to content

Commit

Permalink
Merge branch 'orig' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aurceive committed Jul 21, 2024
2 parents 82590ea + d9431c4 commit bd025a0
Show file tree
Hide file tree
Showing 104 changed files with 2,600 additions and 242 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ jobs:
printf '%s' "$ENVFILE" > apps/frontend/.env.local
env:
ENVFILE: ${{ vars.ENVFILE }}
- name: Build genshin-optimizer
- name: Build frontend
run: |
NX_URL_GITHUB_GO_CURRENT_VERSION="https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)" \
NX_DAEMON="false" \
NX_SHOW_DEV_COMPONENTS="${{inputs.show_dev_components}}" \
yarn run nx run ${{inputs.frontend_name}}:build:production
- name: Build gi-frontend
if: inputs.frontend_name == 'gi-frontend'
run: yarn nx run gi-frontend:next:build
- name: Build other frontend
if: inputs.frontend_name != 'gi-frontend'
run: yarn run nx run ${{inputs.frontend_name}}:build:production
- name: echos
run: |
echo ${{inputs.frontend_name}} > frontend_name
echo ${{inputs.deployment_name}} > deployment_name
echo $(git rev-parse HEAD) > ref
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/build-go-next-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build GO-next PR
run-name: Build GO-next for ${{ github.event.number }} - ${{ github.event.pull_request.title }}

permissions:
contents: read

on:
pull_request:
paths-ignore:
- 'apps/gi-backend/**'
- 'apps/gi-backend-e2e/**'
- 'apps/gi-frontend-next-e2e/**'
- 'apps/gi-frontend-next-e2e/**'
- 'apps/sr-frontend/**'
- 'apps/sr-frontend-e2e/**'
- 'libs/gi/frontend-gql/**'
- 'libs/gi/prisma-schema/**'
- 'libs/gi/ui-next/**'
- 'libs/sr/**'
types: [opened, reopened, synchronize, labeled]

jobs:
call-build-gi-frontend:
uses: ./.github/workflows/build-frontend.yml
with:
frontend_name: 'gi-frontend'
deployment_name: ${{ github.event.number }}
show_dev_components: ${{ contains(github.event.pull_request.labels.*.name, 'showDevComponents') }}
1 change: 1 addition & 0 deletions .github/workflows/build-go-wr-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ permissions:
on:
pull_request:
paths-ignore:
- 'apps/gi-frontend/**'
- 'apps/gi-backend/**'
- 'apps/gi-backend-e2e/**'
- 'apps/gi-frontend-next-e2e/**'
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
54 changes: 41 additions & 13 deletions apps/gi-frontend/src/app/artifacts/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'
import type { ICachedArtifact } from '@genshin-optimizer/gi/db'
import type { Tables } from '@genshin-optimizer/gi/supabase'
import { ArtifactCardObj } from '@genshin-optimizer/gi/ui'
import { randomizeArtifact } from '@genshin-optimizer/gi/util'
import { Button, Container, Grid, Skeleton, Typography } from '@mui/material'
import { Suspense, useEffect, useState } from 'react'
import { useSupabase } from '../../utils/supabase/client'
import type { Artifact, Artifacts } from './getArtifacts'

const columns = { xs: 1, sm: 2, md: 3, lg: 3, xl: 4 }
// const numToShowMap = { xs: 5, sm: 6, md: 12, lg: 12, xl: 12 }
Expand All @@ -14,18 +14,35 @@ export default function Content({
artifacts: serverArtifacts,
accountId,
}: {
artifacts: Array<Tables<'artifacts'>>
artifacts: Artifacts
accountId: string
}) {
const supabase = useSupabase()
const [artifacts, setArtifacts] = useState(serverArtifacts)
const addArtifact = async () => {
try {
const { error } = await supabase.from('artifacts').insert({
...randomizeArtifact(),
account: accountId,
} as any)
if (error) console.error(error)
const randArtifact = randomizeArtifact()
const { substats, location, ...rest } = randArtifact
const { error, data } = await supabase
.from('artifacts')
.insert({
...rest,
account_id: accountId,
} as any)
.select()
if (error) return console.error(error)
const art = data[0]
if (!art.id) return
// TODO: is there a better way to add substats? this sends like 5 requests per artifact...
substats.map(async (substat, index) => {
if (!substat.key) return
const { error } = await supabase.from('substats').insert({
...substat,
index,
artifact_id: art.id,
} as any)
if (error) return console.error(error)
})
} catch (error) {
console.error(error)
}
Expand All @@ -39,13 +56,24 @@ export default function Content({
event: '*',
schema: 'public',
table: 'artifacts',
filter: `account=eq.${accountId}`,
filter: `account_id=eq.${accountId}`,
},
(payload) => {
if (payload.new)
setArtifacts(
(arts) => [...arts, payload.new] as Array<Tables<'artifacts'>>
)
async (payload) => {
// TODO: probably need to listen to other changes? the issue is that we are not listening to changes to substats
if (payload.new) {
// TODO: is there a better way to update this? doing an extra lookup seems kind of excessive, but the payload.new does not include substats.
const { error, data: artifact } = await supabase
.from('artifacts')
.select(
'id, created_at, setKey, slotKey, level, rarity, substats(key, value), lock, mainStatKey'
)
.eq('id', (payload.new as Artifact).id)
.eq('account_id', accountId)
.maybeSingle()
if (error) return console.error(error)
if (!artifact) return
setArtifacts((arts) => [...arts, artifact] as Artifacts)
}
}
)
.subscribe()
Expand Down
10 changes: 8 additions & 2 deletions apps/gi-frontend/src/app/artifacts/getArtifacts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use server'
import type { UnArray, Unpromise } from '@genshin-optimizer/common/util'
import type { Database } from '@genshin-optimizer/gi/supabase'
import type { SupabaseClient } from '@supabase/supabase-js'
export default async function getArtifacts(
Expand All @@ -9,10 +10,15 @@ export default async function getArtifacts(
const { data, error } = await supabase
.from('artifacts')
.select(
`id, created_at, setKey, slotKey, level, rarity, substats, lock, mainStatKey`
`id, created_at, setKey, slotKey, level, rarity, substats(key, value), lock, mainStatKey, character:characters(id, key)`
)
.eq('account', accountId)
.eq('account_id', accountId)

if (error) console.error(error)
return data
}
export type Artifacts = Exclude<
Unpromise<ReturnType<typeof getArtifacts>>,
null
>
export type Artifact = UnArray<Artifacts>
9 changes: 2 additions & 7 deletions apps/gi-frontend/src/app/artifacts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Tables } from '@genshin-optimizer/gi/supabase'
import { redirect } from 'next/navigation'
import { getSupabase } from '../../utils/supabase/server'
import getProfile from '../util/getProfile'
Expand All @@ -12,10 +11,6 @@ export default async function Artifacts() {
const profile = await getProfile(supabase, user)
if (!profile?.active_account) redirect('/profile')
const artifacts = await getArtifacts(supabase, profile?.active_account)
return (
<Content
artifacts={artifacts as Array<Tables<'artifacts'>>}
accountId={profile?.active_account}
/>
)
if (!artifacts) return null
return <Content artifacts={artifacts} accountId={profile?.active_account} />
}
4 changes: 2 additions & 2 deletions apps/gi-frontend/src/app/characters/CharacterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function CharacterCard({
}) {
const calc = genshinCalculatorWithEntries(
withMember(
'member0',
'0',
...charData({
key: character.key,
level: character.level,
Expand All @@ -30,7 +30,7 @@ export function CharacterCard({
})
)
)
const member0 = convert(selfTag, { member: 'member0', et: 'self' })
const member0 = convert(selfTag, { src: '0', et: 'self' })
return (
<CardThemed>
<CardContent>
Expand Down
8 changes: 4 additions & 4 deletions apps/gi-frontend/src/app/characters/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Content({
}) {
const supabase = useSupabase()
const [characters, setCharacters] = useState(serverCharacters)
const addWeapon = async () => {
const addChar = async () => {
try {
const ranChar: any = randomizeCharacter()
if (characters.find((c) => c.key === ranChar.key))
Expand All @@ -31,7 +31,7 @@ export default function Content({

const { error } = await supabase.from('characters').insert({
...ranChar,
account: accountId,
account_id: accountId,
} as any)
if (error) console.error(error)
} catch (error) {
Expand All @@ -47,7 +47,7 @@ export default function Content({
event: '*',
schema: 'public',
table: 'characters',
filter: `account=eq.${accountId}`,
filter: `account_id=eq.${accountId}`,
},
(payload) => {
if (payload.new)
Expand All @@ -65,7 +65,7 @@ export default function Content({
})
return (
<Container>
<Button onClick={addWeapon}> Add Character</Button>
<Button onClick={addChar}> Add Character</Button>
<Typography>Characters</Typography>

<Suspense
Expand Down
9 changes: 8 additions & 1 deletion apps/gi-frontend/src/app/characters/getCharacters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use server'
import type { UnArray, Unpromise } from '@genshin-optimizer/common/util'
import type { Database } from '@genshin-optimizer/gi/supabase'
import type { SupabaseClient } from '@supabase/supabase-js'
export default async function getCharacters(
Expand All @@ -11,8 +12,14 @@ export default async function getCharacters(
.select(
`id, created_at, key, level, ascension, talent_auto, talent_skill, talent_burst, constellation`
)
.eq('account', accountId)
.eq('account_id', accountId)

if (error) console.error(error)
return data
}

export type Characters = Exclude<
Unpromise<ReturnType<typeof getCharacters>>,
null
>
export type Character = UnArray<Characters>
4 changes: 4 additions & 0 deletions apps/gi-frontend/src/app/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const pages = [
title: 'Characters',
href: '/characters',
},
{
title: 'Teams',
href: '/teams',
},
]
const settings = [
{ title: 'Profile', href: '/profile' },
Expand Down
74 changes: 74 additions & 0 deletions apps/gi-frontend/src/app/teams/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use client'
import { Button, Container, Grid, Skeleton, Typography } from '@mui/material'
import { Suspense, useEffect, useState } from 'react'
import { useSupabase } from '../../utils/supabase/client'
import { TeamCard } from './TeamCard'
import type { Teams } from './getTeams'

const columns = { xs: 1, sm: 2, md: 3, lg: 3, xl: 4 }
// const numToShowMap = { xs: 5, sm: 6, md: 12, lg: 12, xl: 12 }

export default function Content({
teams: serverTeams,
accountId,
}: {
teams: Teams
accountId: string
}) {
const supabase = useSupabase()
const [teams, setTeams] = useState(serverTeams)
const addTeam = async () => {
try {
const { error } = await supabase.from('teams').insert({
account_id: accountId,
} as any)
if (error) console.error(error)
} catch (error) {
console.error(error)
}
}
useEffect(() => {
const channel = supabase
.channel('team updates')
.on(
'postgres_changes',
{
event: '*',
schema: 'public',
table: 'teams',
filter: `account_id=eq.${accountId}`,
},
(payload) => {
if (payload.new) setTeams((teams) => [...teams, payload.new] as Teams)
}
)
.subscribe()

return () => {
supabase.removeChannel(channel)
}
})
return (
<Container>
<Button onClick={addTeam}> Add Team</Button>
<Typography>Teams</Typography>

<Suspense
fallback={
<Skeleton
variant="rectangular"
sx={{ width: '100%', height: '100%', minHeight: 5000 }}
/>
}
>
<Grid container spacing={1} columns={columns}>
{teams.map((team) => (
<Grid item key={team.id} xs={1}>
<TeamCard team={team} />
</Grid>
))}
</Grid>
</Suspense>
</Container>
)
}
16 changes: 16 additions & 0 deletions apps/gi-frontend/src/app/teams/TeamCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CardThemed } from '@genshin-optimizer/common/ui'
import { CardActionArea, CardContent, Typography } from '@mui/material'
import Link from 'next/link'
import type { Team } from './getTeams'
export function TeamCard({ team }: { team: Team }) {
return (
<CardThemed>
<CardActionArea component={Link} href={`/teams/${team.id}`}>
<CardContent>
<Typography>{team.name ?? 'Team Name'}</Typography>
<Typography>{team.description ?? 'Team Description'}</Typography>
</CardContent>
</CardActionArea>
</CardThemed>
)
}
5 changes: 5 additions & 0 deletions apps/gi-frontend/src/app/teams/[teamId]/CalcContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//create a context for calc object
import type { Calculator } from '@genshin-optimizer/gi/formula'
import { createContext } from 'react'

export const CalcContext = createContext<Calculator | null>(null)
Loading

0 comments on commit bd025a0

Please sign in to comment.