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

fix(frontend): correct compile error due to missing /lib folder #210

Merged
merged 1 commit into from
Oct 16, 2024
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
2 changes: 1 addition & 1 deletion frontend/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"rsc": false,
"aliases": {
"utils": "@/lib/utils",
"utils": "@/libs/utils",
"components": "@/components"
}
}
2 changes: 1 addition & 1 deletion frontend/components/providers/map-store-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createContext, useContext, useRef, type ReactNode } from "react"
import { useStore, type StoreApi } from "zustand"

import { createMapStore, type MapStore } from "@/lib/stores/map-store"
import { createMapStore, type MapStore } from "@/libs/stores/map-store"

export const MapStoreContext = createContext<StoreApi<MapStore> | null>(null)

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/providers/vessels-store-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createContext, useContext, useRef, type ReactNode } from "react"
import { useStore, type StoreApi } from "zustand"
import { VesselsState, createVesselsStore, type VesselsStore } from "@/lib/stores/vessels-store"
import { VesselsState, createVesselsStore, type VesselsStore } from "@/libs/stores/vessels-store"

export const VesselsStoreContext = createContext<StoreApi<VesselsStore> | null>(null)

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"
import { cn } from "@/libs/utils"

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type DialogProps } from "@radix-ui/react-dialog"
import { Command as CommandPrimitive } from "cmdk"
import { Search } from "lucide-react"

import { cn } from "@/lib/utils"
import { cn } from "@/libs/utils"
import { Dialog, DialogContent } from "@/components/ui/dialog"

const Command = React.forwardRef<
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"
import { cn } from "@/libs/utils"

const Dialog = DialogPrimitive.Root

Expand Down
11 changes: 11 additions & 0 deletions frontend/libs/fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { JetBrains_Mono as FontMono, Inter as FontSans } from "next/font/google"

export const fontSans = FontSans({
subsets: ["latin"],
variable: "--font-sans",
})

export const fontMono = FontMono({
subsets: ["latin"],
variable: "--font-mono",
})
115 changes: 115 additions & 0 deletions frontend/libs/stores/map-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { VesselExcursionSegment, VesselExcursionSegments, VesselExcursionSegmentsGeo, VesselPosition } from "@/types/vessel"
import { MapViewState } from "@deck.gl/core"
import { createStore } from "zustand/vanilla"

export interface ViewState {
longitude: number
latitude: number
zoom: number
pitch?: number
bearing?: number
transitionDuration?: number
transitionInterpolator?: any
}

export type MapState = {
count: number
viewState: MapViewState
latestPositions: VesselPosition[]
activePosition: VesselPosition | null
trackedVesselIDs: number[]
trackedVesselSegments: VesselExcursionSegments[]
}

export type MapActions = {
decrementCount: () => void
incrementCount: () => void
setViewState: (viewState: MapViewState) => void
setZoom: (zoom: number) => void
setLatestPositions: (latestPositions: VesselPosition[]) => void
setActivePosition: (activePosition: VesselPosition | null) => void
addTrackedVessel: (vesselID: number, segments: VesselExcursionSegment[]) => void
removeTrackedVessel: (vesselID: number) => void
clearLatestPositions: () => void
cleartrackedVessels: () => void
}

export type MapStore = MapState & MapActions

export const defaultInitState: MapState = {
count: 0,
viewState: {
longitude: 3.788086,
latitude: 47.840291,
zoom: 5,
pitch: 20,
bearing: 0,
},
latestPositions: [],
activePosition: null,
trackedVesselIDs: [],
trackedVesselSegments: []
}

export const createMapStore = (initState: MapState = defaultInitState) => {
return createStore<MapStore>()((set) => ({
...initState,
decrementCount: () => set((state) => ({ count: state.count - 1 })),
incrementCount: () => set((state) => ({ count: state.count + 1 })),
setViewState: (viewState?: MapViewState) => {
set((state) => ({
...state,
viewState,
}))
},
setZoom: (zoom: number) => {
set((state) => ({
...state,
viewState: { ...state.viewState, zoom },
}))
},
setLatestPositions: (latestPositions: VesselPosition[]) => {
set((state) => ({
...state,
latestPositions,
}))
},
setActivePosition: (activePosition: VesselPosition | null) => {
set((state) => ({
...state,
activePosition,
}))
},
addTrackedVessel: (vesselId: number, segments: VesselExcursionSegment[]) => {
set((state) => ({
...state,
trackedVesselIDs: [...state.trackedVesselIDs, vesselId],
trackedVesselSegments: [...state.trackedVesselSegments, { vesselId, segments }]
}))
},
removeTrackedVessel: (vesselId: number) => {
set((state) => ({
...state,
trackedVesselIDs: state.trackedVesselIDs.filter(
(id) => id !== vesselId
),
trackedVesselSegments: state.trackedVesselSegments.filter(
({vesselId}) => vesselId !== vesselId
),
}))
},
clearLatestPositions: () => {
set((state) => ({
...state,
latestPositions: [],
}))
},
cleartrackedVessels: () => {
set((state) => ({
...state,
trackedVesselIDs: [],
trackedVesselSegments: []
}))
},
}))
}
34 changes: 34 additions & 0 deletions frontend/libs/stores/vessels-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Vessel } from "@/types/vessel"
import { createStore } from "zustand/vanilla"

export type VesselsState = {
count: number;
vessels: Vessel[];
}

export type MapActions = {
decrementCount: () => void
incrementCount: () => void
setVessels: (vessels: Vessel[]) => void
}

export type VesselsStore = VesselsState & MapActions

export const defaultInitState: VesselsState = {
count: 0,
vessels: [],
}

export const createVesselsStore = (initState: VesselsState = defaultInitState) => {
return createStore<VesselsStore>()((set) => ({
...initState,
decrementCount: () => set((state) => ({ count: state.count - 1 })),
incrementCount: () => set((state) => ({ count: state.count + 1 })),
setVessels: (vessels: Vessel[]) => {
set((state) => ({
...state,
vessels,
}))
}
}))
}
6 changes: 6 additions & 0 deletions frontend/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
2 changes: 1 addition & 1 deletion frontend/prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
"^types$",
"^@/types/(.*)$",
"^@/config/(.*)$",
"^@/lib/(.*)$",
"^@/libs/(.*)$",
"^@/hooks/(.*)$",
"^@/components/ui/(.*)$",
"^@/components/(.*)$",
Expand Down
Loading