Show pending ISAC contributions immediately
This commit is contained in:
@@ -8,6 +8,32 @@ import { getContributorMode } from '$lib/server/contributor-mode';
|
||||
export const DATA_MODULES = ['attributes', 'talents', 'brands', 'gear', 'weapons', 'protocols', 'skillchips'] as const;
|
||||
export type DataModule = typeof DATA_MODULES[number];
|
||||
|
||||
const proposalResultKeys: Partial<Record<DataModule, Record<string, { saved: string; mode?: string }>>> = {
|
||||
attributes: { save: { saved: 'saved', mode: 'editorMode' } },
|
||||
brands: { save: { saved: 'brandSaved', mode: 'brandMode' } },
|
||||
gear: {
|
||||
save: { saved: 'gearSaved', mode: 'gearMode' },
|
||||
saveAugmentProfile: { saved: 'augmentProfileSaved' }
|
||||
},
|
||||
weapons: { save: { saved: 'weaponSaved', mode: 'weaponMode' } },
|
||||
talents: {
|
||||
saveTrigger: { saved: 'triggerSaved', mode: 'triggerMode' },
|
||||
saveTalent: { saved: 'talentSaved', mode: 'talentMode' }
|
||||
},
|
||||
protocols: {
|
||||
save: { saved: 'protocolSaved', mode: 'protocolMode' },
|
||||
saveProfile: { saved: 'profileSaved' }
|
||||
},
|
||||
skillchips: { save: { saved: 'skillChipSaved', mode: 'skillChipMode' } }
|
||||
};
|
||||
|
||||
export function proposalActionResult(module: DataModule, action: string, edit: boolean, proposalId: string) {
|
||||
const keys = proposalResultKeys[module]?.[action];
|
||||
return keys
|
||||
? { [keys.saved]: true, ...(keys.mode ? { [keys.mode]: edit ? 'edit' : 'add' } : {}), proposalId, resultToken: randomUUID() }
|
||||
: { proposalQueued: true, proposalId, resultToken: randomUUID() };
|
||||
}
|
||||
|
||||
type SerializedEntry =
|
||||
| { name: string; kind: 'text'; value: string }
|
||||
| { name: string; kind: 'file'; value: string; fileName: string; type: string };
|
||||
@@ -84,6 +110,10 @@ export async function getPendingEntities(_userId: string, definitions: PendingDe
|
||||
const definition = definitions.find((item) => item.module === row.module && item.action === row.action)!;
|
||||
const values = serializedTextValues(String(row.payload_json));
|
||||
const field = (name: string) => values.find((entry) => entry.name === name)?.value ?? '';
|
||||
const fieldValue = (name: string) => {
|
||||
const matches = values.filter((entry) => entry.name === name).map((entry) => entry.value);
|
||||
return matches.length > 1 ? matches : matches[0] ?? '';
|
||||
};
|
||||
return {
|
||||
id: String(row.draft_entity_id),
|
||||
proposalId: String(row.id),
|
||||
@@ -92,7 +122,7 @@ export async function getPendingEntities(_userId: string, definitions: PendingDe
|
||||
kind: definition.kind,
|
||||
name: field('name'),
|
||||
proposerName: String(row.proposer_name),
|
||||
...Object.fromEntries((definition.fields ?? []).map((name) => [name, field(name)]))
|
||||
...Object.fromEntries((definition.fields ?? []).map((name) => [name, fieldValue(name)]))
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -124,7 +154,7 @@ export async function queueDataProposal(user: AuthUser, module: DataModule, acti
|
||||
before: null,
|
||||
after: { module, action, entityId, draftEntityId, dependencies: dependencies.map((item) => item.id), summary }
|
||||
});
|
||||
return id;
|
||||
return { id, entityId, draftEntityId };
|
||||
}
|
||||
|
||||
export async function shouldModerateDataMutation(user: AuthUser | null) {
|
||||
|
||||
Reference in New Issue
Block a user