Fix reactions

This commit is contained in:
Jonathan Staab 2022-12-26 13:36:58 -08:00
parent 452c3d8725
commit 7b7fb2cdcb
3 changed files with 16 additions and 17 deletions

View File

@ -1,7 +1,7 @@
<script> <script>
import cx from 'classnames' import cx from 'classnames'
import extractUrls from 'extract-urls' import extractUrls from 'extract-urls'
import {whereEq, find} from 'ramda' import {whereEq, reject, propEq, find} from 'ramda'
import {slide} from 'svelte/transition' import {slide} from 'svelte/transition'
import {navigate} from 'svelte-routing' import {navigate} from 'svelte-routing'
import {quantify} from 'hurdak/lib/hurdak' import {quantify} from 'hurdak/lib/hurdak'
@ -31,10 +31,11 @@
$: { $: {
likes = note.reactions.filter(n => ['', '+'].includes(n.content)) likes = note.reactions.filter(n => ['', '+'].includes(n.content))
flags = note.reactions.filter(whereEq({content: '-'})) flags = note.reactions.filter(whereEq({content: '-'}))
like = find(whereEq({pubkey: $user?.pubkey}), likes)
flag = find(whereEq({pubkey: $user?.pubkey}), flags)
} }
$: like = find(whereEq({pubkey: $user?.pubkey}), likes)
$: flag = find(whereEq({pubkey: $user?.pubkey}), flags)
const onClick = e => { const onClick = e => {
if (!['I'].includes(e.target.tagName) && !hasParent('a', e.target)) { if (!['I'].includes(e.target.tagName) && !hasParent('a', e.target)) {
modal.set({note}) modal.set({note})
@ -45,21 +46,19 @@
modal.set({note: {id: findReply(note)}}) modal.set({note: {id: findReply(note)}})
} }
const react = content => { const react = async content => {
if ($user) { if (!$user) {
relay.cmd.createReaction(content, note) return navigate('/login')
} else {
navigate('/login')
} }
const event = await relay.cmd.createReaction(content, note)
if (content === '+') { if (content === '+') {
like = true likes = likes.concat(event)
likes += 1
} }
if (content === '-') { if (content === '-') {
flag = true flags = flags.concat(event)
flags += 1
} }
} }
@ -67,13 +66,11 @@
relay.cmd.deleteEvent([e.id]) relay.cmd.deleteEvent([e.id])
if (e.content === '+') { if (e.content === '+') {
like = false likes = reject(propEq('pubkey', $user.pubkey), likes)
likes -= 1
} }
if (e.content === '-') { if (e.content === '-') {
flag = false flags = reject(propEq('pubkey', $user.pubkey), flags)
flags -= 1
} }
} }

View File

@ -165,6 +165,8 @@ const renderNote = async (note, {showEntire = false}) => {
$a.href = url $a.href = url
$a.target = "_blank noopener" $a.target = "_blank noopener"
$a.className = "underline" $a.className = "underline"
/* eslint no-useless-escape: 0 */
$a.innerText = first(url.replace(/https?:\/\/(www\.)?/, '').split(/[\/\?#]/)) $a.innerText = first(url.replace(/https?:\/\/(www\.)?/, '').split(/[\/\?#]/))
// If the url is on its own line, remove it entirely. Otherwise, replace it with the link // If the url is on its own line, remove it entirely. Otherwise, replace it with the link

View File

@ -3,7 +3,7 @@
import {onMount, onDestroy} from 'svelte' import {onMount, onDestroy} from 'svelte'
import {fly} from 'svelte/transition' import {fly} from 'svelte/transition'
import {navigate} from 'svelte-routing' import {navigate} from 'svelte-routing'
import {now, timedelta} from 'src/util/misc' import {now} from 'src/util/misc'
import Tabs from "src/partials/Tabs.svelte" import Tabs from "src/partials/Tabs.svelte"
import Button from "src/partials/Button.svelte" import Button from "src/partials/Button.svelte"
import Notes from "src/views/person/Notes.svelte" import Notes from "src/views/person/Notes.svelte"