Skip to content

Commit

Permalink
Merge branch 'andrew_testing' into fix/google-env-and-backend-build
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-bierman authored May 8, 2024
2 parents 2417444 + aa9e7ae commit 8306bfb
Show file tree
Hide file tree
Showing 42 changed files with 620 additions and 179 deletions.
3 changes: 2 additions & 1 deletion apps/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build:tsc": "tsc || exit 0",
"build:vite": "vite build --debug",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"clean": "rm -rf dist node_modules .tamagui"
},
"dependencies": {
"@originjs/vite-plugin-commonjs": "^1.0.3",
Expand Down
9 changes: 6 additions & 3 deletions packages/app/components/pack/AddPack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const AddPack = ({ isCreatingTrip = false, onSuccess }) => {

const {
addNewPackAsync,
response,
isError,
isLoading,
setIsPublic,
Expand All @@ -40,17 +39,21 @@ export const AddPack = ({ isCreatingTrip = false, onSuccess }) => {
*/
const handleAddPack = async (data) => {
try {
await addNewPackAsync(data);

const response = await addNewPackAsync(data);

onSuccess?.();

if (!response?.id) {
return;
}
if (!isCreatingTrip) {
router.push(`/pack/${response.id}`);
return;
}

setPackIdParam(response.id);

} catch {}
};

Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/ZDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as DropdownMenu from 'zeego/dropdown-menu';
import { styled } from 'tamagui';
import { MaterialIcons } from '@expo/vector-icons';

import { RIconButton } from '@packrat/ui';
import RIconButton from '../RIconButton';

const CustomContent = styled(DropdownMenu.Content, {
backgroundColor: 'white',
Expand Down Expand Up @@ -45,7 +45,7 @@ export const ZDropdownWeb = ({ dropdownItems = [] }) => {
</DropdownMenu.Trigger>
<CustomContent>
{dropdownItems.map(({ label, onSelect = () => {} }) => (
<CustomItem key={label} onSelect={onSelect()}>
<CustomItem key={label} onSelect={onSelect}>
<DropdownMenu.ItemTitle>{label}</DropdownMenu.ItemTitle>
</CustomItem>
))}
Expand All @@ -64,13 +64,13 @@ export const ZDropdownNative = ({ dropdownItems = [] }) => {
style={{ padding: 0 }}
/>
</DropdownMenu.Trigger>
<CustomContent>
<DropdownMenu.Content>
{dropdownItems.map(({ label, onSelect = () => {} }) => (
<DropdownMenu.Item key={label} onSelect={onSelect()}>
<DropdownMenu.Item key={label} onSelect={onSelect}>
<DropdownMenu.ItemTitle>{label}</DropdownMenu.ItemTitle>
</DropdownMenu.Item>
))}
</CustomContent>
</DropdownMenu.Content>
</DropdownMenu.Root>
);
};
Expand Down
4 changes: 4 additions & 0 deletions patches/osm-polygon-features+0.9.2+001+rename.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
diff --git a/node_modules/osm-polygon-features/polygon-features.json b/node_modules/osm-polygon-features/polygon-features.js
similarity index 100%
rename from node_modules/osm-polygon-features/polygon-features.json
rename to node_modules/osm-polygon-features/polygon-features.js
10 changes: 10 additions & 0 deletions patches/osm-polygon-features+0.9.2+002+repair.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/node_modules/osm-polygon-features/polygon-features.js b/node_modules/osm-polygon-features/polygon-features.js
index 8a86d16..09e9df0 100644
--- a/node_modules/osm-polygon-features/polygon-features.js
+++ b/node_modules/osm-polygon-features/polygon-features.js
@@ -1,4 +1,4 @@
-[
+module.exports = [
{
"key": "building",
"polygon": "all"
7 changes: 7 additions & 0 deletions patches/osm-polygon-features+0.9.2+003+update-import.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff --git a/node_modules/osm-polygon-features/index.js b/node_modules/osm-polygon-features/index.js
index 4fcec74..4ebcc9c 100644
--- a/node_modules/osm-polygon-features/index.js
+++ b/node_modules/osm-polygon-features/index.js
@@ -1 +1 @@
-module.exports = require('./polygon-features.json')
+module.exports = require('./polygon-features.js')
15 changes: 15 additions & 0 deletions patches/osmtogeojson+3.0.0-beta.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/node_modules/osmtogeojson/index.js b/node_modules/osmtogeojson/index.js
index 0164459..4d2f9f6 100644
--- a/node_modules/osmtogeojson/index.js
+++ b/node_modules/osmtogeojson/index.js
@@ -3,7 +3,9 @@ var rewind = require("@mapbox/geojson-rewind");

// see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
var polygonFeatures = {};
-require("osm-polygon-features").forEach(function(tags) {
+var osmPolygonFeatures = require("osm-polygon-features");
+
+osmPolygonFeatures.forEach(function(tags) {
if (tags.polygon === "all")
polygonFeatures[tags.key] = true;
else {
1 change: 1 addition & 0 deletions server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ module.exports = {
'no-unmodified-loop-condition': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-extraneous-class': 'off'
},
extends: [
'plugin:@typescript-eslint/recommended',
Expand Down
9 changes: 1 addition & 8 deletions server/migrations/0001_same_iron_patriot.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
-- This is a dummy migration
-- It does nothing
SELECT 1;--> statement-breakpoint
/*
SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html
Due to that we don't generate migration automatically and it has to be done manually
*/
SELECT 1;
9 changes: 1 addition & 8 deletions server/migrations/0002_numerous_tyger_tiger.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
ALTER TABLE item ADD `owner_id` text REFERENCES user(id);--> statement-breakpoint
/*
SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
https://www.sqlite.org/lang_altertable.html
Due to that we don't generate migration automatically and it has to be done manually
*/
ALTER TABLE item ADD `owner_id` text REFERENCES user(id);
2 changes: 1 addition & 1 deletion server/src/controllers/template/addTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function addTemplateRoute() {
.mutation(async (opts) => {
const { type, templateId, isGlobalTemplate, createdBy } = opts.input;
const userClass = new User();
const user = await userClass.findById(createdBy);
const user = await userClass.findUser({ userId: createdBy });
if (!user) {
throw new Error(UserNotFoundError.message);
}
Expand Down
20 changes: 12 additions & 8 deletions server/src/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ export const createDb = async (d1: D1Database) => {

export type DrizzleClient = Awaited<ReturnType<typeof createDb>>;

const DbClient = {
_instance: null as DrizzleClient | null,
get instance(): DrizzleClient {
if (!this._instance) {
class DbClient {
private static _instance: DrizzleClient | null = null;

private constructor() {}

public static get instance(): DrizzleClient {
if (!DbClient._instance) {
throw new Error('Database client instance not initialized.');
}
return this._instance;
},
async init(d1Db: D1Database): Promise<void> {
return DbClient._instance;
}

public static async init(d1Db: D1Database): Promise<void> {
if (d1Db) {
this._instance = await createDb(d1Db);
}
},
}
};

export { DbClient };
Expand Down
10 changes: 2 additions & 8 deletions server/src/drizzle/methods/Geojson.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { createDb } from '../../db/client';
import { DbClient } from '../../db/client';
import { type InsertGeoJson, geojson } from '../../db/schema';
import { getDB } from '../../trpc/context';

export class GeoJson {
async createInstance() {
const dbInstance = await createDb(getDB());
return dbInstance;
}

async create(geoJSONData: InsertGeoJson) {
try {
const db = await this.createInstance();
const db = DbClient.instance;
const record = await db
.insert(geojson)
.values(geoJSONData)
Expand Down
32 changes: 11 additions & 21 deletions server/src/drizzle/methods/Item.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { and, count, eq, sql, ilike, like } from 'drizzle-orm';
import { createDb } from '../../db/client';
import { DbClient } from '../../db/client';
import { and, count, eq, sql } from 'drizzle-orm';
import { type InsertItem, item as ItemTable } from '../../db/schema';
import { getDB } from '../../trpc/context';

export class Item {
async createInstance() {
const dbInstance = await createDb(getDB());
return dbInstance;
}

async create(data: InsertItem) {
try {
const item = (await this.createInstance())
const item = await DbClient.instance
.insert(ItemTable)
.values(data)
.returning()
Expand All @@ -28,7 +22,7 @@ export class Item {
filter = eq(ItemTable.id, id),
) {
try {
const item = (await this.createInstance())
const item = await DbClient.instance
.update(ItemTable)
.set(data)
.where(filter)
Expand All @@ -42,7 +36,7 @@ export class Item {

async delete(id: string, filter = eq(ItemTable.id, id)) {
try {
const deletedItem = (await this.createInstance())
const deletedItem = await DbClient.instance
.delete(ItemTable)
.where(filter)
.returning()
Expand All @@ -58,7 +52,7 @@ export class Item {
const filter = isGlobal
? and(eq(ItemTable.id, id), eq(ItemTable.global, true))
: eq(ItemTable.id, id);
const item = (await this.createInstance()).query.item.findFirst({
const item = await DbClient.instance.query.item.findFirst({
where: filter,
with: {
category: {
Expand Down Expand Up @@ -91,7 +85,7 @@ export class Item {

async findMany() {
try {
const items = (await this.createInstance()).query.item.findMany({
const items = await DbClient.instance.query.item.findMany({
with: {
itemPacks: {
columns: {
Expand All @@ -108,12 +102,8 @@ export class Item {

async findGlobal(limit: number, offset: number, searchString: string) {
try {
console.log(searchString);
const items = (await this.createInstance()).query.item.findMany({
where: and(
eq(ItemTable.global, true),
searchString ? like(ItemTable.name, `${searchString}%`) : undefined,
),
const items = await DbClient.instance.query.item.findMany({
where: eq(ItemTable.global, true),
with: {
category: {
columns: { id: true, name: true },
Expand All @@ -132,7 +122,7 @@ export class Item {
async findItemsByName(name: string) {
try {
const searchName = `%${name}%`;
const query = (await this.createInstance())
const query = await DbClient.instance
.select()
.from(ItemTable)
.where(sql`lower(${ItemTable.name}) LIKE ${sql.placeholder('name')}`)
Expand All @@ -146,7 +136,7 @@ export class Item {

async count() {
try {
const totalCount = await (await this.createInstance())
const totalCount = await DbClient.instance
.select({ value: count() })
.from(ItemTable)
.where(eq(ItemTable.global, true))
Expand Down
10 changes: 2 additions & 8 deletions server/src/drizzle/methods/ItemOwners.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { createDb } from '../../db/client';
import { DbClient } from '../../db/client';
import {
type InsertItemOwner,
itemOwners as ItemOwnersTable,
} from '../../db/schema';
import { getDB } from '../../trpc/context';

export class ItemOwners {
async createInstance() {
const dbInstance = await createDb(getDB());
return dbInstance;
}

async create(itemOwner: InsertItemOwner) {
try {
const record = (await this.createInstance())
const record = await DbClient.instance
.insert(ItemOwnersTable)
.values(itemOwner)
.returning()
Expand Down
18 changes: 5 additions & 13 deletions server/src/drizzle/methods/ItemPacks.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { eq, and } from 'drizzle-orm';
import { createDb } from '../../db/client';
import { DbClient } from '../../db/client';
import {
itemPacks as ItemPacksTable,
type InsertItemPack,
} from '../../db/schema';
import { getDB } from '../../trpc/context';

export class ItemPacks {
async createInstance() {
const dbInstance = await createDb(getDB());
return dbInstance;
}

async create(itemPack: InsertItemPack) {
try {
const record = (await this.createInstance())
const record = await DbClient.instance
.insert(ItemPacksTable)
.values(itemPack)
.returning()
Expand All @@ -27,7 +21,7 @@ export class ItemPacks {

async delete(itemId: string, packId: string) {
try {
const deletedRecord = (await this.createInstance())
const deletedRecord = await DbClient.instance
.delete(ItemPacksTable)
.where(
and(
Expand All @@ -44,9 +38,7 @@ export class ItemPacks {
}

async updateRelation({ oldItemId, newItemId, packId }) {
await (
await this.createInstance()
)
await DbClient.instance
.delete(ItemPacksTable)
.where(
and(
Expand All @@ -56,7 +48,7 @@ export class ItemPacks {
)
.execute();
const newRelation = { itemId: newItemId, packId };
await (await this.createInstance())
await await DbClient.instance
.insert(ItemPacksTable)
.values(newRelation)
.returning()
Expand Down
10 changes: 2 additions & 8 deletions server/src/drizzle/methods/TripGeoJson.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { createDb } from '../../db/client';
import { DbClient } from '../../db/client';
import { type InsertTripGeoJson, tripGeojsons } from '../../db/schema';
import { getDB } from '../../trpc/context';

export class TripGeoJson {
async createInstance() {
const dbInstance = await createDb(getDB());
return dbInstance;
}

async create(tripGeoJson: InsertTripGeoJson) {
try {
const record = (await this.createInstance())
const record = await DbClient.instance
.insert(tripGeojsons)
.values(tripGeoJson)
.returning()
Expand Down
Loading

0 comments on commit 8306bfb

Please sign in to comment.