Added relation comment. Changed relation dialog order.
This commit is contained in:
@@ -43,8 +43,17 @@ function getLabel(relation) {
|
||||
return `${label.charAt(0).toLowerCase()}${label.slice(1)}`;
|
||||
}
|
||||
|
||||
function getEditRelation(relation) {
|
||||
return props.edits.relations?.find((editRelation) => getRelationKey(editRelation) === getRelationKey(relation));
|
||||
}
|
||||
|
||||
function isIncluded(relation) {
|
||||
return props.edits.relations?.some((editRelation) => getRelationKey(editRelation) === getRelationKey(relation));
|
||||
return !!getEditRelation(relation);
|
||||
}
|
||||
|
||||
// show the comment as edited, or as it was when the relation is removed
|
||||
function getComment(relation) {
|
||||
return getEditRelation(relation)?.comment ?? relation.comment;
|
||||
}
|
||||
|
||||
function toEdit(relation) {
|
||||
@@ -52,21 +61,21 @@ function toEdit(relation) {
|
||||
sceneId: relation.sceneId,
|
||||
type: relation.type,
|
||||
direction: relation.direction,
|
||||
comment: relation.comment || null,
|
||||
};
|
||||
}
|
||||
|
||||
// adding an existing relation again replaces its comment
|
||||
function addRelation(relation) {
|
||||
showDialog.value = false;
|
||||
|
||||
if (isIncluded(relation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (![...props.item.value, ...newRelations.value].some((existingRelation) => getRelationKey(existingRelation) === getRelationKey(relation))) {
|
||||
newRelations.value = newRelations.value.concat(relation);
|
||||
}
|
||||
|
||||
emit('relations', props.edits.relations.concat(toEdit(relation)));
|
||||
emit('relations', props.edits.relations
|
||||
.filter((editRelation) => getRelationKey(editRelation) !== getRelationKey(relation))
|
||||
.concat(toEdit(relation)));
|
||||
}
|
||||
|
||||
function openDialog() {
|
||||
@@ -99,6 +108,12 @@ watch(() => props.scene, () => {
|
||||
target="_blank"
|
||||
class="relation-name link"
|
||||
>{{ relation.scene?.title || `#${relation.sceneId}` }}</a>
|
||||
|
||||
<span
|
||||
v-if="getComment(relation)"
|
||||
v-tooltip="getComment(relation)"
|
||||
class="relation-comment"
|
||||
> ({{ getComment(relation) }})</span>
|
||||
</span>
|
||||
|
||||
<Icon
|
||||
@@ -235,4 +250,15 @@ watch(() => props.scene, () => {
|
||||
color: inherit;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
.relation-comment {
|
||||
display: inline-block;
|
||||
max-width: 15rem;
|
||||
overflow: hidden;
|
||||
color: var(--glass-strong-10);
|
||||
font-style: italic;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -44,13 +44,18 @@ function getRelationKey(relation) {
|
||||
return `${relation.direction}:${relation.type}:${relation.sceneId}`;
|
||||
}
|
||||
|
||||
// a relation is modified if the other side has no relation with the same key, or it has a different comment
|
||||
function isRelationModified(relation, otherRelations) {
|
||||
return !otherRelations.some((otherRelation) => getRelationKey(otherRelation) === getRelationKey(relation) && (otherRelation.comment || null) === (relation.comment || null));
|
||||
}
|
||||
|
||||
function curateRelation(relation, modified) {
|
||||
const label = getRelationLabel(relation.type, relation.direction);
|
||||
const relatedScene = relationScenesById.value[relation.sceneId];
|
||||
|
||||
return {
|
||||
id: getRelationKey(relation),
|
||||
name: `${label.charAt(0).toLowerCase()}${label.slice(1)} ${relatedScene?.title || `#${relation.sceneId}`}`,
|
||||
name: `${label.charAt(0).toLowerCase()}${label.slice(1)} ${relatedScene?.title || `#${relation.sceneId}`}${relation.comment ? ` (${relation.comment})` : ''}`,
|
||||
modified,
|
||||
};
|
||||
}
|
||||
@@ -114,7 +119,7 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
|
||||
}
|
||||
|
||||
if (key === 'relations') {
|
||||
return [key, value.map((relation) => curateRelation(relation, revision.deltas.some((delta) => delta.key === key && !delta.value.some((deltaRelation) => getRelationKey(deltaRelation) === getRelationKey(relation)))))];
|
||||
return [key, value.map((relation) => curateRelation(relation, revision.deltas.some((delta) => delta.key === key && isRelationModified(relation, delta.value))))];
|
||||
}
|
||||
|
||||
if (key === 'socials') {
|
||||
@@ -164,7 +169,7 @@ const curatedRevisions = computed(() => revisions.value.map((revision) => {
|
||||
if (delta.key === 'relations') {
|
||||
return {
|
||||
...delta,
|
||||
value: delta.value.map((relation) => curateRelation(relation, !(revision.base.relations || []).some((baseRelation) => getRelationKey(baseRelation) === getRelationKey(relation)))),
|
||||
value: delta.value.map((relation) => curateRelation(relation, isRelationModified(relation, revision.base.relations || []))),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import Dialog from '#/components/dialog/dialog.vue';
|
||||
|
||||
import { get } from '#/src/api.js';
|
||||
import getPath from '#/src/get-path.js';
|
||||
import { getRelationLabel } from '#/utils/relation-labels.js';
|
||||
import { getRelationLabel, sortRelationTypes } from '#/utils/relation-labels.js';
|
||||
|
||||
const props = defineProps({
|
||||
scene: {
|
||||
@@ -30,6 +30,8 @@ const results = ref([]);
|
||||
const searching = ref(false);
|
||||
const selectedScene = ref(null);
|
||||
const selectedOption = ref(null);
|
||||
const comment = ref('');
|
||||
const commentLimit = 500; // matches the server limit
|
||||
const searchCompleted = ref(false); // only show 'no results' once a search for the current query has finished
|
||||
|
||||
let searchTimeout = null;
|
||||
@@ -37,7 +39,7 @@ let searchCount = 0;
|
||||
|
||||
// each type can be read from either side, e.g. this scene is a 'Remaster of' or 'Remastered as' the selected scene
|
||||
// symmetric types like variants read the same both ways
|
||||
const options = computed(() => props.types.flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
|
||||
const options = computed(() => sortRelationTypes(props.types, ({ type }) => type).flatMap(({ type, symmetric }) => (symmetric ? ['both'] : ['target', 'source']).map((direction) => ({
|
||||
key: `${type}-${direction}`,
|
||||
type,
|
||||
direction,
|
||||
@@ -48,7 +50,7 @@ const hasQuery = computed(() => query.value.trim().length > 0);
|
||||
const showResults = computed(() => results.value.length > 0 || (hasQuery.value && !searching.value && searchCompleted.value));
|
||||
|
||||
// derivations and compilations are released after what they're based on, the source of the relation should not predate the target
|
||||
const chronologicalTypes = ['rerelease', 'remaster', 'compilation'];
|
||||
const chronologicalTypes = ['rerelease', 'remaster', 'reedit', 'compilation'];
|
||||
const datePrecisions = { year: startOfYear, month: startOfMonth };
|
||||
|
||||
// compare at the coarsest precision of the two, a scene known only by its year isn't necessarily earlier than one from later that year
|
||||
@@ -85,7 +87,7 @@ const inversion = computed(() => {
|
||||
});
|
||||
|
||||
const canSubmit = computed(() => !!selectedScene.value && !!selectedOption.value);
|
||||
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value);
|
||||
const hasChanges = computed(() => !!selectedScene.value || !!selectedOption.value || comment.value.trim().length > 0);
|
||||
|
||||
// accept a pasted scene ID or traxxx scene URL, the search index does not match IDs
|
||||
function getSceneId(value) {
|
||||
@@ -166,6 +168,7 @@ function addRelation() {
|
||||
sceneId: selectedScene.value.id,
|
||||
type: selectedOption.value.type,
|
||||
direction: selectedOption.value.direction,
|
||||
comment: comment.value.trim() || null,
|
||||
scene: selectedScene.value,
|
||||
});
|
||||
}
|
||||
@@ -288,6 +291,13 @@ onMounted(() => focusInput());
|
||||
</template>
|
||||
</VDropdown>
|
||||
|
||||
<input
|
||||
v-model="comment"
|
||||
:maxlength="commentLimit"
|
||||
placeholder="Optional comment"
|
||||
class="comment input"
|
||||
>
|
||||
|
||||
<p
|
||||
v-if="inversion"
|
||||
class="inversion"
|
||||
@@ -434,4 +444,8 @@ onMounted(() => focusInput());
|
||||
margin: 0;
|
||||
padding: .5rem;
|
||||
}
|
||||
|
||||
.comment {
|
||||
margin: .5rem 0 0 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -16,6 +16,11 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
// further detail on the label, shown on hover
|
||||
labelTooltip: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const pageContext = inject('pageContext');
|
||||
@@ -60,8 +65,15 @@ const favorited = ref(props.scene.stashes.some((sceneStash) => sceneStash.id ===
|
||||
|
||||
<span
|
||||
v-if="label"
|
||||
v-tooltip="labelTooltip"
|
||||
class="label"
|
||||
>{{ label }}</span>
|
||||
:class="{ 'has-tooltip': labelTooltip }"
|
||||
>
|
||||
<Icon
|
||||
v-if="labelTooltip"
|
||||
icon="bubble-lines3"
|
||||
/>{{ label }}
|
||||
</span>
|
||||
|
||||
<Heart
|
||||
domain="scenes"
|
||||
@@ -235,6 +247,19 @@ const favorited = ref(props.scene.stashes.some((sceneStash) => sceneStash.id ===
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
pointer-events: none;
|
||||
|
||||
&.has-tooltip {
|
||||
pointer-events: auto;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: .75rem;
|
||||
height: .75rem;
|
||||
margin-right: .3rem;
|
||||
fill: var(--text-light);
|
||||
vertical-align: -.1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
|
||||
Reference in New Issue
Block a user