Ignore:
Timestamp:
06/24/26 16:28:50 (11 days ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
a8f4a2d
Parents:
0b502c2
Message:

Fixed writer section and admin management

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chapterx-frontend/src/components/story/LikeButton.tsx

    r0b502c2 r99c1e45  
    99const API = 'https://localhost:7125/api'
    1010
    11 function getAuthHeaders() {
    12   try {
    13     const token = JSON.parse(localStorage.getItem('chapterx-auth') || '{}')?.state?.token
    14     return token ? { Authorization: `Bearer ${token}` } : {}
    15   } catch { return {} }
    16 }
    17 
    1811interface LikeButtonProps {
    1912  storyId: number
     
    2518export const LikeButton: React.FC<LikeButtonProps> = ({ storyId, authorUserId, totalLikes, onCountChange }) => {
    2619  const navigate = useNavigate()
    27   const { currentUser } = useAuthStore()
     20  const { currentUser, token } = useAuthStore()
    2821  const { addNotification } = useNotificationStore()
     22  const authHeaders = token ? { Authorization: `Bearer ${token}` } : {}
    2923  const { addToast } = useUIStore()
    3024  const [liked, setLiked] = useState(false)
     
    5549    try {
    5650      if (liked) {
    57         await axios.delete(`${API}/likes/user/${currentUser.user_id}/story/${storyId}`, { headers: getAuthHeaders() })
     51        await axios.delete(`${API}/likes/user/${currentUser.user_id}/story/${storyId}`, { headers: authHeaders })
    5852        setLiked(false)
    5953        setCount(c => { const n = c - 1; onCountChange?.(n); return n })
    6054        addToast('Removed from likes', 'info')
    6155      } else {
    62         await axios.post(`${API}/likes`, { userId: currentUser.user_id, storyId }, { headers: getAuthHeaders() })
     56        await axios.post(`${API}/likes`, { userId: currentUser.user_id, storyId }, { headers: authHeaders })
    6357        setLiked(true)
    6458        setCount(c => { const n = c + 1; onCountChange?.(n); return n })
Note: See TracChangeset for help on using the changeset viewer.