Skip to content

Commit

Permalink
Merge pull request #34 from r00tat/enhancement/layer-grouping
Browse files Browse the repository at this point in the history
Allow layers to be grouped
  • Loading branch information
r00tat authored Jan 17, 2024
2 parents b7644cf + 7a1a104 commit 1e4a9be
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/FirecallItems/FirecallItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function FirecallItemCard({
)}
</CardActions>
)}
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Collapse in={expanded} timeout={1000} unmountOnExit>
<CardContent>
<Grid container spacing={2}>
{subItems &&
Expand Down
31 changes: 27 additions & 4 deletions src/components/FirecallItems/elements/FirecallItemLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { FirecallItem, FirecallLayer } from '../../firebase/firestore';
import { SimpleMap } from '../../../common/types';
import { FirecallLayer } from '../../firebase/firestore';
import { FirecallItemBase } from './FirecallItemBase';

export interface FirecallItemLayerInt extends FirecallItem, FirecallLayer {}

export class FirecallItemLayer extends FirecallItemBase {
public constructor(firecallItem?: FirecallItemLayerInt) {
grouped?: string;

public constructor(firecallItem?: FirecallLayer) {
super({
...(firecallItem || { name: '' }),
type: 'layer',
} as FirecallItemLayer);
this.type = 'layer';
({ grouped: this.grouped = '' } = firecallItem || {});
}

public static firebaseCollectionName(): string {
Expand All @@ -23,4 +25,25 @@ export class FirecallItemLayer extends FirecallItemBase {
public copy(): FirecallItemBase {
return Object.assign(new FirecallItemLayer(this.data()), this);
}

public fields(): SimpleMap<string> {
return {
...super.fields(),
grouped: 'Elemente gruppieren',
};
}

public fieldTypes(): SimpleMap<string> {
return {
...super.fieldTypes(),
grouped: 'boolean',
};
}

public data(): FirecallLayer {
return {
...super.data(),
grouped: this.grouped,
};
}
}
14 changes: 11 additions & 3 deletions src/components/Map/layers/FirecallLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useFirecallId } from '../../../hooks/useFirecall';
import FirecallItemsLayer from './FirecallItemsLayer';
import FirecallMarker from '../markers/FirecallMarker';
import { useFirecallLayers } from '../../../hooks/useFirecallLayers';
import MarkerClusterLayer from './MarkerClusterLayer';

export default function FirecallLayer() {
const firecallId = useFirecallId();
Expand All @@ -28,9 +29,16 @@ export default function FirecallLayer() {
checked
key={layerId}
>
<LayerGroup>
<FirecallItemsLayer layer={layer} />
</LayerGroup>
{layer.grouped === 'true' && (
<MarkerClusterLayer>
<FirecallItemsLayer layer={layer} />
</MarkerClusterLayer>
)}
{layer.grouped !== 'true' && (
<LayerGroup>
<FirecallItemsLayer layer={layer} />
</LayerGroup>
)}
</LayersControl.Overlay>
))}
</>
Expand Down
6 changes: 2 additions & 4 deletions src/components/firebase/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ export interface FirecallItem {
created?: string;
}

export interface FirecallLayer {
id?: string;
name: string;
beschreibung?: string;
export interface FirecallLayer extends FirecallItem {
grouped?: string;
}

export interface FcAttachment {
Expand Down
6 changes: 3 additions & 3 deletions src/components/pages/Layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ export default function LayersPage() {
<Grid item xs={6} md={6} lg={6} xl={8}>
<Typography variant="h5">Erstellte Ebenen</Typography>
<Grid container spacing={2}>
{Object.values(layers).map((item) => (
{Object.entries(layers).map(([layerId, item]) => (
<DroppableFirecallCard
item={item}
key={item.id}
subItems={layerItems[item.id]}
key={layerId}
subItems={layerItems[layerId]}
/>
))}
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useFirecallLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type FirecallLayers = SimpleMap<FirecallLayer>;
export const FirecallLayersContext = React.createContext<FirecallLayers>({});

export const useFirecallLayers = () => {
const { layers } = useContext(FirecallLayersContext);
const layers = useContext(FirecallLayersContext);
return layers;
};

Expand All @@ -26,5 +26,5 @@ export function useFirecallLayersFromFirstore(): FirecallLayers {
queryConstraints: [orderBy('name', 'asc')],
});

return { layers: Object.fromEntries(layers.map((l) => [l.id, l])) };
return Object.fromEntries(layers.map((l) => [l.id, l]));
}

0 comments on commit 1e4a9be

Please sign in to comment.