Skip to content

Commit

Permalink
feat: RunRow toggle selection & cursor pointer (yihong0618#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
orionna319 authored Nov 24, 2023
1 parent dbdfa8c commit 048e941
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/components/RunTable/RunRow.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { formatPace, titleForRun, formatRunTime, Activity } from '@/utils/utils';
import { formatPace, titleForRun, formatRunTime, Activity, RunIds } from '@/utils/utils';
import styles from './style.module.scss';

interface IRunRowProperties {
elementIndex: number;
locateActivity: (_date: string) => void;
locateActivity: (_runIds: RunIds) => void;
run: Activity;
runIndex: number;
setRunIndex: (_ndex: number) => void;
Expand All @@ -16,7 +16,11 @@ const RunRow = ({ elementIndex, locateActivity, run, runIndex, setRunIndex }: IR
const heartRate = run.average_heartrate;
const runTime = formatRunTime(run.moving_time);
const handleClick = () => {
if (runIndex === elementIndex) return;
if (runIndex === elementIndex) {
setRunIndex(-1);
locateActivity([]);
return
};
setRunIndex(elementIndex);
locateActivity([run.run_id]);
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/RunTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
sortDateFuncReverse,
convertMovingTime2Sec,
Activity,
RunIds,
} from '@/utils/utils';
import RunRow from './RunRow';
import styles from './style.module.scss';

interface IRunTableProperties {
runs: Activity[];
locateActivity: (_date: string) => void;
locateActivity: (_runIds: RunIds) => void;
setActivity: (_runs: Activity[]) => void;
runIndex: number;
setRunIndex: (_index: number) => void;
Expand Down
1 change: 1 addition & 0 deletions src/components/RunTable/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}

.runRow {
cursor: pointer;
td {
padding: 0.5rem;
border: 0;
Expand Down
7 changes: 5 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
scrollToMap,
sortDateFunc,
titleForShow,
RunIds,
} from '@/utils/utils';

const Index = () => {
Expand Down Expand Up @@ -74,10 +75,12 @@ const Index = () => {
changeByItem(title, 'Title', filterTitleRuns);
};

const locateActivity = (runIds: [Number]) => {
const locateActivity = (runIds: RunIds) => {
const ids = new Set(runIds);

const selectedRuns = runs.filter((r) => ids.has(r.run_id));
const selectedRuns = !runIds.length
? runs
: runs.filter((r: any) => ids.has(r.run_id));

if (!selectedRuns.length) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { FeatureCollection, LineString } from 'geojson';

export type Coordinate = [number, number];

export type RunIds = Array<number> | [];

export interface Activity {
run_id: number;
name: string;
Expand Down

0 comments on commit 048e941

Please sign in to comment.