Resolving place in edit form.

This commit is contained in:
DebaucheryLibrarian 2024-10-31 03:55:26 +01:00
parent f8aa903817
commit 2c49e0f9fe
6 changed files with 2919 additions and 828 deletions

2
common

@ -1 +1 @@
Subproject commit 3bf8ce6e23a1c6c4c909b1a56b201903bad5b26e
Subproject commit 1122b4198f2c5bc27f9f4e3f3aedea6c81f09ba1

View File

@ -230,6 +230,10 @@ const timeline = computed(() => {
font-weight: bold;
}
&:hover {
z-index: 10;
}
&:before {
content: '';
display: inline-block;

3685
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -54,6 +54,7 @@
"redis": "^4.6.12",
"sharp": "^0.32.6",
"sirv": "^2.0.3",
"unprint": "^0.14.1",
"video.js": "^8.10.0",
"vike": "^0.4.150",
"vite": "^4.5.1",

View File

@ -706,8 +706,11 @@
@change="(checked) => apply = checked"
/>
<Ellipsis v-if="submitting" />
<!-- we don't want the return key to submit the form -->
<button
v-else
class="button button-primary"
type="button"
:disabled="editing.size === 0"
@ -728,6 +731,7 @@ import { format } from 'date-fns';
import Avatar from '#/components/edit/avatar.vue';
import Checkbox from '#/components/form/checkbox.vue';
import Ellipsis from '#/components/loading/ellipsis.vue';
import {
// get,
@ -965,6 +969,7 @@ const editing = ref(new Set());
const edits = ref(Object.fromEntries(fields.value.map((field) => [field.key, field.value])));
const comment = ref(null);
const apply = ref(user.role !== 'user');
const submitting = ref(false);
const submitted = ref(false);
const sizeUnits = ref('metric');
@ -1006,6 +1011,8 @@ const groupMap = {
async function submit() {
try {
submitting.value = true;
await post('/revisions/actors', {
actorId: actor.value.id,
edits: {
@ -1041,6 +1048,7 @@ async function submit() {
appendErrorMessage: true,
});
submitting.value = false;
editing.value = new Set();
edits.value = {};
comment.value = null;

View File

@ -5,9 +5,11 @@ import { MerkleJson } from 'merkle-json';
import moment from 'moment';
import omit from 'object.omit';
import convert from 'convert';
import unprint from 'unprint';
import initLogger from './logger.js';
import { knexOwner as knex, knexManticore } from './knex.js';
import redis from './redis.js';
import { utilsApi } from './manticore.js';
import { HttpError } from './errors.js';
import { fetchCountriesByAlpha2 } from './countries.js';
@ -18,6 +20,7 @@ import escape from '../utils/escape-manticore.js';
import slugify from '../utils/slugify.js';
import { curateRevision } from './revisions.js';
import { interpolateProfiles } from '../common/actors.mjs'; // eslint-disable-line import/namespace
import { resolvePlace } from '../common/geo.mjs'; // eslint-disable-line import/namespace
const logger = initLogger();
const mj = new MerkleJson();
@ -816,14 +819,48 @@ export async function createActorRevision(actorId, {
return [key, values];
}).filter(Boolean));
const deltas = Object.entries(edits).map(([key, value]) => {
const deltas = await Promise.all(Object.entries(edits).map(async ([key, value]) => {
if (baseActor[key] === value || typeof value === 'undefined') {
return null;
}
if (['originPlace', 'residencePlay'].includes(key)) {
console.log(key, value);
throw new Error('must be converted first!');
if (['originPlace', 'residencePlace'].includes(key)) {
if (!value) {
return [
// { key: key.includes('origin') ? 'originCountry' : 'residenceCountry', value: null },
{ key: key.includes('origin') ? 'originState' : 'residenceState', value: null },
{ key: key.includes('origin') ? 'originCity' : 'residenceCity', value: null },
];
}
const resolvedLocation = await resolvePlace(value, {
knex,
redis,
logger,
slugify,
unprint,
}, {
userAgent: 'contact via https://traxxx.me/',
});
if (!resolvedLocation) {
throw new Error(`Failed to resolve ${key} ${value}`);
}
return [
{
key: key.includes('origin') ? 'originCountry' : 'residenceCountry',
value: resolvedLocation.country,
},
{
key: key.includes('origin') ? 'originState' : 'residenceState',
value: resolvedLocation.state,
},
{
key: key.includes('origin') ? 'originCity' : 'residenceCity',
value: resolvedLocation.city,
},
];
}
if (['cup', 'bust', 'waist', 'hip'].includes(key)) {
@ -902,7 +939,7 @@ export async function createActorRevision(actorId, {
}
return { key, value };
}).filter(Boolean);
})).then((rawDeltas) => rawDeltas.flat().filter(Boolean));
const deltaComments = deltas.map((delta) => delta.comment);
const curatedComment = [comment, ...deltaComments].filter(Boolean).join(' | ');