const start = async () => { const usersResponse = await getPosts(0, untrack(checkedUsers)); let checked = untrack(checkedUsers); if (usersResponse) { checked.push( String( usersResponse.success[Object.keys(usersResponse.success)[0]].author_id ) ); setCheckedUsers(checked); setUsers(usersResponse); setAllUsersId( Object.keys(usersResponse.success).map((user) => Number(usersResponse.success[user].author_id) ) ); } };
let [users, setUsers] = createSignal([], { equals: false }); let [checkedUsers, setCheckedUsers] = createSignal([]); let [allUsersId, setAllUsersId] = createSignal([]); let [checkedHorizontalPosts, setCheckedHorizontalPosts] = createSignal({}); let [currentUser, setCurrentUser] = createSignal();
let [users, setUsers] = createSignal([], { equals: false }); let [checkedUsers, setCheckedUsers] = createSignal([], { equals: false }); let [allUsersId, setAllUsersId] = createSignal([], { equals: false }); let [checkedHorizontalPosts, setCheckedHorizontalPosts] = createSignal( {}, { equals: false } ); let [currentUser, setCurrentUser] = createSignal();
const onUserHorizontalSwipe = async (user) => { let json = checkedHorizontalPosts(); let usersStatic = users(); const slide = user.slides.filter((element) => element.classList.value.includes("active") )[0]; let [author_id, id] = [ Number(slide?.id.split(" ")[1]), Number(slide?.id.split(" ")[0]), ]; if (Object.keys(json).includes(String(author_id))) { if (!json[author_id].includes(id)) { json[author_id].push(id); } } else { json[author_id] = [id]; } setCheckedHorizontalPosts(json); Object.keys(users().success).map(async (user) => { if (users().success[user].author_id === author_id) { const difference = users().success[user].posts.length - json[author_id].length; if (difference == 2) { const postsByUser = await getUserPosts( users().success[user].posts[users().success[user].posts.length - 1] .id, author_id ); if (postsByUser) { postsByUser.success.map((post) => { usersStatic.success[user].posts.push(post); }); } } } }); setUsers(usersStatic); };
const onUserSwipe = async (user) => { setCurrentUser(user); const currentPost = user.slides.filter((element) => element.className.endsWith("active") )[0]; let checked = checkedUsers(); if (!checked.includes("" + currentPost.id)) { setCurrentUser(currentPost.id); checked.push(currentPost.id); console.log(checked); } setCheckedUsers(checked); const [usersStatic, checkedUsersStatic, allUsersIdStatic] = [ Object.keys(users().success), checkedUsers(), allUsersId(), ]; const difference = usersStatic.length - checkedUsersStatic.length; let usersJson = users(); if (difference === 1) { const usersResponseToAdd = await getPosts(0, allUsersIdStatic); if (usersResponseToAdd) { Object.keys(usersResponseToAdd.success).map( (user) => (usersJson.success[user] = usersResponseToAdd.success[user]) ); setUsers(usersJson); } } };
const start = async () => { const usersResponse = await getPosts(0, checkedUsers()); let checked = checkedUsers(); if (usersResponse) { checked.push( Number( usersResponse.success[Object.keys(usersResponse.success)[0]].author_id ) ); setCheckedUsers(checked); setUsers(usersResponse); setAllUsersId( Object.keys(usersResponse.success).map((user) => Number(usersResponse.success[user].author_id) ) ); } };