Skip to content

Commit

Permalink
Revert "Frzyc/go/simplify opt (#1666)" (#1668)
Browse files Browse the repository at this point in the history
This reverts commit ca73f9f.
  • Loading branch information
nguyentvan7 committed Mar 12, 2024
1 parent ca73f9f commit 0196ffe
Show file tree
Hide file tree
Showing 80 changed files with 1,350 additions and 1,659 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/build-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Get Cache Key
id: get-cache-key
run: |
echo "key=$(git ls-tree -r HEAD | grep '^160000' | sha256sum | cut -d " " -f 1)" >> $GITHUB_OUTPUT
- uses: actions/cache/restore@v4
with:
path: .git/modules
key: submodule-${{ steps.get-cache-key.outputs.key }}
restore-keys: |
submodule-
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
submodules: true
- uses: actions/setup-node@v4
with:
Expand Down
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 @@ -2,6 +2,7 @@ name: Build GO (WR) PR
run-name: Build GO (WR) for ${{ github.event.number }} - ${{ github.event.pull_request.title }}

permissions:
actions: read
contents: read

on:
Expand Down
67 changes: 0 additions & 67 deletions .github/workflows/build-new-release.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/build-sro-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build SRO PR
run-name: Build SRO for ${{ github.event.number }} - ${{ github.event.pull_request.title }}

permissions:
actions: read
contents: read

on:
Expand Down
21 changes: 2 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: CI

permissions:
contents: read

on:
push:
branches:
Expand Down Expand Up @@ -81,6 +78,8 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Get Cache Key
id: get-cache-key
run: |
Expand All @@ -93,13 +92,8 @@ jobs:
submodule-
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }} # Force checking of the whole repo when running on pushes to master
persist-credentials: false
submodules: true
- name: Fetch master
if: ${{ github.event_name == 'pull_request' }}
run: |
git fetch --no-tags --no-recurse-submodules --filter=blob:none origin +master:refs/heads/master
- name: Sparse Checkout
run: |
$(cd libs/gi/dm/GenshinData && git sparse-checkout set TextMap ExcelBinOutput)
Expand All @@ -119,17 +113,6 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Get Cache Key
id: get-cache-key
run: |
echo "key=$(git ls-tree -r HEAD | grep '^160000' | sha256sum | cut -d " " -f 1)" >> $GITHUB_OUTPUT
- uses: actions/cache/restore@v4
with:
path: .git/modules
key: submodule-${{ steps.get-cache-key.outputs.key }}
restore-keys: |
submodule-
- uses: actions/checkout@v4
with:
persist-credentials: false
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 5
if: ${{ github.event.workflow_run.conclusion == 'success' }}
timeout-minutes: 15
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
Expand Down
44 changes: 37 additions & 7 deletions .github/workflows/new-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
- name: Get version # TODO(eeeqeee) add option to increment from current version
id: get-version
run: |
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
Expand All @@ -34,14 +40,38 @@ jobs:
id: get-commit-msg
run: |
if [[ -z "${{ steps.get-version.outputs.version }}" ]]; then
echo "title-release=Release ref $(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "msg=deploy: $(git rev-parse HEAD)" >> $GITHUB_OUTPUT
else
echo "title-release=Release version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "msg=deploy: version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT
fi
- name: Create PR
- name: Yarn install
run: |
yarn install --immutable --immutable-cache
- name: Setup .env
run: |
printf '%s' "$ENVFILE" > apps/frontend/.env.local
env:
ENVFILE: ${{ vars.ENVFILE }}
- name: Build genshin-optimizer
run: |
NX_URL_GITHUB_GO_CURRENT_VERSION="https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)" \
yarn run nx run frontend:build-vite:production
- name: Deploy to Github Pages
run: |
git fetch origin gh-pages --depth=1
git worktree add ../gh-pages gh-pages --no-checkout
cp -rT dist/apps/frontend ../gh-pages
cd ../gh-pages
git add --all .
git commit -m "${{ steps.get-commit-msg.outputs.msg }}"
git push
- name: Push
run: |
git status
git push origin HEAD:actions/new-release --force
gh pr create --base $(git rev-parse --abbrev-ref HEAD) --head actions/new-release --title '${{ steps.get-commit-msg.outputs.title-release }}' --body '' --label release
git push
- name: Make release
if: steps.get-version.outputs.version != ''
run: |
gh release create ${{ steps.get-version.outputs.version }} --generate-notes --target $(git rev-parse HEAD)
env:
GH_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion apps/frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function Content() {
<Grid item>
<Header anchor="back-to-top-anchor" />
</Grid>
<Container maxWidth="xl" sx={{ px: { xs: 0.5, sm: 1 } }}>
<Container maxWidth="xl" sx={{ px: { xs: 0.5, sm: 1, md: 2 } }}>
<Suspense
fallback={
<Skeleton
Expand Down
92 changes: 54 additions & 38 deletions apps/frontend/src/app/Components/Artifact/ArtifactSwapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
useForceUpdate,
useMediaQueryUp,
} from '@genshin-optimizer/common/react-util'
import { useOnScreen } from '@genshin-optimizer/common/ui'
import { filterFunction } from '@genshin-optimizer/common/util'
import { clamp, filterFunction } from '@genshin-optimizer/common/util'
import { imgAssets } from '@genshin-optimizer/gi/assets'
import type { ArtifactSlotKey } from '@genshin-optimizer/gi/consts'
import { useDatabase } from '@genshin-optimizer/gi/db-ui'
Expand All @@ -25,6 +24,7 @@ import {
useEffect,
useMemo,
useReducer,
useRef,
useState,
} from 'react'
import { useTranslation } from 'react-i18next'
Expand All @@ -39,7 +39,7 @@ import CloseButton from '../CloseButton'
import CompareBuildButton from '../CompareBuildButton'
import ImgIcon from '../Image/ImgIcon'
import ModalWrapper from '../ModalWrapper'
import ShowingAndSortOptionSelect from '../ShowingAndSortOptionSelect'
import PageAndSortOptionSelect from '../PageAndSortOptionSelect'

const numToShowMap = { xs: 2 * 3, sm: 2 * 3, md: 3 * 3, lg: 4 * 3, xl: 4 * 3 }
const ArtifactEditor = lazy(() => import('../../PageArtifact/ArtifactEditor'))
Expand Down Expand Up @@ -86,42 +86,53 @@ export default function ArtifactSwapModal({
}, [database, forceUpdate])

const brPt = useMediaQueryUp()
const maxNumArtifactsToDisplay = numToShowMap[brPt]

const [pageIdex, setpageIdex] = useState(0)
const invScrollRef = useRef<HTMLDivElement>(null)

const filterConfigs = useMemo(() => artifactFilterConfigs(), [])
const totalArtNum = database.arts.values.filter(
(s) => s.slotKey === filterOption.slotKeys[0]
).length

const artifactIds = useMemo(() => {
const artIdList = useMemo(() => {
const filterFunc = filterFunction(filterOption, filterConfigs)
return (
dbDirty && database.arts.values.filter(filterFunc).map((art) => art.id)
)
}, [dbDirty, database, filterConfigs, filterOption])

const [numShow, setNumShow] = useState(numToShowMap[brPt])
// reset the numShow when artifactIds changes
useEffect(() => {
artifactIds && setNumShow(numToShowMap[brPt])
}, [artifactIds, brPt])

const [element, setElement] = useState<HTMLElement | undefined>()
const trigger = useOnScreen(element)
const shouldIncrease = trigger && numShow < artifactIds.length
useEffect(() => {
if (!shouldIncrease) return
setNumShow((num) => num + numToShowMap[brPt])
}, [shouldIncrease, brPt])

const artifactIdsToShow = useMemo(
() => artifactIds.slice(0, numShow),
[artifactIds, numShow]
)
const { artifactIdsToShow, numPages, currentPageIndex } = useMemo(() => {
const numPages = Math.ceil(artIdList.length / maxNumArtifactsToDisplay)
const currentPageIndex = clamp(pageIdex, 0, numPages - 1)
return {
artifactIdsToShow: artIdList.slice(
currentPageIndex * maxNumArtifactsToDisplay,
(currentPageIndex + 1) * maxNumArtifactsToDisplay
),
numPages,
currentPageIndex,
}
}, [artIdList, pageIdex, maxNumArtifactsToDisplay])

// for pagination
const totalShowing =
artifactIds.length !== totalArtNum
? `${artifactIds.length}/${totalArtNum}`
artIdList.length !== totalArtNum
? `${artIdList.length}/${totalArtNum}`
: `${totalArtNum}`
const setPage = useCallback(
(e, value) => {
invScrollRef.current?.scrollIntoView({ behavior: 'smooth' })
setpageIdex(value - 1)
},
[setpageIdex, invScrollRef]
)

const paginationProps = {
count: numPages,
page: currentPageIndex + 1,
onChange: setPage,
}

const showingTextProps = {
numShowing: artifactIdsToShow.length,
Expand Down Expand Up @@ -170,7 +181,7 @@ export default function ArtifactSwapModal({
<ArtifactFilterDisplay
filterOption={filterOption}
filterOptionDispatch={filterOptionDispatch}
filteredIds={artifactIds}
filteredIds={artIdList}
disableSlotFilter
/>
</Suspense>
Expand All @@ -184,7 +195,10 @@ export default function ArtifactSwapModal({
alignItems="flex-end"
flexWrap="wrap"
>
<ShowingAndSortOptionSelect showingTextProps={showingTextProps} />
<PageAndSortOptionSelect
paginationProps={paginationProps}
showingTextProps={showingTextProps}
/>
</Box>
<Button
fullWidth
Expand Down Expand Up @@ -213,17 +227,19 @@ export default function ArtifactSwapModal({
</Grid>
</Suspense>
</Box>
{artifactIds.length !== artifactIdsToShow.length && (
<Skeleton
ref={(node) => {
if (!node) return
setElement(node)
}}
sx={{ borderRadius: 1, mt: 1 }}
variant="rectangular"
width="100%"
height={100}
/>
{numPages > 1 && (
<Box
pt={2}
display="flex"
justifyContent="space-between"
alignItems="center"
flexWrap="wrap"
>
<PageAndSortOptionSelect
paginationProps={paginationProps}
showingTextProps={showingTextProps}
/>
</Box>
)}
</CardContent>
</CardDark>
Expand Down
Loading

0 comments on commit 0196ffe

Please sign in to comment.