-
Notifications
You must be signed in to change notification settings - Fork 0
/
ideahub.js
116 lines (97 loc) · 4.38 KB
/
ideahub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
document.addEventListener('DOMContentLoaded', function() {
const ideaForm = document.querySelector('.idea-sharing form');
const ideaTitleInput = document.querySelector('.idea-sharing form input[type="text"]');
const ideaDescriptionInput = document.querySelector('.idea-sharing form textarea');
const skillsRequiredInput = document.querySelector('.idea-sharing form input[type="text"][placeholder="Skills Needed (comma-separated)"]');
const ideasContainer = document.querySelector('.ideas .idea-container');
const joinIdeaModal = document.getElementById('joinIdeaModal');
const joinIdeaForm = document.getElementById('joinIdeaForm');
function saveIdeasToLocalStorage(ideas) {
localStorage.setItem('ideas', JSON.stringify(ideas));
}
function getIdeasFromLocalStorage() {
const storedIdeas = localStorage.getItem('ideas');
return storedIdeas ? JSON.parse(storedIdeas) : [];
}
function renderIdeasFromLocalStorage() {
const ideas = getIdeasFromLocalStorage();
ideasContainer.innerHTML = ''; // Clear existing ideas
ideas.forEach(function(idea, index) {
const ideaCard = createIdeaCard(idea.title, idea.description, idea.skills, index);
ideasContainer.appendChild(ideaCard);
});
}
function createIdeaCard(title, description, skills, index) {
const ideaCard = document.createElement('div');
ideaCard.classList.add('idea-card');
ideaCard.innerHTML = `
<h3 style="font-weight:bold;">${title}</h3>
<p>${description}</p>
<p>Skills Needed: ${skills}</p>
<button class="join-idea-btn">Join Idea</button>
<button class="delete-idea-btn" data-index="${index}">Delete Idea</button>
`;
return ideaCard;
}
renderIdeasFromLocalStorage();
ideaForm.addEventListener('submit', function(event) {
event.preventDefault();
const ideaTitle = ideaTitleInput.value;
const ideaDescription = ideaDescriptionInput.value;
const skillsRequired = skillsRequiredInput.value;
if (ideaTitle.trim() !== '') {
const idea = {
title: ideaTitle,
description: ideaDescription,
skills: skillsRequired
};
const ideaCard = createIdeaCard(idea.title, idea.description, idea.skills);
ideasContainer.appendChild(ideaCard);
const ideas = getIdeasFromLocalStorage();
ideas.push(idea);
saveIdeasToLocalStorage(ideas);
ideaForm.reset();
} else {
alert('Please enter an idea title.');
}
});
ideasContainer.addEventListener('click', function(event) {
if (event.target.classList.contains('delete-idea-btn')) {
const index = event.target.dataset.index;
deleteIdea(index);
} else if (event.target.classList.contains('join-idea-btn')) {
joinIdeaModal.style.display = 'block';
}
});
joinIdeaForm.addEventListener('submit', function(event) {
event.preventDefault();
// Get form values
const name = document.getElementById('name').value;
const phone = document.getElementById('phone').value;
const email = document.getElementById('email').value;
const languages = document.getElementById('languages').value;
// Do something with the form data (e.g., send a request to the server)
// Display success notification
alert('Request sent successfully!');
// Close the modal
joinIdeaModal.style.display = 'none';
// Clear form fields
joinIdeaForm.reset();
});
// Close the modal when clicking on the close button
document.querySelector('.close').addEventListener('click', function() {
joinIdeaModal.style.display = 'none';
});
// Close the modal when clicking outside of it
window.addEventListener('click', function(event) {
if (event.target === joinIdeaModal) {
joinIdeaModal.style.display = 'none';
}
});
function deleteIdea(index) {
const ideas = getIdeasFromLocalStorage();
ideas.splice(index, 1);
saveIdeasToLocalStorage(ideas);
renderIdeasFromLocalStorage();
}
});