Skip to content

Commit

Permalink
Merge pull request #55 from TurtIeSocks/various-client-adjustments
Browse files Browse the repository at this point in the history
various client adjustments
  • Loading branch information
TurtIeSocks authored Jan 4, 2023
2 parents 56c8c8f + 357bff5 commit 0586faa
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 242 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Docker
on:
push:
branches: [main]
pull_request:
branches: [main]
on: [push]

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -34,11 +30,15 @@ jobs:
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "koji",
"version": "0.3.1",
"version": "0.3.2",
"description": "Tool to make RDM routes",
"main": "server/dist/index.js",
"author": "TurtIeSocks <[email protected]>",
Expand Down
6 changes: 6 additions & 0 deletions client/src/assets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import * as L from 'leaflet'
import type { UsePersist } from '@hooks/usePersist'
import type { UseStatic } from '@hooks/useStatic'

export type SpecificValueType<T, U> = {
[k in keyof T]: T[k] extends U ? k : never
}[keyof T]

export type OnlyType<T, U> = { [k in SpecificValueType<T, U>]: U }

export interface Data {
gyms: PixiMarker[]
pokestops: PixiMarker[]
Expand Down
1 change: 1 addition & 0 deletions client/src/components/dialogs/Manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function Manager({ open, setOpen, geojson }: Props) {
Save to Koji
</Button>
<Button
disabled
onClick={() =>
save('/api/v1/geofence/save-scanner', code).then((res) =>
console.log(res),
Expand Down
15 changes: 7 additions & 8 deletions client/src/components/dialogs/Polygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type { ToConvert } from '@assets/types'
import { usePersist } from '@hooks/usePersist'
import { useShapes } from '@hooks/useShapes'
import { convert } from '@services/fetches'
import MultiOptions from '@components/drawer/inputs/MultiOptions'

import DialogHeader from './Header'
import { Code } from '../Code'
import BtnGroup from '../drawer/inputs/BtnGroup'

interface Props {
open: string
Expand Down Expand Up @@ -40,7 +40,6 @@ export default function ExportPolygon({
}: Import | Export | ExportAll): JSX.Element {
const polygonExportMode = usePersist((s) => s.polygonExportMode)
const simplifyPolygons = usePersist((s) => s.simplifyPolygons)
const setStore = usePersist((s) => s.setStore)

const add = useShapes((s) => s.setters.add)

Expand Down Expand Up @@ -147,22 +146,22 @@ export default function ExportPolygon({
</DialogContent>
<DialogActions>
{(mode === 'export' || mode === 'exportAll') && (
<BtnGroup
<MultiOptions
field="polygonExportMode"
value={polygonExportMode}
setValue={setStore}
buttons={[
'featureCollection',
'feature',
'array',
'multiArray',
'feature',
'featureCollection',
'struct',
'multiStruct',
'text',
'altText',
'poracle',
]}
/>
)}
<Button onClick={() => navigator.clipboard.writeText(code)}>
<Button onPointerDown={() => navigator.clipboard.writeText(code)}>
Copy to Clipboard
</Button>
<Button
Expand Down
26 changes: 26 additions & 0 deletions client/src/components/drawer/drawing/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { List, Divider, ListItem } from '@mui/material'

import ListSubheader from '../../styled/Subheader'
import Toggle from '../inputs/Toggle'
import MultiOptions from '../inputs/MultiOptions'

export default function DrawingTab() {
return (
<List dense>
<ListSubheader disableGutters>Drawing Options</ListSubheader>
<Toggle field="snappable" />
<Toggle field="continueDrawing" />
<ListItem>
Activate:
<MultiOptions field="setActiveMode" buttons={['hover', 'click']} />
</ListItem>
<Divider sx={{ my: 2 }} />
<ListSubheader disableGutters>Vectors</ListSubheader>
<Toggle field="showCircles" />
<Toggle field="showLines" />
<Toggle field="showPolygons" />
<Toggle field="showArrows" />
</List>
)
}
44 changes: 0 additions & 44 deletions client/src/components/drawer/geofence/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions client/src/components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { safeParse } from '@services/utils'

import { Drawer } from '../styled/Drawer'
import DrawerHeader from '../styled/DrawerHeader'
import GeofenceTab from './geofence'
import DrawingTab from './drawing'
import RoutingTab from './routing'
import MenuAccordion from './MenuItem'
import ImportExport from './manage'
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function DrawerIndex({ drawerWidth }: Props) {
{!!i && <Divider />}
<MenuAccordion name={text}>
{{
Drawing: <GeofenceTab />,
Drawing: <DrawingTab />,
Clustering: <RoutingTab />,
Manage: <ImportExport />,
Settings: <Settings />,
Expand Down
39 changes: 0 additions & 39 deletions client/src/components/drawer/inputs/BtnGroup.tsx

This file was deleted.

22 changes: 10 additions & 12 deletions client/src/components/drawer/inputs/DateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ import dayjs from 'dayjs'
import TextField from '@mui/material/TextField'
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'

import { type UsePersist } from '@hooks/usePersist'
import { usePersist, type UsePersist } from '@hooks/usePersist'
import { fromCamelCase, fromSnakeCase } from '@services/utils'
import { ListItem } from '@mui/material'
import { OnlyType } from '@assets/types'

interface Props<T extends keyof UsePersist> {
export default function DateTime<T extends keyof OnlyType<UsePersist, Date>>({
field,
disabled,
}: {
field: T
value: Date
setValue: (field: Props<T>['field'], value: Props<T>['value']) => void
disabled?: boolean
}
}) {
const value = usePersist((s) => s[field])
const setStore = usePersist((s) => s.setStore)

export default function DateTime<T extends keyof UsePersist>({
field,
value,
setValue,
disabled,
}: Props<T>) {
return (
<ListItem>
<DateTimePicker
Expand All @@ -35,7 +33,7 @@ export default function DateTime<T extends keyof UsePersist>({
value={dayjs(value)}
onChange={(newValue) => {
if (newValue) {
setValue(field, newValue.set('second', 0).set('minute', 0).toDate())
setStore(field, newValue.set('second', 0).set('minute', 0).toDate())
}
}}
/>
Expand Down
62 changes: 62 additions & 0 deletions client/src/components/drawer/inputs/MultiOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as React from 'react'
import {
ToggleButtonGroup,
ToggleButton,
Select,
MenuItem,
} from '@mui/material'

import { usePersist, type UsePersist } from '@hooks/usePersist'
import { fromCamelCase, fromSnakeCase } from '@services/utils'
import { OnlyType } from '@assets/types'

export default function MultiOptions<
T extends keyof OnlyType<UsePersist, string>,
K extends UsePersist[T],
>({
field,
buttons,
disabled = false,
type = 'button',
}: {
field: T
buttons: K[]
disabled?: boolean
type?: 'button' | 'select'
}) {
const value = usePersist((s) => s[field])
const setStore = usePersist((s) => s.setStore)

return type === 'button' ? (
<ToggleButtonGroup
size="small"
color="primary"
value={value}
exclusive
onChange={(_e, v) => setStore(field, v)}
sx={{ mx: 'auto' }}
disabled={disabled}
>
{buttons.map((m) => (
<ToggleButton key={m} value={m} disabled={disabled}>
{m.includes('_') ? fromSnakeCase(m) : fromCamelCase(m)}
</ToggleButton>
))}
</ToggleButtonGroup>
) : (
<Select
size="small"
color="primary"
value={value}
onChange={({ target }) => setStore(field, target.value as K)} // Mui y u like this
sx={{ mx: 'auto' }}
disabled={disabled}
>
{buttons.map((m) => (
<MenuItem key={m} value={m}>
{m.includes('_') ? fromSnakeCase(m) : fromCamelCase(m)}
</MenuItem>
))}
</Select>
)
}
34 changes: 14 additions & 20 deletions client/src/components/drawer/inputs/NumInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import * as React from 'react'
import { ListItem, ListItemText, TextField } from '@mui/material'

import { fromCamelCase, fromSnakeCase } from '@services/utils'
import { UsePersist, usePersist } from '@hooks/usePersist'
import { OnlyType } from '@assets/types'

interface Props<T> {
export default function NumInput<
T extends keyof OnlyType<UsePersist, number | ''>,
>({
field,
endAdornment,
disabled = false,
}: {
field: T
value: number | ''
setValue: (field: T, value: number | '') => void
disabled?: boolean
endAdornment?: string
}
}) {
const value = usePersist((s) => s[field])
const setStore = usePersist((s) => s.setStore)

export default function NumInput<T extends string>({
field,
value,
setValue,
endAdornment,
disabled = false,
}: Props<T>) {
return (
<ListItem disabled={disabled}>
<ListItemText
Expand All @@ -28,17 +29,10 @@ export default function NumInput<T extends string>({
/>
<TextField
name={field}
value={value}
value={value || ''}
type="number"
size="small"
onChange={({ target }) => {
setValue(
field,
target.value && (+target.value || target.value === '0')
? +target.value
: '',
)
}}
onChange={({ target }) => setStore(field, +target.value)}
sx={{ width: '35%' }}
inputProps={{ min: 0, max: 9999 }}
InputProps={{ endAdornment }}
Expand Down
Loading

0 comments on commit 0586faa

Please sign in to comment.