Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
doc(#1266): Add tutorial for creating layers in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
hatchla committed Apr 21, 2024
1 parent 4dd3a2a commit 3424f3a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions doc/guidelines/frontend-create-layer-tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Creating a New Layer in Frontend

This document gives guidelines on how to implement a new layer in the frontend.

## Folder Structure

- Navigate to the `layers` directory in your project (`features/map_planning/layers`).
- Create a new folder named after the type of layer you want to add (e.g., "NewLayer").

## Add Necessary Files and Folders

- Inside the "NewLayer" folder:
- If your layer requires API interactions, create an `api` folder and place your .ts files in there or place them into the map_planning api folder depending on wheter its a special api that is part of the layer or its just for initiating the layer in general.
- For React components or custom hooks specific to this layer, add a `components` or `hooks` folder.
- Create a main TypeScript file for the layer (e.g., `NewLayer.tsx`).

## Define the Layer Component

- In `NewLayer.tsx`:
- Import Konva and other dependencies.
- Define a functional component that returns a Konva `Layer`.
- In `mapEditorHookApi.ts`:
- Define a hook for your layer (e.g., `useNewLayer.tsx`).
- Add states that need be saved across components.
- Add init function (e.g., `initNewLayer`) which is then defined inside the `TrackedMapStore.ts`.

## Implement Layer Logic

- Use hooks (starting with `use` in the name) and the global MapStore (tracked & untracked) to manage state and interactions.
- **Tracked** is used for storing changes that can be rolled back with undo/redo.
- **Untracked** containes all other states that are not affected by this.
- Ensure proper interaction with other layers and elements.

## Test Your Layer

- Write tests for hooks if feasable/useful (see plant/hooks) to verify functionality.
- Especially if side effects or wrong behaviour can not be easily seen in manual tests!

0 comments on commit 3424f3a

Please sign in to comment.