Skip to content

Commit

Permalink
multiple bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Beutel committed Mar 17, 2024
1 parent eae4551 commit abecaa4
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search/data.ms
search/dumps

run.sh
build.sh
build*.sh
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# v0.1.1
## Bug fixes

- fixed a bug that would prevent trails longer than 20km from being displayed
- added BODY_SIZE_LIMIT env variable to docker compose to allow for bigger file uploads
- fixed a bug that caused only 5 trails to be shown at a time
- fixed a bug that would cause waypoints not to be deleted from the backend
- updated the default docker-compose.yml to include a secure MEILI_MASTER_KEY
- the default location field now sets the value correctly after clicking on a search result

## Docs

- updated the docs to include BODY_SIZE_LIMIT

# v0.1.0
- Initial release
4 changes: 3 additions & 1 deletion db/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ WORKDIR /

COPY migrations ./migrations

COPY ./pocketbase_arm64 /pocketbase
ARG TARGETARCH
RUN echo ${TARGETARCH}
COPY ./pocketbase_${TARGETARCH} /pocketbase
RUN chmod +x /pocketbase

ENV MEILI_URL=http://localhost:7700
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

x-common-env: &cenv
MEILI_URL: http://search:7700
MEILI_MASTER_KEY: CHANGE_ME!
MEILI_MASTER_KEY: vODkljPcfFANYNepCHyDyGjzAMPcdHnrb6X5KyXQPWo

services:
search:
Expand Down Expand Up @@ -50,6 +50,7 @@ services:
environment:
<<: *cenv
ORIGIN: http://localhost:3000
BODY_SIZE_LIMIT: Infinity
PUBLIC_POCKETBASE_URL: http://db:8090
ports:
- "3000:3000"
Expand Down
14 changes: 3 additions & 11 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
RUN npm run build
RUN npm prune --production

FROM node:18-alpine
WORKDIR /app
COPY --from=build /app/build build/
COPY --from=build /app/node_modules node_modules/
COPY package.json .
COPY ./build build/
COPY package*.json .
RUN npm ci --omit=dev
EXPOSE 3000
ENV NODE_ENV=production

Expand Down
8 changes: 4 additions & 4 deletions web/src/lib/components/trail/trail_filter_panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,27 @@
<p class="text-sm font-medium pb-4">{$_("distance")}</p>
<DoubleSlider
minValue={filter.distanceMin}
maxValue={filter.distanceMax}
maxValue={filter.distanceLimit}
bind:currentMin={filter.distanceMin}
bind:currentMax={filter.distanceMax}
on:set={() => update()}
></DoubleSlider>
<div class="flex justify-between">
<span>{formatDistance(filter.distanceMin)}</span>
<span>{formatDistance(filter.distanceMax)}</span>
<span>{formatDistance(filter.distanceMax)}{filter.distanceMax == filter.distanceLimit ? '+' : ''}</span>
</div>
<hr class="my-4 border-separator" />
<p class="text-sm font-medium pb-4">{$_("elevation-gain")}</p>
<DoubleSlider
minValue={filter.elevationGainMin}
maxValue={filter.elevationGainMax}
maxValue={filter.elevationGainLimit}
bind:currentMin={filter.elevationGainMin}
bind:currentMax={filter.elevationGainMax}
on:set={() => update()}
></DoubleSlider>
<div class="flex justify-between">
<span>{formatElevation(filter.elevationGainMin)}</span>
<span>{formatElevation(filter.elevationGainMax)}</span>
<span>{formatElevation(filter.elevationGainMax)}{filter.elevationGainMax == filter.elevationGainLimit ? '+' : ''}</span>
</div>
<hr class="my-4 border-separator" />
<p class="text-sm font-medium pb-4">{$_("completed")}</p>
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/models/trail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ interface TrailFilter {
}
distanceMin: number,
distanceMax: number,
distanceLimit: number,
elevationGainMin: number;
elevationGainMax: number;
elevationGainLimit: number;
completed?: boolean;
sort: "name" | "distance" | "elevation_gain" | "created";
sortOrder: "+" | "-"
Expand Down
28 changes: 22 additions & 6 deletions web/src/lib/stores/trail_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ export async function trails_index(data: { perPage: number, random?: boolean, f:
}

export async function trails_search_filter(filter: TrailFilter, page: number = 1, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
let filterText: string = `distance >= ${filter.distanceMin} AND distance <= ${filter.distanceMax} AND elevation_gain >= ${filter.elevationGainMin} AND elevation_gain <= ${filter.elevationGainMax}`;
let filterText: string = `distance >= ${filter.distanceMin} AND elevation_gain >= ${filter.elevationGainMin}`

if (filter.distanceMax < filter.distanceLimit) {
filterText += ` AND distance <= ${filter.distanceMax}`
}

if (filter.elevationGainMax < filter.elevationGainLimit) {
filterText += ` AND elevation_gain <= ${filter.elevationGainMax}`
}

filterText += ` AND difficulty IN [${filter.difficulty.join(",")}]`

Expand All @@ -52,7 +60,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
}
let r = await f("/api/v1/search/trails", {
method: "POST",
body: JSON.stringify({ q: filter.q, options: { filter: filterText, hitsPerPage: 20, page: page } }),
body: JSON.stringify({ q: filter.q, options: { filter: filterText, hitsPerPage: 21, page: page } }),
});

const result = await r.json();
Expand Down Expand Up @@ -90,7 +98,15 @@ export async function trails_search_bounding_box(northEast: LatLng, southWest: L
let filterText: string = "";

if (filter) {
filterText += `distance >= ${filter.distanceMin} AND distance <= ${filter.distanceMax} AND elevation_gain >= ${filter.elevationGainMin} AND elevation_gain <= ${filter.elevationGainMax}`;
filterText += `distance >= ${filter.distanceMin} AND elevation_gain >= ${filter.elevationGainMin}`;

if (filter.distanceMax < filter.distanceLimit) {
filterText += ` AND distance <= ${filter.distanceMax}`
}

if (filter.elevationGainMax < filter.elevationGainLimit) {
filterText += ` AND elevation_gain <= ${filter.elevationGainMax}`
}

filterText += ` AND difficulty IN [${filter.difficulty.join(",")}]`

Expand Down Expand Up @@ -162,7 +178,7 @@ export async function trails_show(id: string, loadGPX?: boolean, f: (url: Reques
}

if (loadGPX) {
if(!response.expand) {
if (!response.expand) {
response.expand = {}
}
const gpxData: string = await fetchGPX(response, f);
Expand Down Expand Up @@ -312,12 +328,12 @@ export async function trails_update(oldTrail: Trail, newTrail: Trail, photos: Fi
export async function trails_delete(trail: Trail) {
if (trail.expand.waypoints) {
for (const waypoint of trail.expand.waypoints) {
waypoints_delete(waypoint);
await waypoints_delete(waypoint);
}
}
if (trail.expand.summit_logs) {
for (const summit_log of trail.expand.summit_logs) {
summit_logs_delete(summit_log);
await summit_logs_delete(summit_log);
}
}

Expand Down
1 change: 1 addition & 0 deletions web/src/lib/stores/user_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type User = {
export const currentUser: Writable<User | null> = writable<User | null>()

export async function users_create(user: User) {
user.unit = "metric";
const r = await fetch('/api/v1/user', {
method: 'PUT',
body: JSON.stringify({ ...user, passwordConfirm: user.password })
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/api/v1/search/[index]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function POST(event: RequestEvent) {
const data = await event.request.json()

try {
const r = await event.locals.ms.index(event.params.index as string).search(data.q, data.options);
const r = await event.locals.ms.index(event.params.index as string).search(data.q, data.options);
return json(r);
} catch (e: any) {
console.log(e);
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/api/v1/trail/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { error, json, type RequestEvent } from '@sveltejs/kit';

export async function GET(event: RequestEvent) {
const page = event.url.searchParams.get("page") ?? "0";
const perPage = event.url.searchParams.get("per-page") ?? "5";
const perPage = event.url.searchParams.get("per-page") ?? "21";
const expand = event.url.searchParams.get("expand") ?? ""
const sort = event.url.searchParams.get("sort") ?? ""
const filter = event.url.searchParams.get("filter") ?? "";
Expand Down
2 changes: 2 additions & 0 deletions web/src/routes/lists/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const load: Load = async ({ params, fetch }) => {
},
distanceMin: 0,
distanceMax: 20000,
distanceLimit: 20000,
elevationGainMin: 0,
elevationGainMax: 4000,
elevationGainLimit: 4000,
sort: "created",
sortOrder: "+",
};
Expand Down
2 changes: 2 additions & 0 deletions web/src/routes/map/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
},
distanceMin: 0,
distanceMax: 20000,
distanceLimit: 20000,
elevationGainMin: 0,
elevationGainMax: 4000,
elevationGainLimit: 4000,
sort: "created",
sortOrder: "+",
};
Expand Down
1 change: 1 addition & 0 deletions web/src/routes/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
}
async function handleSearchClick(item: SearchItem) {
citySearchQuery = item.text;
await users_update($currentUser!.id, {
location: {
name: item.value.name,
Expand Down
14 changes: 6 additions & 8 deletions web/src/routes/trails/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
import TrailList from "$lib/components/trail/trail_list.svelte";
import type { TrailFilter } from "$lib/models/trail";
import { categories } from "$lib/stores/category_store";
import {
trails,
trails_search_filter,
} from "$lib/stores/trail_store";
import { trails, trails_search_filter } from "$lib/stores/trail_store";
import { onMount } from "svelte";
import { _ } from "svelte-i18n";
let filterExpanded: boolean = true;
const filter: TrailFilter = $page.data.filter;
const pagination: {page: number, totalPages: number} = $page.data.pagination
const pagination: { page: number; totalPages: number } =
$page.data.pagination;
onMount(() => {
if (window.innerWidth < 768) {
Expand All @@ -23,8 +21,8 @@
});
async function handleFilterUpdate() {
const response= await trails_search_filter(filter, 1);
pagination.page = response.page
const response = await trails_search_filter(filter, 1);
pagination.page = response.page;
pagination.totalPages = response.totalPages;
}
Expand All @@ -50,7 +48,7 @@
<TrailList
{filter}
trails={$trails}
pagination={pagination}
{pagination}
on:update={() => handleFilterUpdate()}
on:pagination={(e) => paginate(e.detail)}
></TrailList>
Expand Down
2 changes: 2 additions & 0 deletions web/src/routes/trails/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
},
distanceMin: 0,
distanceMax: 20000,
distanceLimit: 20000,
elevationGainMin: 0,
elevationGainMax: 4000,
elevationGainLimit: 4000,
sort: "created",
sortOrder: "+",
};
Expand Down

0 comments on commit abecaa4

Please sign in to comment.