Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Revert "Fold long content""" #1581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions web/src/lib/EventHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { nip19, type Event } from 'nostr-tools';
import type { Event } from 'nostr-tools';
import type { id } from './Types';
import { isParameterizedReplaceableKind, isReplaceableKind } from './nostr-tools/kinds';

export function isReply(event: Event): boolean {
if (!event.tags.some(([tagName]) => tagName === 'p')) {
Expand Down Expand Up @@ -185,21 +184,3 @@ export function isNostrHex(hex: string): boolean {
export function getTitle(tags: string[][]): string | undefined {
return filterTags('title', tags).at(0);
}

export function getAddress(event: Event): string {
if (isReplaceableKind(event.kind)) {
return nip19.naddrEncode({
kind: event.kind,
pubkey: event.pubkey,
identifier: ''
});
} else if (isParameterizedReplaceableKind(event.kind)) {
return nip19.naddrEncode({
kind: event.kind,
pubkey: event.pubkey,
identifier: findIdentifier(event.tags) ?? ''
});
} else {
return nip19.neventEncode({ id: event.id, author: event.pubkey });
}
}
62 changes: 5 additions & 57 deletions web/src/lib/components/items/Note.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import { Kind, nip19 } from 'nostr-tools';
import type { EventItem, Item } from '$lib/Items';
import { goto } from '$app/navigation';
import { metadataStore } from '$lib/cache/Events';
import IconMessages from '@tabler/icons-svelte/icons/messages';
import { readRelays } from '$lib/stores/Author';
Expand All @@ -11,7 +9,7 @@
import { Api } from '$lib/Api';
import { onMount } from 'svelte';
import Content from '$lib/components/Content.svelte';
import { getAddress, isReply } from '$lib/EventHelper';
import { isReply } from '$lib/EventHelper';
import { Channel, channelIdStore } from '$lib/Channel';
import EventMetadata from '$lib/components/EventMetadata.svelte';
import ProxyLink from '../ProxyLink.svelte';
Expand Down Expand Up @@ -40,21 +38,6 @@
showContent = true;
};

//#region Fold

let height: number | undefined;
let fold = false;
let first = true;

$: folded = !full && fold;

$: if (height !== undefined && height > 500 && first) {
fold = true;
first = false;
}

//#endregion

onMount(async () => {
if (item.event.kind === Kind.ChannelMessage) {
channelId = item.event.tags
Expand Down Expand Up @@ -112,20 +95,12 @@
<button on:click={showWarningContent}>Show</button>
</div>
{:else}
<div class="content" class:folded bind:clientHeight={height}>
<div class="content" class:shorten={!full}>
{#if Number(item.event.kind) === 1063}
<Nip94 event={item.event} />
{:else}
<Content content={item.event.content} tags={item.event.tags} />
{/if}
{#if folded}
<button
class="open"
on:click={async () => await goto(`/${getAddress(item.event)}`)}
>
<span>{$_('fold.view')}</span>
</button>
{/if}
</div>
{/if}
{#if item.event.kind === Kind.ChannelMessage && channelId !== undefined && $channelIdStore === undefined}
Expand Down Expand Up @@ -161,38 +136,11 @@

.content {
margin: 0.2rem 0 0 0;
overflow: auto;
}

.folded {
max-height: 500px;
overflow: hidden;
}

.open {
position: absolute;
bottom: 0;

width: 100%;
height: 2rem;
padding: 0;
border-radius: 0;
background: linear-gradient(transparent, var(--surface));
}

.open span {
display: inline-block;
color: var(--accent);
background-color: var(--accent-surface-high);
padding: 0.3rem 1.5rem;
border-radius: calc(infinity * 1px);
}

.open:hover {
opacity: 1;
}

.open:hover span {
background-color: var(--accent-surface);
.content.shorten {
max-height: 30em;
}

.channel,
Expand Down
3 changes: 0 additions & 3 deletions web/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,5 @@
"unknown": "Unknown",
"impersonation": "Impersonation"
}
},
"fold": {
"view": "View more"
}
}
3 changes: 0 additions & 3 deletions web/src/lib/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,5 @@
"unknown": "不明",
"impersonation": "なりすまし"
}
},
"fold": {
"view": "もっと見る"
}
}
7 changes: 0 additions & 7 deletions web/src/lib/nostr-tools/kinds.ts

This file was deleted.

Loading