mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
commit
5d7f384166
24 changed files with 4631 additions and 701 deletions
|
@ -4,19 +4,13 @@ CREATE TABLE IF NOT EXISTS "adventures" (
|
|||
"userId" text,
|
||||
"name" text NOT NULL,
|
||||
"location" text,
|
||||
"activityTypes" json,
|
||||
"activityTypes" text[] DEFAULT ARRAY[]::text[],
|
||||
"description" text,
|
||||
"rating" integer,
|
||||
"link" text,
|
||||
"imageUrl" text,
|
||||
"date" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "featuredAdventures" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"location" text,
|
||||
CONSTRAINT "featuredAdventures_name_unique" UNIQUE("name")
|
||||
"date" text,
|
||||
"tripId" integer
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "session" (
|
||||
|
@ -38,8 +32,7 @@ CREATE TABLE IF NOT EXISTS "userPlannedTrips" (
|
|||
"adventureName" text NOT NULL,
|
||||
"description" text,
|
||||
"startDate" text,
|
||||
"endDate" text,
|
||||
"adventures" json
|
||||
"endDate" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
|
@ -82,6 +75,12 @@ EXCEPTION
|
|||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "adventures" ADD CONSTRAINT "adventures_tripId_userPlannedTrips_id_fk" FOREIGN KEY ("tripId") REFERENCES "userPlannedTrips"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
|
@ -1,8 +0,0 @@
|
|||
ALTER TABLE "adventures" ADD COLUMN "tripId" integer;--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "adventures" ADD CONSTRAINT "adventures_tripId_userPlannedTrips_id_fk" FOREIGN KEY ("tripId") REFERENCES "userPlannedTrips"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "userPlannedTrips" DROP COLUMN IF EXISTS "adventures";
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"id": "7cce94bb-5a17-42ff-850f-e0a41834b739",
|
||||
"id": "7d9fd5eb-2eed-4595-a3db-6f01cde31041",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
|
@ -40,9 +40,10 @@
|
|||
},
|
||||
"activityTypes": {
|
||||
"name": "activityTypes",
|
||||
"type": "json",
|
||||
"type": "text[]",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
"notNull": false,
|
||||
"default": "ARRAY[]::text[]"
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
|
@ -73,6 +74,12 @@
|
|||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"tripId": {
|
||||
"name": "tripId",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
|
@ -89,47 +96,24 @@
|
|||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"adventures_tripId_userPlannedTrips_id_fk": {
|
||||
"name": "adventures_tripId_userPlannedTrips_id_fk",
|
||||
"tableFrom": "adventures",
|
||||
"tableTo": "userPlannedTrips",
|
||||
"columnsFrom": [
|
||||
"tripId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"featuredAdventures": {
|
||||
"name": "featuredAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"location": {
|
||||
"name": "location",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"featuredAdventures_name_unique": {
|
||||
"name": "featuredAdventures_name_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"session": {
|
||||
"name": "session",
|
||||
"schema": "",
|
||||
|
@ -245,12 +229,6 @@
|
|||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"adventures": {
|
||||
"name": "adventures",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
|
|
|
@ -1,524 +0,0 @@
|
|||
{
|
||||
"id": "7b641b27-ea8e-4786-b130-0c827041d12c",
|
||||
"prevId": "7cce94bb-5a17-42ff-850f-e0a41834b739",
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"tables": {
|
||||
"adventures": {
|
||||
"name": "adventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"location": {
|
||||
"name": "location",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"activityTypes": {
|
||||
"name": "activityTypes",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"rating": {
|
||||
"name": "rating",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"link": {
|
||||
"name": "link",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"imageUrl": {
|
||||
"name": "imageUrl",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"date": {
|
||||
"name": "date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"tripId": {
|
||||
"name": "tripId",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"adventures_userId_user_id_fk": {
|
||||
"name": "adventures_userId_user_id_fk",
|
||||
"tableFrom": "adventures",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"userId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"adventures_tripId_userPlannedTrips_id_fk": {
|
||||
"name": "adventures_tripId_userPlannedTrips_id_fk",
|
||||
"tableFrom": "adventures",
|
||||
"tableTo": "userPlannedTrips",
|
||||
"columnsFrom": [
|
||||
"tripId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"featuredAdventures": {
|
||||
"name": "featuredAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"location": {
|
||||
"name": "location",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"featuredAdventures_name_unique": {
|
||||
"name": "featuredAdventures_name_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"session": {
|
||||
"name": "session",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"session_user_id_user_id_fk": {
|
||||
"name": "session_user_id_user_id_fk",
|
||||
"tableFrom": "session",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"sharedAdventures": {
|
||||
"name": "sharedAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"data": {
|
||||
"name": "data",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"date": {
|
||||
"name": "date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"userPlannedTrips": {
|
||||
"name": "userPlannedTrips",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"userId": {
|
||||
"name": "userId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"adventureName": {
|
||||
"name": "adventureName",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"startDate": {
|
||||
"name": "startDate",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"endDate": {
|
||||
"name": "endDate",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"userPlannedTrips_userId_user_id_fk": {
|
||||
"name": "userPlannedTrips_userId_user_id_fk",
|
||||
"tableFrom": "userPlannedTrips",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"userId"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"user": {
|
||||
"name": "user",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"first_name": {
|
||||
"name": "first_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"last_name": {
|
||||
"name": "last_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"icon": {
|
||||
"name": "icon",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"hashed_password": {
|
||||
"name": "hashed_password",
|
||||
"type": "varchar",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"signup_date": {
|
||||
"name": "signup_date",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"last_login": {
|
||||
"name": "last_login",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"userVisitedWorldTravel": {
|
||||
"name": "userVisitedWorldTravel",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"region_id": {
|
||||
"name": "region_id",
|
||||
"type": "varchar",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk": {
|
||||
"name": "userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "worldTravelCountries",
|
||||
"columnsFrom": [
|
||||
"country_code"
|
||||
],
|
||||
"columnsTo": [
|
||||
"country_code"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userVisitedWorldTravel_user_id_user_id_fk": {
|
||||
"name": "userVisitedWorldTravel_user_id_user_id_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk": {
|
||||
"name": "userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "worldTravelCountryRegions",
|
||||
"columnsFrom": [
|
||||
"region_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"worldTravelCountries": {
|
||||
"name": "worldTravelCountries",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"continent": {
|
||||
"name": "continent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"worldTravelCountries_country_code_unique": {
|
||||
"name": "worldTravelCountries_country_code_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"country_code"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"worldTravelCountryRegions": {
|
||||
"name": "worldTravelCountryRegions",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "varchar",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"info": {
|
||||
"name": "info",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk": {
|
||||
"name": "worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk",
|
||||
"tableFrom": "worldTravelCountryRegions",
|
||||
"tableTo": "worldTravelCountries",
|
||||
"columnsFrom": [
|
||||
"country_code"
|
||||
],
|
||||
"columnsTo": [
|
||||
"country_code"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
|
@ -5,15 +5,8 @@
|
|||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1715035790035,
|
||||
"tag": "0000_grey_iron_monger",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1715806684204,
|
||||
"tag": "0001_salty_ser_duncan",
|
||||
"when": 1717264326698,
|
||||
"tag": "0000_whole_blob",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
|
4149
pnpm-lock.yaml
generated
Normal file
4149
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
48
src/lib/components/AutoComplete.svelte
Normal file
48
src/lib/components/AutoComplete.svelte
Normal file
|
@ -0,0 +1,48 @@
|
|||
<script lang="ts">
|
||||
export let items: String[] = [];
|
||||
export let displayValue: String = "";
|
||||
export let selectedItem;
|
||||
|
||||
let newAdd: String[] = [];
|
||||
|
||||
$: inputVal = "";
|
||||
|
||||
function onItemClicked(item: String) {
|
||||
// items.push(item);
|
||||
console.log(newAdd);
|
||||
if (newAdd.includes(item)) {
|
||||
return;
|
||||
} else {
|
||||
newAdd.push(item);
|
||||
selectedItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
$: filteredItems = items.filter(function (item) {
|
||||
return item.toLowerCase().includes(inputVal.toLowerCase());
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="dropdown">
|
||||
<input
|
||||
class="input input-bordered"
|
||||
placeholder=""
|
||||
bind:value={displayValue}
|
||||
/>
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<ul
|
||||
tabindex="0"
|
||||
class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52 max-h-80 flex-nowrap overflow-auto"
|
||||
>
|
||||
{#each filteredItems as item}
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<li>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<a on:click|preventDefault={() => onItemClicked(item)}>{item}</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
|
@ -17,13 +17,35 @@
|
|||
const dispatch = createEventDispatcher();
|
||||
import { onMount } from "svelte";
|
||||
import { addActivityType, generateDescription, getImage } from "$lib";
|
||||
import AutoComplete from "./AutoComplete.svelte";
|
||||
let modal: HTMLDialogElement;
|
||||
|
||||
onMount(() => {
|
||||
let activityTypes: string[] = [];
|
||||
|
||||
$: selected = "";
|
||||
|
||||
// on selection add to activityTypes
|
||||
$: {
|
||||
if (selected) {
|
||||
newAdventure = addActivityType(selected, newAdventure);
|
||||
|
||||
if (activityInput.length === 0) {
|
||||
activityInput = selected;
|
||||
} else {
|
||||
activityInput = activityInput + ", " + selected;
|
||||
}
|
||||
selected = "";
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
||||
if (modal) {
|
||||
modal.showModal();
|
||||
}
|
||||
let activityFetch = await fetch("/api/activitytypes?type=" + type);
|
||||
let res = await activityFetch.json();
|
||||
activityTypes = res.types;
|
||||
});
|
||||
|
||||
function create() {
|
||||
|
@ -129,10 +151,17 @@
|
|||
<label for="date">Activity Types (Comma Seperated)</label>
|
||||
<input
|
||||
type="text"
|
||||
hidden
|
||||
id="activityTypes"
|
||||
bind:value={activityInput}
|
||||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
|
||||
<AutoComplete
|
||||
items={activityTypes}
|
||||
bind:selectedItem={selected}
|
||||
bind:displayValue={activityInput}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="rating">Rating</label>
|
||||
|
|
|
@ -5,18 +5,42 @@
|
|||
const dispatch = createEventDispatcher();
|
||||
import { onMount } from "svelte";
|
||||
import { addActivityType, generateDescription, getImage } from "$lib";
|
||||
import AutoComplete from "./AutoComplete.svelte";
|
||||
let modal: HTMLDialogElement;
|
||||
|
||||
console.log(adventureToEdit.id);
|
||||
|
||||
let originalName = adventureToEdit.name;
|
||||
|
||||
onMount(() => {
|
||||
let activityTypes: string[] = [];
|
||||
|
||||
$: selected = "";
|
||||
|
||||
// on selection add to activityTypes
|
||||
$: {
|
||||
if (selected) {
|
||||
adventureToEdit = addActivityType(selected, adventureToEdit);
|
||||
|
||||
if (activityInput.length === 0) {
|
||||
activityInput = selected;
|
||||
} else {
|
||||
activityInput = activityInput + ", " + selected;
|
||||
}
|
||||
selected = "";
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
modal = document.getElementById("my_modal_1") as HTMLDialogElement;
|
||||
if (modal) {
|
||||
modal.showModal();
|
||||
}
|
||||
activityInput = (adventureToEdit?.activityTypes || []).join(", ");
|
||||
let activityFetch = await fetch(
|
||||
"/api/activitytypes?type=" + adventureToEdit.type
|
||||
);
|
||||
let res = await activityFetch.json();
|
||||
activityTypes = res.types;
|
||||
});
|
||||
|
||||
function submit() {
|
||||
|
@ -113,13 +137,19 @@
|
|||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="date">Activity Types (Comma Seperated)</label>
|
||||
<input
|
||||
type="text"
|
||||
hidden
|
||||
id="activityTypes"
|
||||
bind:value={activityInput}
|
||||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
<label for="date">Activity Types (Comma Seperated)</label>
|
||||
<AutoComplete
|
||||
items={activityTypes}
|
||||
bind:selectedItem={selected}
|
||||
bind:displayValue={activityInput}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="rating">Rating</label>
|
||||
|
|
|
@ -1,53 +1,20 @@
|
|||
<script>
|
||||
import pinLogo from "$lib/assets/pinLogo.svg";
|
||||
import { appVersion } from "$lib/config";
|
||||
</script>
|
||||
|
||||
<footer
|
||||
class="footer items-center p-4 bg-neutral text-neutral-content fixed bottom-0 left-0 w-full"
|
||||
>
|
||||
<aside class="items-center grid-flow-col">
|
||||
<img src={pinLogo} class="inline-block -mt-1 mr-1" alt="Logo" />
|
||||
<p>Copyright © 2024 Sean Morley - All rights reserved</p>
|
||||
</aside>
|
||||
<nav class="grid-flow-col gap-4 md:place-self-center md:justify-self-end">
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<a
|
||||
><svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
class="fill-current"
|
||||
><path
|
||||
d="M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.609 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-3.179 0-5.515 2.966-4.797 6.045-4.091-.205-7.719-2.165-10.148-5.144-1.29 2.213-.669 5.108 1.523 6.574-.806-.026-1.566-.247-2.229-.616-.054 2.281 1.581 4.415 3.949 4.89-.693.188-1.452.232-2.224.084.626 1.956 2.444 3.379 4.6 3.419-2.07 1.623-4.678 2.348-7.29 2.04 2.179 1.397 4.768 2.212 7.548 2.212 9.142 0 14.307-7.721 13.995-14.646.962-.695 1.797-1.562 2.457-2.549z"
|
||||
></path></svg
|
||||
<footer class="footer footer-center p-4 bg-base-300 text-base-content mt-10">
|
||||
<aside>
|
||||
<p>
|
||||
Copyright © 2024 <a
|
||||
href="https://github.com/seanmorley15"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-primary-500 underline">Sean Morley</a
|
||||
>
|
||||
</a>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<a
|
||||
><svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
class="fill-current"
|
||||
><path
|
||||
d="M19.615 3.184c-3.604-.246-11.631-.245-15.23 0-3.897.266-4.356 2.62-4.385 8.816.029 6.185.484 8.549 4.385 8.816 3.6.245 11.626.246 15.23 0 3.897-.266 4.356-2.62 4.385-8.816-.029-6.185-.484-8.549-4.385-8.816zm-10.615 12.816v-8l8 3.993-8 4.007z"
|
||||
></path></svg
|
||||
></a
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<a
|
||||
><svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
class="fill-current"
|
||||
><path
|
||||
d="M9 8h-3v4h3v12h5v-12h3.642l.358-4h-4v-1.667c0-.955.192-1.333 1.115-1.333h2.885v-5h-3.808c-3.596 0-5.192 1.583-5.192 4.615v3.385z"
|
||||
></path></svg
|
||||
></a
|
||||
>
|
||||
</nav>
|
||||
- All right reserved | Thank you contributors!
|
||||
</p>
|
||||
<p class="py-1">
|
||||
AdventureLog {appVersion}
|
||||
</p>
|
||||
</aside>
|
||||
</footer>
|
||||
|
|
|
@ -1,30 +1,36 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from "$app/forms";
|
||||
import { goto } from "$app/navigation";
|
||||
import type { DatabaseUser } from "$lib/server/auth";
|
||||
export let user: any;
|
||||
import UserAvatar from "./UserAvatar.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import InfoModal from "./InfoModal.svelte";
|
||||
import infoIcon from "$lib/assets/info.svg";
|
||||
import type { SubmitFunction } from "@sveltejs/kit";
|
||||
async function goHome() {
|
||||
goto("/");
|
||||
}
|
||||
async function goToLog() {
|
||||
goto("/log");
|
||||
}
|
||||
async function goToFeatured() {
|
||||
goto("/featured");
|
||||
}
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let searchVal: string = "";
|
||||
|
||||
async function toToLogin() {
|
||||
goto("/login");
|
||||
}
|
||||
async function goToSignup() {
|
||||
goto("/signup");
|
||||
}
|
||||
async function goToWorldTravel() {
|
||||
goto("/worldtravel");
|
||||
|
||||
onMount(() => {
|
||||
if (window.location.pathname === "/search") {
|
||||
searchVal = new URLSearchParams(window.location.search).get("all") || "";
|
||||
}
|
||||
});
|
||||
|
||||
async function goToSearch() {
|
||||
let reload: boolean = false;
|
||||
if (window.location.pathname === "/search") {
|
||||
reload = true;
|
||||
}
|
||||
await goto("/search?all=" + searchVal);
|
||||
if (reload) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
const submitUpdateTheme: SubmitFunction = ({ action }) => {
|
||||
|
@ -86,6 +92,24 @@
|
|||
<li>
|
||||
<button on:click={() => goto("/featured")}>Featured</button>
|
||||
</li>
|
||||
{#if user}
|
||||
<li>
|
||||
<label class="input input-bordered flex items-center gap-2">
|
||||
<input type="text" class="grow" placeholder="Search" />
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="w-4 h-4 opacity-70"
|
||||
><path
|
||||
fill-rule="evenodd"
|
||||
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
|
||||
clip-rule="evenodd"
|
||||
/></svg
|
||||
>
|
||||
</label>
|
||||
</li>
|
||||
{/if}
|
||||
{#if !user}
|
||||
<li>
|
||||
<button class="btn btn-primary" on:click={toToLogin}>Login</button>
|
||||
|
@ -125,6 +149,38 @@
|
|||
>Featured</button
|
||||
>
|
||||
</li>
|
||||
{#if user}
|
||||
<li>
|
||||
<label class="input input-bordered flex items-center gap-2">
|
||||
<form on:submit={() => goto("/search?all=" + searchVal)}>
|
||||
<input
|
||||
type="text"
|
||||
class="grow"
|
||||
placeholder="Search"
|
||||
bind:value={searchVal}
|
||||
on:keydown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
|
||||
goToSearch();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</form>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="w-4 h-4 opacity-70"
|
||||
><path
|
||||
fill-rule="evenodd"
|
||||
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
|
||||
clip-rule="evenodd"
|
||||
/></svg
|
||||
>
|
||||
</label>
|
||||
</li>
|
||||
{/if}
|
||||
{#if !user}
|
||||
<li>
|
||||
<button class="btn btn-primary" on:click={toToLogin}>Login</button>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { desc } from "drizzle-orm";
|
||||
import { desc, sql } from "drizzle-orm";
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
|
@ -93,7 +93,9 @@ export const adventureTable = pgTable("adventures", {
|
|||
userId: text("userId").references(() => userTable.id),
|
||||
name: text("name").notNull(),
|
||||
location: text("location"),
|
||||
activityTypes: json("activityTypes"),
|
||||
activityTypes: text("activityTypes")
|
||||
.array()
|
||||
.default(sql`ARRAY[]::text[]`),
|
||||
description: text("description"),
|
||||
rating: integer("rating"),
|
||||
link: text("link"),
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<script lang="ts">
|
||||
export let data;
|
||||
import Footer from "$lib/components/Footer.svelte";
|
||||
// import Footer from "$lib/components/Footer.svelte";
|
||||
import Navbar from "$lib/components/Navbar.svelte";
|
||||
import type { SubmitFunction } from "@sveltejs/kit";
|
||||
import "../app.css";
|
||||
import { goto } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
|
@ -30,17 +29,11 @@
|
|||
});
|
||||
</script>
|
||||
|
||||
<!-- passes the user object to the navbar component -->
|
||||
<Navbar user={data.user} />
|
||||
<section>
|
||||
<slot />
|
||||
</section>
|
||||
<!-- <Footer /> -->
|
||||
|
||||
<!-- <style>
|
||||
section {
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 5rem;
|
||||
/* gives the footer space! */
|
||||
}
|
||||
</style> -->
|
||||
<div class="flex flex-col min-h-screen">
|
||||
<!-- passes the user object to the navbar component -->
|
||||
<Navbar user={data.user} />
|
||||
<main class="flex-grow">
|
||||
<slot />
|
||||
</main>
|
||||
<!-- <Footer /> -->
|
||||
</div>
|
||||
|
|
55
src/routes/api/activitytypes/+server.ts
Normal file
55
src/routes/api/activitytypes/+server.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { addActivityType } from "$lib";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
import { json, type RequestEvent, type RequestHandler } from "@sveltejs/kit";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
|
||||
/**
|
||||
* Handles the GET request for retrieving activity types based on the provided type parameter.
|
||||
* @param {Request} request - The request object containing the URL and locals.
|
||||
* @returns {Promise<Response>} - A promise that resolves to the JSON response containing the activity types.
|
||||
*/
|
||||
export const GET: RequestHandler = async ({ url, locals }) => {
|
||||
const type = url.searchParams.get("type");
|
||||
const user = locals.user;
|
||||
|
||||
if (!user) {
|
||||
return json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
return json({ error: "Missing adventure ID" }, { status: 400 });
|
||||
}
|
||||
|
||||
let types = await db
|
||||
.select({ activityTypes: adventureTable.activityTypes })
|
||||
.from(adventureTable)
|
||||
.where(
|
||||
and(eq(adventureTable.userId, user.id), eq(adventureTable.type, type))
|
||||
)
|
||||
.execute();
|
||||
|
||||
types.forEach((type) => {
|
||||
console.log(type.activityTypes);
|
||||
});
|
||||
// if (types.length === 0) {
|
||||
// return json({ error: "Types not found" }, { status: 404 });
|
||||
// }
|
||||
|
||||
// console.log(types);
|
||||
|
||||
let array: any[] = [];
|
||||
|
||||
types.forEach((type) => {
|
||||
const parsedActivityTypes = type.activityTypes;
|
||||
if (parsedActivityTypes && parsedActivityTypes.length > 0) {
|
||||
array.push(...parsedActivityTypes);
|
||||
}
|
||||
});
|
||||
|
||||
// remove duplicates
|
||||
array = [...new Set(array)];
|
||||
|
||||
return json({ types: array }, { status: 200 });
|
||||
};
|
|
@ -132,8 +132,6 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
|||
});
|
||||
}
|
||||
|
||||
console.log(activityTypes);
|
||||
|
||||
// insert the adventure to the user's visited list
|
||||
let res = await db
|
||||
.insert(adventureTable)
|
||||
|
@ -145,7 +143,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
|||
tripId: tripId || null,
|
||||
date: date || null,
|
||||
description: description || null,
|
||||
activityTypes: JSON.stringify(activityTypes) || null,
|
||||
activityTypes: activityTypes || null,
|
||||
rating: rating || null,
|
||||
imageUrl: imageUrl || null,
|
||||
})
|
||||
|
@ -153,7 +151,6 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
|||
.execute();
|
||||
|
||||
let insertedId = res[0].insertedId;
|
||||
console.log(insertedId);
|
||||
|
||||
body.detailAdventure.id = insertedId;
|
||||
|
||||
|
@ -217,7 +214,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
|||
date: date,
|
||||
description: description,
|
||||
rating: rating,
|
||||
activityTypes: JSON.stringify(activityTypes),
|
||||
activityTypes: activityTypes,
|
||||
imageUrl: imageUrl,
|
||||
})
|
||||
.where(
|
||||
|
|
|
@ -135,7 +135,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
|||
location: location || null,
|
||||
date: date || null,
|
||||
description: description || null,
|
||||
activityTypes: JSON.stringify(activityTypes) || null,
|
||||
activityTypes: activityTypes || null,
|
||||
rating: rating || null,
|
||||
imageUrl: imageUrl || null,
|
||||
})
|
||||
|
@ -215,7 +215,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
|||
date: date,
|
||||
description: description,
|
||||
rating: rating,
|
||||
activityTypes: JSON.stringify(activityTypes),
|
||||
activityTypes: activityTypes,
|
||||
imageUrl: imageUrl,
|
||||
})
|
||||
.where(
|
||||
|
|
|
@ -8,7 +8,10 @@ export const load: PageServerLoad = async (event) => {
|
|||
}
|
||||
const response = await event.fetch("/api/planner");
|
||||
const result = await response.json();
|
||||
const activityTypes = await event.fetch("/api/activitytypes?type=planner");
|
||||
const activityTypesResult = await activityTypes.json();
|
||||
return {
|
||||
result,
|
||||
activityTypesResult,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,15 +19,16 @@
|
|||
let adventuresPlans: Adventure[] = [];
|
||||
let tripPlans: Trip[] = [];
|
||||
|
||||
let activityTypes: String[] = [];
|
||||
|
||||
let isLoadingIdeas: boolean = true;
|
||||
let isLoadingTrips: boolean = true;
|
||||
|
||||
onMount(async () => {
|
||||
console.log(data);
|
||||
getAllTrips();
|
||||
console.log(tripPlans);
|
||||
adventuresPlans = data.result;
|
||||
isLoadingIdeas = false;
|
||||
activityTypes = data.activityTypesResult.types;
|
||||
});
|
||||
|
||||
let isShowingMoreFields: boolean = false;
|
||||
|
@ -38,8 +39,6 @@
|
|||
|
||||
let adventureToEdit: Adventure | undefined;
|
||||
|
||||
console.log(data);
|
||||
|
||||
function showToast(action: string) {
|
||||
toastAction = action;
|
||||
isShowingToast = true;
|
||||
|
@ -65,10 +64,16 @@
|
|||
}
|
||||
|
||||
async function savePlan(event: { detail: Adventure }) {
|
||||
let types: String[] = [];
|
||||
if (event.detail.activityTypes && event.detail.activityTypes.length > 0) {
|
||||
types = event.detail.activityTypes;
|
||||
}
|
||||
let newArray = await saveAdventure(event.detail, adventuresPlans);
|
||||
if (newArray.length > 0) {
|
||||
adventuresPlans = newArray;
|
||||
showToast("Adventure updated successfully!");
|
||||
activityTypes = activityTypes.concat(types);
|
||||
activityTypes = [...new Set(activityTypes)];
|
||||
} else {
|
||||
showToast("Failed to update adventure");
|
||||
}
|
||||
|
@ -93,10 +98,16 @@
|
|||
|
||||
const createNewAdventure = async (event: { detail: Adventure }) => {
|
||||
isShowingMoreFields = false;
|
||||
let types: String[] = [];
|
||||
if (event.detail.activityTypes && event.detail.activityTypes.length > 0) {
|
||||
types = event.detail.activityTypes;
|
||||
}
|
||||
let newArray = await addAdventure(event.detail, adventuresPlans);
|
||||
if (newArray.length > 0) {
|
||||
adventuresPlans = newArray;
|
||||
showToast("Adventure added successfully!");
|
||||
activityTypes = activityTypes.concat(types);
|
||||
activityTypes = [...new Set(activityTypes)];
|
||||
} else {
|
||||
showToast("Failed to add adventure");
|
||||
}
|
||||
|
@ -220,6 +231,15 @@
|
|||
<h1 class="text-center">My Adventure Ideas</h1>
|
||||
</article>
|
||||
</div>
|
||||
<div class="flex justify-center items-center w-full mt-4 mb-4">
|
||||
Activity Type
|
||||
<select class="select select-bordered w-full max-w-xs">
|
||||
<option value="">All</option>
|
||||
{#each activityTypes as type}
|
||||
<option value={type}>{type}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if isLoadingIdeas && isLoadingTrips}
|
||||
|
|
114
src/routes/search/+page.server.ts
Normal file
114
src/routes/search/+page.server.ts
Normal file
|
@ -0,0 +1,114 @@
|
|||
// +page.server.js
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import { db } from "$lib/db/db.server";
|
||||
import { adventureTable } from "$lib/db/schema";
|
||||
import { and, eq, arrayContains, ilike } from "drizzle-orm";
|
||||
|
||||
/**
|
||||
* Loads the page data based on the provided URL and locals.
|
||||
*
|
||||
* @param {PageServerLoadParams} params - The parameters for loading the page.
|
||||
* @returns {Promise<PageServerLoadResult>} The result of loading the page.
|
||||
*/
|
||||
export const load: PageServerLoad = async ({ url, locals }) => {
|
||||
if (!locals.user) {
|
||||
return redirect(301, "/login");
|
||||
}
|
||||
let param: string = "";
|
||||
let value: string = "";
|
||||
if (Array.from(url.searchParams.entries()).length > 0) {
|
||||
const params = Array.from(url.searchParams.entries());
|
||||
param = params[0][0];
|
||||
value = params[0][1];
|
||||
} else {
|
||||
param = "all";
|
||||
value = "";
|
||||
}
|
||||
// Activity type search
|
||||
if (param === "activity") {
|
||||
return {
|
||||
props: await activitySearch(value, locals),
|
||||
};
|
||||
}
|
||||
|
||||
if (param === "location") {
|
||||
return {
|
||||
props: await locationSearch(value, locals),
|
||||
};
|
||||
}
|
||||
if (param === "name") {
|
||||
return {
|
||||
props: await nameSearch(value, locals),
|
||||
};
|
||||
}
|
||||
if (param == "all" || param == "") {
|
||||
console.log("all");
|
||||
const activityResults = await activitySearch(value, locals);
|
||||
const locationResults = await locationSearch(value, locals);
|
||||
const namesResults = await nameSearch(value, locals);
|
||||
|
||||
return {
|
||||
props: {
|
||||
adventures: [
|
||||
...activityResults.adventures,
|
||||
...locationResults.adventures,
|
||||
...namesResults.adventures,
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function activitySearch(value: string, locals: any) {
|
||||
let arr: string[] = [];
|
||||
arr.push(value.toLowerCase());
|
||||
let res = await db
|
||||
.select()
|
||||
.from(adventureTable)
|
||||
.where(
|
||||
and(
|
||||
arrayContains(adventureTable.activityTypes, arr),
|
||||
eq(adventureTable.userId, locals.user.id)
|
||||
)
|
||||
)
|
||||
.execute();
|
||||
|
||||
return {
|
||||
adventures: res,
|
||||
};
|
||||
}
|
||||
|
||||
async function locationSearch(value: string, locals: any) {
|
||||
let res = await db
|
||||
.select()
|
||||
.from(adventureTable)
|
||||
.where(
|
||||
and(
|
||||
ilike(adventureTable.location, `%${value}%`),
|
||||
eq(adventureTable.userId, locals.user.id)
|
||||
)
|
||||
)
|
||||
.execute();
|
||||
|
||||
return {
|
||||
adventures: res,
|
||||
};
|
||||
}
|
||||
|
||||
async function nameSearch(value: string, locals: any) {
|
||||
let res = await db
|
||||
.select()
|
||||
.from(adventureTable)
|
||||
.where(
|
||||
and(
|
||||
ilike(adventureTable.name, `%${value}%`),
|
||||
eq(adventureTable.userId, locals.user.id)
|
||||
)
|
||||
)
|
||||
.execute();
|
||||
|
||||
return {
|
||||
adventures: res,
|
||||
};
|
||||
}
|
||||
};
|
24
src/routes/search/+page.svelte
Normal file
24
src/routes/search/+page.svelte
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script lang="ts">
|
||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
import type { PageData } from "./$types";
|
||||
|
||||
export let data: PageData;
|
||||
let adventureArray: Adventure[] = data.props?.adventures as Adventure[];
|
||||
console.log(adventureArray);
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<h1 class="text-center font-bold text-4xl">Search Results</h1>
|
||||
{#if adventureArray.length > 0}
|
||||
<div
|
||||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
{#each adventureArray as adventure}
|
||||
<AdventureCard {adventure} type="mylog" />
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<h1 class="text-center text-4xl font-bold mt-16">No Results Found</h1>
|
||||
{/if}
|
||||
</main>
|
|
@ -1,6 +1,5 @@
|
|||
<script>
|
||||
import { enhance } from "$app/forms";
|
||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||
|
||||
export let data;
|
||||
let username = data.user?.username;
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
import { page } from "$app/stores";
|
||||
|
||||
import { enhance } from "$app/forms";
|
||||
import { goto } from "$app/navigation";
|
||||
import { type SubmitFunction } from "@sveltejs/kit";
|
||||
import type { DatabaseUser } from "lucia";
|
||||
import UserCard from "$lib/components/UserCard.svelte";
|
||||
|
||||
let username: string = "";
|
||||
|
@ -13,8 +10,6 @@
|
|||
let password: string = "";
|
||||
import ConfirmModal from "$lib/components/ConfirmModal.svelte";
|
||||
|
||||
let errors: { addUser?: string } = {};
|
||||
let sucess: { addUser?: string } = {};
|
||||
let isModalOpen = false;
|
||||
|
||||
async function clearAllSessions() {
|
||||
|
@ -35,8 +30,6 @@
|
|||
isModalOpen = false;
|
||||
}
|
||||
|
||||
let form = $page.form;
|
||||
|
||||
let visitCount = $page.data.visitCount[0].count;
|
||||
let userCount = $page.data.userCount[0].count;
|
||||
let regionCount = $page.data.regionCount[0].count;
|
||||
|
|
|
@ -31,6 +31,7 @@ export const actions: Actions = {
|
|||
const password = formData.get("password");
|
||||
const firstName = formData.get("first_name");
|
||||
const lastName = formData.get("last_name");
|
||||
const confirmPassword = formData.get("passwordConfirm");
|
||||
// username must be between 4 ~ 31 characters, and only consists of lowercase letters, 0-9, -, and _
|
||||
// keep in mind some database (e.g. mysql) are case insensitive
|
||||
|
||||
|
@ -38,7 +39,7 @@ export const actions: Actions = {
|
|||
return redirect(302, "/");
|
||||
}
|
||||
// check all to make sure all fields are provided
|
||||
if (!username || !password || !firstName || !lastName) {
|
||||
if (!username || !password || !firstName || !lastName || !confirmPassword) {
|
||||
return error(400, {
|
||||
message: "All fields are required",
|
||||
});
|
||||
|
@ -84,6 +85,12 @@ export const actions: Actions = {
|
|||
});
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
return error(400, {
|
||||
message: "Passwords do not match",
|
||||
});
|
||||
}
|
||||
|
||||
const usernameTaken = await db
|
||||
.select()
|
||||
.from(userTable)
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
class="min-h-screen bg-no-repeat bg-cover flex items-center justify-center"
|
||||
style="background-image: url('{backgroundImageUrl}')"
|
||||
>
|
||||
<div class="card card-compact w-96 bg-base-100 shadow-xl p-6">
|
||||
<div class="card card-compact w-96 bg-base-100 shadow-xl p-6 mt-4 mb-4">
|
||||
<article class="text-center text-4xl font-extrabold">
|
||||
<h1>Signup</h1>
|
||||
</article>
|
||||
|
@ -70,6 +70,12 @@
|
|||
name="password"
|
||||
id="password"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br /><label for="password">Confirm Password</label>
|
||||
<input
|
||||
type="password"
|
||||
name="passwordConfirm"
|
||||
id="passwordConfirm"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<button class="py-2 px-4 btn btn-primary">Signup</button>
|
||||
</form>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue