Problem s dvojitym proklikem

Aleksandr
Člen | 14
+
0
-

čau jsem **začátečník ** s Ajaxem, vlastně musím vyřešit tohle a mám klid od Ajaxu.
mám metodu handleLike a problém je, že musím 2× klikat, po načtení stránky, aby fungovala (na první kliknutí nereaguje, pak již funguje normálně jak chci).

v ArticlePresentru

  public function handleLike($id) {
    $userID = $this->user->getId();
    $userhaslike = $this->ArticleService->hasUserLikedArticle($userID, $id);
    if ($userhaslike == null) {
      $this->ArticleService->addArticleLike($userID, $id);
      $this->template->classLike = '';
      $this->redrawControl('likes');
      $this->redrawControl('likeIcon');
    } else {
      $this->ArticleService->dislikeArticleByUser($userID, $id);
      $this->template->classLike = 'graylike';
      $this->redrawControl('likes');
      $this->redrawControl('likeIcon');
    }
  }

v latte:

  <a class="ajax redrawLike" n:href="Like!,$article->id">
    {snippet likeIcon}
      <img class="{$classLike}" width="50px" src="http://pngimg.com/uploads/like/like_PNG62.png">
    {/snippet}
  </a>
Ondřej Kubíček
Člen | 494
+
0
-

předpokládám, že tam máš ještě render metodu, která ti to přepíše
handle se volá dřív než render viz životní cyklus – https://doc.nette.org/…n/presenters#…

Aleksandr
Člen | 14
+
0
-

zdravím to není ono, v ArticlePresentru nemám nic jinýho kromě actionDetail

 public function actionDetail($id, $title) {
    $userhaslike = $this->ArticleService->hasUserLikedArticle($this->user->getId(), $id);
    if ($userhaslike == null) {
      $this->template->classLike = '';
    } else {
      $this->template->classLike = 'graylike';
    }
    $this->template->article = $this->ArticleService->getArticle($id);
    $this->template->articles = $this->ArticleService->getPublishedArticles(3);
  }