Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change back button to last viewed page #1522

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ec32029
changed back on match page to window's back
varCepheid Jan 15, 2023
71595ac
removed back attribute in page
varCepheid Jan 27, 2023
2fb4e73
added a link to event in match details card
varCepheid Feb 9, 2023
9abd4c7
Merge branch 'dev' into match-back-button
varCepheid Feb 9, 2023
4c1b581
more work on event links in matches
varCepheid Feb 9, 2023
5a142a7
fixed team numbers in match details card
varCepheid Feb 9, 2023
662e43f
continued trying to fix team numbers
varCepheid Feb 9, 2023
3c7179f
moved event title above date and removed back attributes
varCepheid Feb 10, 2023
1410018
attempted to fix grid layout
varCepheid Feb 10, 2023
4926a33
more styling for match cards
varCepheid Feb 10, 2023
5ad746c
grid styling, back button fix
varCepheid Feb 10, 2023
b9ba663
color and spacing fixes
varCepheid Feb 10, 2023
583597a
one more spacing fix
varCepheid Feb 10, 2023
7d9dee3
added a report editing page
varCepheid Feb 17, 2023
266f440
Merge branch 'dev' into match-back-button
varCepheid Feb 17, 2023
81d2b22
added functionality to support local or server reports
varCepheid Feb 24, 2023
43fdc9d
fixed URL typo and homepage error
varCepheid Feb 24, 2023
798549b
changed to using only report IDs in report editor
varCepheid Feb 24, 2023
0258408
bug fixes
varCepheid Feb 24, 2023
a25bce2
added a separate file for an editor for cached reports
varCepheid Feb 24, 2023
c7b7f48
fixed local editor input & simplified inputs
varCepheid Feb 24, 2023
7d96123
undid input-simplifying changes
varCepheid Feb 26, 2023
ac0d0f8
moved event link from match card to event page headers
varCepheid Jun 25, 2023
48752ef
lint fixes
varCepheid Jun 25, 2023
845d146
changed headers to sets of elements
varCepheid Jun 25, 2023
79dff07
changed link colors, added hover
varCepheid Jun 25, 2023
5f8c4a9
moved headerLinkStyle to Page
varCepheid Nov 7, 2023
6e1116b
reverted changes to match-card
varCepheid Nov 7, 2023
d0642c7
minor changes
varCepheid Nov 7, 2023
9458155
more moving event-page header styles to Page
varCepheid Nov 7, 2023
3f90658
changed colors greenOnPurple and redOnPurple to match accessibility g…
varCepheid Nov 7, 2023
5c613a6
Merge remote-tracking branch 'origin/dev' into match-back-button
calebeby Jan 6, 2024
6d69601
Merge remote-tracking branch 'origin/dev' into match-back-button
calebeby Feb 2, 2024
68b8bd4
Merge branch 'dev' into match-back-button
calebeby Feb 3, 2024
5e2bbc4
Remove `back` prop from about page component
calebeby Feb 3, 2024
ee45d65
requested changes
varCepheid Feb 17, 2024
50d9762
consolidated report-page elements, renamed report-edit-link
varCepheid Jul 5, 2024
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
4 changes: 2 additions & 2 deletions src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const lightGrey = '#E8E8E8'
export const faintGrey = '#f5f5f5'
export const blue = '#295dc0'
export const red = '#c30000'
export const greenOnPurple = '#4FAC40'
export const redOnPurple = '#D61E42'
export const greenOnPurple = '#47D232'
export const redOnPurple = '#FF3C2E'
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
export const offBlack = '#333'
export const focusRing = '#0044ff40'
2 changes: 1 addition & 1 deletion src/components/authenticated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const Authenticated = ({ label, render }: Props) => {

if (!jwt) {
return (
<Page name={label || 'Log In'} back={() => window.history.back()}>
<Page name={label || 'Log In'}>
{/* Don't flash the login page if we don't yet know if there is a jwt */}
{jwt === null ? (
<div class={loginStyle}>
Expand Down
22 changes: 15 additions & 7 deletions src/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RenderableProps, ComponentChildren } from 'preact'
import { ErrorBoundary } from './error-boundary'
import { css } from '@linaria/core'
import { createShadow } from '@/utils/create-shadow'
import { pigmicePurple } from '@/colors'
import { greenOnPurple, pigmicePurple } from '@/colors'
import IconButton, { iconButtonClass } from './icon-button'
import { mdiArrowLeft, mdiMenu } from '@mdi/js'
import clsx from 'clsx'
Expand Down Expand Up @@ -46,19 +46,27 @@ const headerText = css`
flex-shrink: 1;
text-overflow: ellipsis;
overflow: hidden;

& a {
color: white;

&:hover {
text-decoration-color: ${greenOnPurple};
}
}
`

type Props = Merge<
JSX.HTMLAttributes,
{
name: ComponentChildren
back: string | (() => void) | false
showBackButton?: boolean
class?: string
wrapperClass?: string
}
>

const Header = ({ back, name }: Omit<Props, 'class'>) => {
const Header = ({ name, showBackButton }: Omit<Props, 'class'>) => {
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
const [isMenuOpen, setIsMenuOpen] = useState(false)

const toggleMenu = () => setIsMenuOpen((isOpen) => !isOpen)
Expand All @@ -67,11 +75,11 @@ const Header = ({ back, name }: Omit<Props, 'class'>) => {
return (
<>
<header class={headerStyle}>
{back && (
{(showBackButton || showBackButton === undefined) && (
<IconButton
icon={mdiArrowLeft}
aria-label="Back"
{...{ [typeof back === 'string' ? 'href' : 'onClick']: back }}
onClick={() => window.history.back()}
/>
)}
<h1 class={headerText}>{name}</h1>
Expand All @@ -91,13 +99,13 @@ const Page = ({
class: className,
wrapperClass,
name,
back,
showBackButton,
...rest
}: RenderableProps<Props>) => {
return (
<ErrorBoundary>
<div class={clsx(wrapperClass)} {...rest}>
<Header name={name} back={back} />
<Header name={name} showBackButton={showBackButton} />
<main class={clsx(className)}>{children}</main>
</div>
</ErrorBoundary>
Expand Down
9 changes: 6 additions & 3 deletions src/components/report-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProfileLink } from './profile-link'

interface Props {
report: Report
onEditClick?: () => void
reportEditorLink?: string
}

const nameTypeSeparatorStyle = css`
Expand Down Expand Up @@ -62,7 +62,10 @@ const fieldValuesStyle = css`
`

// viewing a report on the report page
export const ReportViewer = ({ report, onEditClick }: Props) => {
export const ReportViewer = ({
report,
reportEditorLink: onEditClick,
}: Props) => {
const reporterId = report.reporterId
const eventInfo = useEventInfo(report.eventKey)
const matchInfo = useMatchInfo(report.eventKey, report.matchKey)
Expand Down Expand Up @@ -130,7 +133,7 @@ export const ReportViewer = ({ report, onEditClick }: Props) => {

{/* links to the author of the report */}
<ProfileLink reporterId={reporterId} />
{onEditClick && <Button onClick={onEditClick}>Edit</Button>}
{onEditClick && <Button href={onEditClick}>Edit</Button>}
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</>
)
}
8 changes: 8 additions & 0 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const routes = [
path: '/saved-reports/:reportKey',
component: () => import('./routes/saved-report'),
},
{
path: '/saved-reports/:reportKey/edit',
component: () => import('./routes/saved-report-edit'),
},
{
path: '/users/:userId',
component: () => import('./routes/user'),
Expand All @@ -71,6 +75,10 @@ const routes = [
path: '/reports/:reportId',
component: () => import('./routes/report'),
},
{
path: '/reports/:reportId/edit',
component: () => import('./routes/report-edit'),
},
]

export default routes
2 changes: 1 addition & 1 deletion src/routes/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sourceStyle = css`

const AboutPage = () => {
return (
<Page name="About" back="/" class={pageStyle}>
<Page name="About" class={pageStyle}>
<h1 class={headerStyle}>Welcome to Peregrine!</h1>
<section class={informationStyle}>
<p>
Expand Down
9 changes: 7 additions & 2 deletions src/routes/event-analysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ const teamStyle = css`
const EventAnalysis: FunctionComponent<Props> = ({ eventKey }) => {
const eventStats = usePromise(() => getEventStats(eventKey), [eventKey])
const eventInfo = useEventInfo(eventKey)
const eventName = eventInfo?.name || eventKey

const schema = useSchema(eventInfo?.schemaId)

return (
<Page
name={`Analysis - ${eventInfo ? eventInfo.name : eventKey}`}
back={`/events/${eventKey}`}
name={
<>
{'Analysis - '}
<a href={`/events/${eventKey}`}> {eventName} </a>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</>
}
class={tablePageStyle}
wrapperClass={tablePageWrapperStyle}
>
Expand Down
9 changes: 4 additions & 5 deletions src/routes/event-match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,11 @@ const EventMatch = ({ eventKey, matchKey }: Props) => {
return (
// page setup
<Page
back={`/events/${eventKey}`}
name={
m.group +
(m.num ? ' Match ' + m.num : '') +
' - ' +
(event ? event.name : eventKey)
<>
{m.group + (m.num ? ' Match ' + m.num : '') + ' - '}
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
<a href={`/events/${eventKey}`}> {event ? event.name : eventKey} </a>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</>
}
class={clsx(
matchStyle,
Expand Down
16 changes: 12 additions & 4 deletions src/routes/event-team-comments.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-nested-callbacks */

import Page from '@/components/page'
import { useEventInfo } from '@/cache/event-info/use'
import { css } from '@linaria/core'
import Card from '@/components/card'
import Loader from '@/components/loader'
Expand All @@ -10,6 +10,7 @@ import { formatMatchKeyShort } from '@/utils/format-match-key-short'
import { compareMatchKeys } from '@/utils/compare-matches'
import { GetReport } from '@/api/report'
import { getReports } from '@/api/report/get-reports'
import { useEventInfo } from '@/cache/event-info/use'

interface Props {
eventKey: string
Expand All @@ -27,12 +28,15 @@ const matchListStyle = css`
`

const EventTeamComments = ({ eventKey, teamNum }: Props) => {
const eventInfo = useEventInfo(eventKey)
const team = 'frc' + teamNum
const reports = usePromise(() => getReports({ team, event: eventKey }), [
team,
eventKey,
])

const eventInfo = useEventInfo(eventKey)
const eventName = eventInfo?.name || eventKey

const commentsByMatch = reports?.reduce<{ [matchKey: string]: GetReport[] }>(
(acc, report) => {
if (report.comment) {
Expand All @@ -46,8 +50,12 @@ const EventTeamComments = ({ eventKey, teamNum }: Props) => {

return (
<Page
name={`Comments: ${teamNum} @ ${eventInfo ? eventInfo.name : eventKey}`}
back={`/events/${eventKey}/teams/${teamNum}`}
name={
<>
{`Comments: ${teamNum} @ `}
<a href={`/events/${eventKey}`}> {eventName} </a>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</>
}
class={commentsPageStyle}
>
<Card class={matchListStyle}>
Expand Down
8 changes: 6 additions & 2 deletions src/routes/event-team-matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ const EventTeamMatches = ({ eventKey, teamNum }: Props) => {
const matches = useEventMatches(eventKey, 'frc' + teamNum)
return (
<Page
name={`Matches: ${teamNum} @ ${eventName}`}
back={`/events/${eventKey}/teams/${teamNum}`}
name={
<>
{`Matches: ${teamNum} @ `}
<a href={`/events/${eventKey}`}> {eventName} </a>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</>
}
class={eventTeamMatchesStyle}
>
{matches ? (
Expand Down
10 changes: 6 additions & 4 deletions src/routes/event-team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ const EventTeam = ({ eventKey, teamNum }: Props) => {
() => getEventTeamInfo(eventKey, 'frc' + teamNum).catch(() => undefined),
[eventKey, teamNum],
)
const eventName = eventInfo?.name || eventKey

const schema = useSchema(eventInfo?.schemaId)
const teamMatches = useEventMatches(eventKey, 'frc' + teamNum)?.sort(
compareMatches,
Expand All @@ -178,9 +180,10 @@ const EventTeam = ({ eventKey, teamNum }: Props) => {
<Page
name={
<span class={pageHeadingStyle}>
<span class={teamHeadingSpanStyle}>{`${teamNum} @ ${
eventInfo ? eventInfo.name : eventKey
}`}</span>
<span class={teamHeadingSpanStyle}>
{`${teamNum} @ `}
<a href={`/events/${eventKey}`}> {eventName} </a>
varCepheid marked this conversation as resolved.
Show resolved Hide resolved
</span>
<IconButton
icon={isTeamSaved ? mdiStar : mdiStarOutline}
onClick={() =>
Expand All @@ -192,7 +195,6 @@ const EventTeam = ({ eventKey, teamNum }: Props) => {
/>
</span>
}
back={`/events/${eventKey}`}
class={eventTeamStyle}
>
{nextMatch && (
Expand Down
7 changes: 1 addition & 6 deletions src/routes/event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ const Event = ({ eventKey }: Props) => {
const newestIncompleteMatch = matches && nextIncompleteMatch(matches)

return (
<Page
name={eventInfo?.name || <code>{eventKey}</code>}
back="/"
class={eventStyle}
>
<Page name={eventInfo?.name || <code>{eventKey}</code>} class={eventStyle}>
<div class={sectionStyle}>
<Heading level={2} class={headingStyle}>
Information
Expand All @@ -73,7 +69,6 @@ const Event = ({ eventKey }: Props) => {
</Heading>
{newestIncompleteMatch && (
<MatchDetailsCard
key={newestIncompleteMatch.key}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why you removed this attribute. Having a key attribute helps Preact with diffing, so that it knows the difference between when items were changed, added, reordered, or removed. I think there was some weird edge case where when this page rerendered (due to the newestIncompleteMatch switching), it might have reset the input on the event matches list, or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because the MatchDetailsCard component doesn't have key as a property. I don't know what it's passing into.

match={newestIncompleteMatch}
eventKey={eventKey}
link
Expand Down
2 changes: 1 addition & 1 deletion src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Home = () => {
const events = useEvents(year)

return (
<Page name="Home" back={false} class={homeStyle}>
<Page name="Home" class={homeStyle} showBackButton={false}>
<div class={filterStyle}>
<Dropdown options={years} onChange={setYear} value={year} />
<TextInput onInput={setQuery} label="Search for Events" />
Expand Down
2 changes: 1 addition & 1 deletion src/routes/leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Leaderboard = () => {
return (
<Authenticated
render={() => (
<Page name="Leaderboard" back="/">
<Page name="Leaderboard">
<LeaderboardList />
</Page>
)}
Expand Down
Loading
Loading