Skip to content

Commit

Permalink
vehicles: switch to data loading (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling authored Jun 11, 2024
1 parent dc8515a commit b208189
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
8 changes: 8 additions & 0 deletions ui/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { db } from '$lib/database';

export async function load() {
const vehicles = await db.selectFrom('vehicle').where('company', '=', 1).selectAll().execute();
return {
vehicles
};
}
19 changes: 13 additions & 6 deletions ui/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
const { data } = $props();
import { getCompany } from '$lib/api';
import type { Company } from '$lib/types';
import { getVehicles } from '$lib/api';
import { DateFormatter, today, getLocalTimeZone } from '@internationalized/date';
import CalendarIcon from 'lucide-svelte/icons/calendar';
Expand Down Expand Up @@ -39,7 +39,7 @@
let vehicles = $state<Map<number, Vehicle>>(new Map<number, Vehicle>());
onMount(async () => {
vehicles = new Map<number, Vehicle>(
(await getVehicles(1)).map((v) => [
data.vehicles.map((v) => [
v.id,
{
license_plate: v.license_plate,
Expand Down Expand Up @@ -179,6 +179,7 @@
};
const selectionFinish = () => {
console.log('Selection FIN');
if (selection !== null) {
console.log(selection.available, getSelection());
selection = null;
Expand Down Expand Up @@ -214,12 +215,14 @@
};
const dragOver = (vehicle_id: number) => {
draggedTours!.vehicle_id = vehicle_id;
if (draggedTours !== null) {
draggedTours!.vehicle_id = vehicle_id;
}
};
const onDrop = () => {
if (!hasOverlap()) {
draggedTours!.tours.forEach((t) => (t.vehicle_id = draggedTours!.vehicle_id));
if (draggedTours !== null && !hasOverlap()) {
draggedTours.tours.forEach((t) => (t.vehicle_id = draggedTours!.vehicle_id));
}
draggedTours = null;
};
Expand Down Expand Up @@ -285,6 +288,7 @@
<tr>
{#each split(x, 15) as cell}
<td
class="cell"
draggable={hasTour(id, cell)}
ondragstart={() => dragStart(id, cell)}
ondragover={() => dragOver(id)}
Expand Down Expand Up @@ -377,3 +381,6 @@
</Card.Content>
</Card.Root>
</div>

<style>
</style>
8 changes: 0 additions & 8 deletions ui/src/routes/api/vehicle/+server.ts

This file was deleted.

0 comments on commit b208189

Please sign in to comment.