Implement pasting into wormholes by maintaining a legit system along with a wormhole system
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { System } from '@/lib/types';
|
||||
import pb from '@/lib/pocketbase';
|
||||
import { SystemRecord } from '@/lib/pbtypes';
|
||||
|
||||
const wormholeCollection = pb.collection('wormholeSystems');
|
||||
const systemsCollection = pb.collection('system');
|
||||
|
||||
// Load all wormhole systems
|
||||
export const loadWormholeSystems = async (): Promise<Map<string, System>> => {
|
||||
@@ -19,9 +21,24 @@ export const saveWormholeSystem = async (system: System): Promise<System> => {
|
||||
try {
|
||||
console.log('Saving wormhole system:', system);
|
||||
if (system.id) {
|
||||
return await wormholeCollection.update(system.id, system);
|
||||
await wormholeCollection.update(system.id, system);
|
||||
const legitSystem: SystemRecord = {
|
||||
id: system.id,
|
||||
name: system.solarSystemName,
|
||||
region: "Wormhole",
|
||||
connectedTo: system.connectedSystems
|
||||
}
|
||||
await systemsCollection.update(system.id, legitSystem);
|
||||
} else {
|
||||
return await wormholeCollection.create(system);
|
||||
const createdWormhole = await wormholeCollection.create(system);
|
||||
const legitSystem: SystemRecord = {
|
||||
id: createdWormhole.id,
|
||||
name: createdWormhole.solarSystemName,
|
||||
region: "Wormhole",
|
||||
connectedTo: createdWormhole.connectedSystems,
|
||||
}
|
||||
await systemsCollection.create(legitSystem);
|
||||
return createdWormhole;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error saving wormhole system:', error);
|
||||
@@ -35,6 +52,7 @@ export const deleteWormholeSystem = async (system: System): Promise<void> => {
|
||||
throw new Error('System has no ID');
|
||||
}
|
||||
await wormholeCollection.delete(system.id);
|
||||
await systemsCollection.delete(system.id);
|
||||
} catch (error) {
|
||||
console.error('Error deleting wormhole system:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user