AlignmentResearch / KataGoVisualizer

MIT License
3 stars 1 forks source link

website: Make move links jump to first game #119

Closed tomtseng closed 3 weeks ago

tomtseng commented 3 weeks ago

Fixes #116 Issue:

When clicking a move link, make it jump to the correct game -- currently it'll jump moves within whichever game is currently selected which is problematic in cases there are multiple games in a section.

This PR makes move links jump to the first game (other games can be specified, but we aren't currently specifying any other games). In content.ts, instead of writing

<a class='clickable' onclick='setMove(section_name, move_number)'>link text</a>

we write

<MoveLink game=game_number move=move_number>link text</a>

where game=game_number is optional (defaults to game=0)

Notes on rationale for implementation

communicating state changes

We previously modified move numbers by exposing a function window.setMove at global scope that modifies each section's Go player wgoPlayer. For this PR, we want move links to not only modify wgoPlayer state but to also modify Svelte state — selectedRow in <GameList>.

Strictly speaking I think we could still solve this by similarly having every <GameList> save their selectedRow in a global object and then exposing a global window function to modify each selectedRow, but this isn't how you're "supposed" to communicate Svelte state. So part 1 of this PR is just refactoring so as to not communicate via global state:

this involves some wacky regex parsing — if we'd prefer to just pass around globally scoped variables instead of weird regex I can revert this part

implementing the state change

After the refactor, how do we actually implement updating the game and move, i.e., what is <GameMoveLink>'s onClick function?

An alternative implementation I tried: instead of giving MoveGameLink the callback updateGame(), let it modify a shared tuple [selectedRow, moveNumber] and then reactively update wgoPlayer based on that state. This doesn't work because we can't actually sync moveNumber with wgoPlayer (i.e., say we click a move link to change moveNumber to 1, then we manually use the wgoPlayer UI to change the move number to 4, then click the move link again — moveNumber was 1 the whole time so no reactive update will be triggered)

(We could've based this branch on main instead of tomtseng/defense-site, but basing on tomtseng/defense-site saves us the annoyance of having to deal with content.ts merge conflicts when both this PR and PR #99 merge. Also, issue #116 is only relevant on tomtseng/defense-site anyway — main currently doesn't have any multi-game sections with move links, which is what causes #116.)

netlify[bot] commented 3 weeks ago

Deploy Preview for goattack ready!

Name Link
Latest commit
Latest deploy log https://app.netlify.com/sites/goattack/deploys/6664f7d228a7e0548846b3a3
Deploy Preview https://deploy-preview-119--goattack.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

Lighthouse
1 paths audited
Performance: 95 (no change from production)
Accessibility: 95 (🔴 down 2 from production)
Best Practices: 100 (no change from production)
SEO: 100 (🟢 up 8 from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

tomtseng commented 3 weeks ago

netlify deploy preview currently pointing at wrong commit from 2 hours ago https://github.com/AlignmentResearch/KataGoVisualizer/commit/4c59fc07f13e1dd0d33c15a71002df2a73194175 instead of 1341f2a, so deploy preview isn't showing changes yet

AdamGleave commented 3 weeks ago

I also just noticed that the highlighted row in the table doesn't update when you click on the move link.

tomtseng commented 3 weeks ago

If you're looking at the deploy preview, you'll need to re-trigger the netlify deploy (which I don't think I have the permissions to do) — it's stuck on the wrong commit, not sure why

AdamGleave commented 3 weeks ago

The Netlify build is failing:

7:59:16 PM: Netlify Build                                                 
7:59:16 PM: ────────────────────────────────────────────────────────────────
7:59:16 PM: ​
7:59:16 PM: ❯ Version
7:59:16 PM:   @netlify/build 29.46.5
7:59:16 PM: ​
7:59:16 PM: ❯ Flags
7:59:16 PM:   baseRelDir: true
7:59:16 PM:   buildId: 6663c8ddfd81e46e40d74883
7:59:16 PM:   deployId: 6663c8ddfd81e46e40d74885
7:59:16 PM: ​
7:59:16 PM: ❯ Current directory
7:59:16 PM:   /opt/build/repo/sgf-viewer
7:59:16 PM: ​
7:59:16 PM: ❯ Config file
7:59:16 PM:   /opt/build/repo/sgf-viewer/netlify.toml
7:59:16 PM: ​
7:59:16 PM: ❯ Context
7:59:16 PM:   deploy-preview
7:59:16 PM: ​
7:59:16 PM: ❯ Loading plugins
7:59:16 PM:    - @netlify/plugin-lighthouse@4.1.1 from Netlify app
7:59:16 PM: ​
7:59:16 PM: ❯ Outdated plugins
7:59:16 PM:    - @netlify/plugin-lighthouse@4.1.1: latest version is 6.0.0
7:59:16 PM:      To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)
7:59:18 PM: ​
7:59:18 PM: build.command from netlify.toml                               
7:59:18 PM: ────────────────────────────────────────────────────────────────
7:59:18 PM: ​
7:59:18 PM: $ npm run build
7:59:18 PM: > sgf-viewer-2@0.0.0 build
7:59:18 PM: > vite build
7:59:19 PM: vite v3.2.7 building for production...
7:59:19 PM: transforming...
7:59:20 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
7:59:20 PM: 2:59:20 AM [vite-plugin-svelte] /opt/build/repo/sgf-viewer/src/components/Citation.svelte:13:0 A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.
7:59:20 PM: 11: <hr />
7:59:20 PM: 12: <h4 class="toc-exclude">Citation Info</h4>
7:59:20 PM: 13: <code on:click={tdFocus}>
7:59:20 PM:     ^
7:59:20 PM: 14:     <pre>{`@inproceedings{wang2023adversarial,
15:   title={Adversarial Policies Beat Superhuman Go {AI}s},
2:59:20 AM [vite-plugin-svelte] /opt/build/repo/sgf-viewer/src/components/Citation.svelte:21:0 A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.
19: }`}</pre>
7:59:20 PM: 20: </code>
7:59:20 PM: 21: <code on:click={tdFocus}>
7:59:20 PM:     ^
7:59:20 PM: 22:     <pre>{`@misc{tseng2024challenges,
23:   title={Can Go {AI}s be adversarially robust?},
✓ 11 modules transformed.
7:59:20 PM: Could not resolve './components/Navbar.svelte' from src/App.svelte
7:59:20 PM: error during build:
7:59:20 PM: Error: Could not resolve './components/Navbar.svelte' from src/App.svelte
7:59:20 PM:     at error (file:///opt/build/repo/sgf-viewer/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
7:59:20 PM:     at ModuleLoader.handleResolveId (file:///opt/build/repo/sgf-viewer/node_modules/rollup/dist/es/shared/rollup.js:22156:24)
7:59:20 PM:     at file:///opt/build/repo/sgf-viewer/node_modules/rollup/dist/es/shared/rollup.js:22119:26
7:59:20 PM: ​
7:59:20 PM: "build.command" failed                                        
7:59:20 PM: ────────────────────────────────────────────────────────────────
7:59:20 PM: ​
7:59:20 PM:   Error message
7:59:20 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
7:59:20 PM: ​
7:59:20 PM:   Error location
7:59:20 PM:   In build.command from netlify.toml:
7:59:20 PM:   npm run build
7:59:20 PM: ​
7:59:20 PM:   Resolved config
7:59:20 PM:   build:
7:59:20 PM:     base: /opt/build/repo/sgf-viewer
7:59:20 PM:     command: npm run build
7:59:20 PM:     commandOrigin: config
7:59:20 PM:     environment:
7:59:20 PM:       - REVIEW_ID
7:59:20 PM:     publish: /opt/build/repo/sgf-viewer/dist
7:59:20 PM:     publishOrigin: config
7:59:20 PM:   plugins:
7:59:20 PM:     - inputs: {}
7:59:20 PM:       origin: ui
7:59:20 PM:       package: '@netlify/plugin-lighthouse'
7:59:20 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:59:20 PM: Failing build: Failed to build site
7:59:20 PM: Finished processing build request in 26.416s

I've invited you to Netlify so you can debug directly.

tomtseng commented 3 weeks ago

fixed and re-deployed

AdamGleave commented 3 weeks ago

Nice, works great now, will merge.