@ -120,7 +120,8 @@ function handleReaction(evt, relay) {
// feed
// feed
const feedContainer = document . querySelector ( '#homefeed' ) ;
const feedContainer = document . querySelector ( '#homefeed' ) ;
const feedDomMap = { } ;
const feedDomMap = { } ;
const replyDomMap = window . replyDomMap = { } ;
const replyDomMap = { } ;
const restoredReplyTo = localStorage . getItem ( 'reply_to' ) ;
const sortByCreatedAt = ( evt1 , evt2 ) => {
const sortByCreatedAt = ( evt1 , evt2 ) => {
if ( evt1 . created _at === evt2 . created _at ) {
if ( evt1 . created _at === evt2 . created _at ) {
@ -191,6 +192,7 @@ function createTextNote(evt, relay) {
} , [ elem ( 'img' , { height : 24 , width : 24 , src : 'assets/comment.svg' } ) ] ) ,
} , [ elem ( 'img' , { height : 24 , width : 24 , src : 'assets/comment.svg' } ) ] ) ,
replies [ 0 ] ? elem ( 'div' , { className : 'mobx-replies' } , replyFeed . reverse ( ) ) : '' ,
replies [ 0 ] ? elem ( 'div' , { className : 'mobx-replies' } , replyFeed . reverse ( ) ) : '' ,
] ) ;
] ) ;
if ( restoredReplyTo === evt . id ) appendReplyForm ( body . querySelector ( 'button[name="reply"]' ) ) ;
return rendernArticle ( [ img , body ] ) ;
return rendernArticle ( [ img , body ] ) ;
}
}
@ -359,23 +361,11 @@ function getMetadata(evt, relay) {
}
}
// reply
// reply
const writeForm = document . querySelector ( '#writeForm' ) ;
const input = document . querySelector ( 'textarea[name="message"]' ) ;
let lastReplyBtn = null ;
let replyTo = null ;
feedContainer . addEventListener ( 'click' , ( e ) => {
feedContainer . addEventListener ( 'click' , ( e ) => {
const button = e . target . closest ( 'button' ) ;
const button = e . target . closest ( 'button' ) ;
if ( button && button . name === 'reply' ) {
if ( button && button . name === 'reply' ) {
if ( lastReplyBtn ) {
appendReplyForm ( button ) ;
lastReplyBtn . hidden = false ;
localStorage . setItem ( 'reply_to' , button . dataset . eventId ) ;
}
lastReplyBtn = button ;
// button.hidden = true;
button . after ( writeForm ) ;
button . after ( sendStatus ) ;
writeForm . hidden = false ;
replyTo = [ 'e' , button . dataset . eventId , button . dataset . relay ] ;
input . focus ( ) ;
return ;
return ;
}
}
if ( button && button . name === 'star' ) {
if ( button && button . name === 'star' ) {
@ -384,12 +374,21 @@ feedContainer.addEventListener('click', (e) => {
}
}
} ) ;
} ) ;
const writeForm = document . querySelector ( '#writeForm' ) ;
const writeInput = document . querySelector ( 'textarea[name="message"]' ) ;
function appendReplyForm ( el ) {
el . after ( writeForm ) ;
el . after ( sendStatus ) ;
writeInput . focus ( ) ;
}
const newMessageDiv = document . querySelector ( '#newMessage' ) ;
const newMessageDiv = document . querySelector ( '#newMessage' ) ;
document . querySelector ( '#bubble' ) . addEventListener ( 'click' , ( e ) => {
document . querySelector ( '#bubble' ) . addEventListener ( 'click' , ( e ) => {
replyTo = null ;
localStorage. removeItem ( 'reply_to' ) ;
newMessageDiv . prepend ( writeForm ) ;
newMessageDiv . prepend ( writeForm ) ;
newMessageDiv . append ( sendStatus ) ;
newMessageDiv . append ( sendStatus ) ;
input . focus ( ) ;
wr iteI nput. focus ( ) ;
} ) ;
} ) ;
async function upvote ( eventId , relay ) {
async function upvote ( eventId , relay ) {
@ -428,14 +427,15 @@ writeForm.addEventListener('submit', async (e) => {
if ( ! pubkey || ! privatekey ) {
if ( ! pubkey || ! privatekey ) {
return onSendError ( new Error ( 'no pubkey/privatekey' ) ) ;
return onSendError ( new Error ( 'no pubkey/privatekey' ) ) ;
}
}
if ( ! input. value ) {
if ( ! wr iteI nput. value ) {
return onSendError ( new Error ( 'message is empty' ) ) ;
return onSendError ( new Error ( 'message is empty' ) ) ;
}
}
const tags = replyTo ? [ replyTo ] : [ ] ;
const replyTo = localStorage . getItem ( 'reply_to' ) ;
const tags = replyTo ? [ [ 'e' , replyTo , eventRelayMap [ replyTo ] [ 0 ] ] ] : [ ] ;
const newEvent = {
const newEvent = {
kind : 1 ,
kind : 1 ,
pubkey ,
pubkey ,
content : input. value ,
content : wr iteI nput. value ,
tags ,
tags ,
created _at : Math . floor ( Date . now ( ) * 0.001 ) ,
created _at : Math . floor ( Date . now ( ) * 0.001 ) ,
} ;
} ;
@ -447,12 +447,11 @@ writeForm.addEventListener('submit', async (e) => {
}
}
if ( status === 1 ) {
if ( status === 1 ) {
sendStatus . hidden = true ;
sendStatus . hidden = true ;
input . value = '' ;
writeInput . value = '' ;
writeInput . style . removeProperty ( 'height' ) ;
publish . disabled = true ;
publish . disabled = true ;
if ( lastReplyBtn ) {
if ( replyTo ) {
lastReplyBtn . hidden = false ;
localStorage . removeItem ( 'reply_to' ) ;
lastReplyBtn = null ;
replyTo = null ;
newMessageDiv . append ( writeForm ) ;
newMessageDiv . append ( writeForm ) ;
newMessageDiv . append ( sendStatus ) ;
newMessageDiv . append ( sendStatus ) ;
}
}
@ -462,8 +461,22 @@ writeForm.addEventListener('submit', async (e) => {
}
}
} ) ;
} ) ;
input . addEventListener ( 'input' , ( ) => publish . disabled = ! input . value ) ;
writeInput . addEventListener ( 'input' , ( ) => {
input . addEventListener ( 'blur' , ( ) => sendStatus . textContent = '' ) ;
publish . disabled = ! writeInput . value ;
updateElemHeight ( writeInput ) ;
} ) ;
writeInput . addEventListener ( 'blur' , ( ) => sendStatus . textContent = '' ) ;
function updateElemHeight ( el ) {
el . style . removeProperty ( 'height' ) ;
if ( el . value ) {
el . style . paddingBottom = 0 ;
el . style . paddingTop = 0 ;
el . style . height = el . scrollHeight + 'px' ;
el . style . removeProperty ( 'padding-bottom' ) ;
el . style . removeProperty ( 'padding-top' ) ;
}
}
// settings
// settings
const settingsForm = document . querySelector ( 'form[name="settings"]' ) ;
const settingsForm = document . querySelector ( 'form[name="settings"]' ) ;