Skip to content

Commit

Permalink
feat(edit): adds default board layout (#1099)
Browse files Browse the repository at this point in the history
* feat(settings): adds default column settings

* chore(map tile): removes all map tile definitions and usage

* fix(ts): ts error when assigning const

* feat(settings): refactor to implicit default columns implementation
  • Loading branch information
stianjsu authored Jul 5, 2023
1 parent 19d127d commit 500e83a
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 65 deletions.
26 changes: 0 additions & 26 deletions next-tavla/src/Admin/scenarios/AddTile/components/AddMapTile.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions next-tavla/src/Admin/scenarios/AddTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import { AddStopPlaceTile } from './components/AddStopPlaceTile'
import { AddQuayTile } from './components/AddQuayTile'
import { TAnonTiles } from 'Admin/types'
import { useSettingsDispatch } from 'Admin/utils/contexts'
import { AddMapTile } from './components/AddMapTile'

const components: Record<
TTileType,
(props: { setTile: (tile: TAnonTiles) => void }) => JSX.Element
> = {
stop_place: AddStopPlaceTile,
quay: AddQuayTile,
map: AddMapTile,
}

function AddTile() {
Expand Down
20 changes: 14 additions & 6 deletions next-tavla/src/Admin/scenarios/Edit/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { TAnonTiles } from 'Admin/types'
import { clone, xor } from 'lodash'
import { nanoid } from 'nanoid'
import { TSettings, TTheme } from 'types/settings'
import { TColumn, TQuayTile, TStopPlaceTile, TTile } from 'types/tile'
import {
DefaultColumns,
TColumn,
TQuayTile,
TStopPlaceTile,
TTile,
} from 'types/tile'
import { TColumnSetting } from 'types/tile'

export type Action =
Expand Down Expand Up @@ -82,7 +88,7 @@ export function settingsReducer(
return {
...settings,
tiles: arrayMove(
settings.tiles,
settings.tiles ?? [...DefaultColumns],
action.oldIndex,
action.newIndex,
),
Expand All @@ -96,7 +102,7 @@ export function settingsReducer(
return {
...tile,
columns: [
...(tile.columns || []),
...(tile.columns || [...DefaultColumns]),
{ type: action.column },
],
}
Expand All @@ -107,9 +113,10 @@ export function settingsReducer(
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
const cols = tile.columns ?? [...DefaultColumns]
return {
...tile,
columns: tile.columns?.filter(
columns: cols.filter(
(col) => col.type !== action.column,
),
}
Expand All @@ -120,9 +127,10 @@ export function settingsReducer(
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
const cols = tile.columns ?? [...DefaultColumns]
return {
...tile,
columns: tile.columns?.map((col) =>
columns: cols.map((col) =>
col.type === action.columnSetting.type
? action.columnSetting
: col,
Expand All @@ -138,7 +146,7 @@ export function settingsReducer(
return {
...tile,
columns: arrayMove(
tile.columns || [],
tile.columns || [...DefaultColumns],
action.oldIndex,
action.newIndex,
),
Expand Down
3 changes: 2 additions & 1 deletion next-tavla/src/Admin/scenarios/SortableColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@dnd-kit/sortable'
import {
Columns,
DefaultColumns,
TColumn,
TColumnSetting,
TQuayTile,
Expand All @@ -35,7 +36,7 @@ function SortableColumns<T extends TStopPlaceTile | TQuayTile>({
tile: T
defaultOpen?: boolean
}) {
const columns: TColumnSetting[] = tile.columns ?? []
const columns: TColumnSetting[] = tile.columns ?? [...DefaultColumns]

const sensors = useSensors(
useSensor(PointerSensor),
Expand Down
2 changes: 0 additions & 2 deletions next-tavla/src/Admin/scenarios/TilesSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ function TilesSettings({ tiles }: { tiles: TTile[] }) {
return (
<QuaySettings key={tile.uuid} tile={tile} />
)
case 'map':
return null
}
})}
</div>
Expand Down
7 changes: 2 additions & 5 deletions next-tavla/src/Admin/types/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { TMapTile, TQuayTile, TStopPlaceTile, TTile } from 'types/tile'
import { TQuayTile, TStopPlaceTile, TTile } from 'types/tile'

export type TAnon<T extends TTile> = Omit<T, 'uuid'>

export type TAnonTiles =
| TAnon<TQuayTile>
| TAnon<TStopPlaceTile>
| TAnon<TMapTile>
export type TAnonTiles = TAnon<TQuayTile> | TAnon<TStopPlaceTile>
3 changes: 0 additions & 3 deletions next-tavla/src/Board/scenarios/Board/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TSettings } from 'types/settings'
import { TTile } from 'types/tile'
import { StopPlaceTile } from '../StopPlaceTile'
import { MapTile } from '../MapTile'
import { QuayTile } from '../QuayTile'
import classes from './styles.module.css'

Expand All @@ -11,8 +10,6 @@ function Tile({ tileSpec }: { tileSpec: TTile }) {
return <StopPlaceTile {...tileSpec} />
case 'quay':
return <QuayTile {...tileSpec} />
case 'map':
return <MapTile {...tileSpec} />
}
}

Expand Down
8 changes: 0 additions & 8 deletions next-tavla/src/Board/scenarios/MapTile/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions next-tavla/src/Board/scenarios/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TDepartureFragment } from 'graphql/index'
import { Columns, TColumn, TColumnSetting } from 'types/tile'
import { Columns, DefaultColumns, TColumn, TColumnSetting } from 'types/tile'
import React from 'react'
import classes from './styles.module.css'
import { DepartureContext } from './contexts'
Expand Down Expand Up @@ -34,7 +34,7 @@ function flexToPercentage(columnSettings: TColumnSetting[]) {
}

function Table({
columns = [],
columns = [...DefaultColumns],
departures,
}: {
columns?: TColumnSetting[]
Expand Down
13 changes: 8 additions & 5 deletions next-tavla/src/Shared/types/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const Columns = {
export type TColumn = keyof typeof Columns
export type TColumnSetting = { type: TColumn; size?: number }

export const DefaultColumns: readonly TColumnSetting[] = [
{ type: 'line' },
{ type: 'destination', size: 2 },
{ type: 'situations', size: 2 },
{ type: 'time' },
] as const

export type TTileType = TTile['type']

type TBaseTile = {
Expand All @@ -34,8 +41,4 @@ export type TStopPlaceTile = {
whitelistedTransportModes?: TTransportMode[]
} & TBaseTile

export type TMapTile = {
type: 'map'
} & TBaseTile

export type TTile = TStopPlaceTile | TMapTile | TQuayTile
export type TTile = TStopPlaceTile | TQuayTile
6 changes: 1 addition & 5 deletions next-tavla/src/Shared/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ type TBaseStopPlaceTile = {
whitelistedTransportModes?: TBaseTransportMode[]
} & TBaseTile

type TBaseMapTile = {
type: 'map'
} & TBaseTile

type TBaseBaseTile = TBaseStopPlaceTile | TBaseMapTile | TBaseQuayTile
type TBaseBaseTile = TBaseStopPlaceTile | TBaseQuayTile

type TBaseSetting = {
tiles: TBaseBaseTile[]
Expand Down

0 comments on commit 500e83a

Please sign in to comment.