Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions ui/src/components/AboutView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChevronRight, Plus } from 'lucide-react'
import { fetchCoverage } from '../lib/api'
import { useLatestBatch } from '../hooks/useLatestBatch'
import { useTagCatalog } from '../hooks/useTagCatalog'
import { NEW_GRAPH_STATE } from '../hooks/useNewGraphRequest'
import { NEW_GRAPH_STATE, TOUR_STATE } from '../hooks/useRouteRequest'

const REPO_URL = 'https://github.com/ai-safety-graph/alignment-graph'
const ISSUES_URL = `${REPO_URL}/issues`
Expand Down Expand Up @@ -182,26 +182,25 @@ export default function AboutView() {
</div>

<Section title='How to use'>
<SubHeading>Quick start</SubHeading>
<ol className='list-decimal pl-5 flex flex-col gap-2'>
<li>
<span className='text-white'>Pick a topic.</span> Click{' '}
<span className='text-white'>New graph</span> and choose topic
tags, research domains and a date range. Turn on{' '}
<span className='text-white'>Peer-reviewed only</span> to keep
only accepted papers.
</li>
<li>
<span className='text-white'>Explore.</span> Each dot is a
paper, and papers on similar topics sit close together. Click
one to see its summary and related papers.
</li>
<li>
<span className='text-white'>Keep what's useful.</span> Save the
graph, then <span className='text-white'>Pin</span> papers to it
from their details.
</li>
</ol>
<p>
Click <span className='text-white'>New graph</span> and choose
topic tags, research domains and a date range, optionally only
peer-reviewed papers. Papers on similar topics sit close together;
click one for its summary and related papers, and{' '}
<span className='text-white'>Pin</span> the ones you want to keep.
</p>
{/* The tour lives in the graph view, which phones don't have */}
<p className='hidden md:block'>
New here?{' '}
<Link
to='/'
state={TOUR_STATE}
className='text-[#4ea8de] hover:underline'
>
Take the tour
</Link>{' '}
for a quick walk through the graph view.
</p>

<SubHeading>Views</SubHeading>
<ul className='list-disc pl-5 flex flex-col gap-2'>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/BrowseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { NewGraphButton, NewGraphMenuItem } from './NewGraph'
import GenerateGraphModal from './GenerateGraphModal'
import ShareLinkButton from './ShareLinkButton'
import SharedDraftBar from './SharedDraftBar'
import { useNewGraphRequest } from '../hooks/useNewGraphRequest'
import { useNewGraphRequest } from '../hooks/useRouteRequest'
import type { NodeCompact } from '../lib/types'
import { presetToFromDate, useServerFilters } from '../hooks/useServerFilters'
import { useMediaQuery } from '../hooks/useMediaQuery'
Expand Down
18 changes: 14 additions & 4 deletions ui/src/components/GraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { GRAPH_PICKER_WIDTH, HeaderLogo, ViewSwitch } from './HeaderNav'
import { NewGraphButton, NewGraphMenuItem } from './NewGraph'
import { track } from '../lib/analytics'
import { useCapabilities } from '../hooks/useCapabilities'
import { useNewGraphRequest } from '../hooks/useNewGraphRequest'
import { useNewGraphRequest, useTourRequest } from '../hooks/useRouteRequest'
import { useSharedGraph } from '../hooks/useSharedGraph'
import ShareLinkButton from './ShareLinkButton'

Expand Down Expand Up @@ -283,7 +283,12 @@ export default function ArxivGraph() {
const [confirmingDelete, setConfirmingDelete] = useState(false)
// Opened by the header's Tour button, or once on its own (see below)
const [tourOpen, setTourOpen] = useState(false)
// About's "Take the tour" asks for it even if it was seen before. Pending
// until the tour opens, so it shows once, not every time the effect reruns.
const tourRequested = useTourRequest()
const tourRequest = useRef(tourRequested)
const closeTour = () => {
tourRequest.current = false
setTourSeen()
setTourOpen(false)
}
Expand Down Expand Up @@ -373,11 +378,16 @@ export default function ArxivGraph() {
// a moment more for the layout to settle.
const hasPapers = !!data?.nodes.length
// It also stays out of the way of the "discard the draft?" prompt, and
// re-checks on firing in case the Tour button was used meanwhile.
// re-checks on firing in case the Tour button was used meanwhile. An
// explicit request from About doesn't wait for papers: the user just asked
// for it, so an empty graph shouldn't swallow the click.
useEffect(() => {
if (modal || pendingExit || !hasPapers || getTourSeen()) return
const wanted = () => tourRequest.current || (hasPapers && !getTourSeen())
if (modal || pendingExit || !wanted()) return
const timer = setTimeout(() => {
if (!getTourSeen()) setTourOpen(true)
if (!wanted()) return
tourRequest.current = false
setTourOpen(true)
}, 500)
return () => clearTimeout(timer)
}, [modal, pendingExit, hasPapers])
Expand Down
28 changes: 0 additions & 28 deletions ui/src/hooks/useNewGraphRequest.ts

This file was deleted.

39 changes: 39 additions & 0 deletions ui/src/hooks/useRouteRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

// Router state a link sets to ask the view it lands on to do something once.
// Both come from the About page.
type RouteRequest = 'newGraph' | 'tour'

// Open the new-graph modal ("Create a graph")
export const NEW_GRAPH_STATE = { newGraph: true } as const
// Show the graph tour, even if it was seen before ("Take the tour")
export const TOUR_STATE = { tour: true } as const

// Whether this view was opened with the given request. Read once on mount;
// the state is then cleared from history so a reload or Back doesn't repeat it.
function useRouteRequest(key: RouteRequest): boolean {
const location = useLocation()
const navigate = useNavigate()
const [requested] = useState(
() =>
(location.state as Partial<Record<RouteRequest, boolean>> | null)?.[
key
] === true,
)

useEffect(() => {
if (requested)
navigate(location.pathname + location.search, {
replace: true,
state: null,
})
// Only on mount: later navigations aren't requests
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return requested
}

export const useNewGraphRequest = () => useRouteRequest('newGraph')
export const useTourRequest = () => useRouteRequest('tour')
Loading