Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion backend/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ def send_bloom():
)


# === Rebloom Feature ===
@jwt_required()
def rebloom(bloom_id):
current_user = get_current_user()

# Check if the bloom exists
original_bloom = blooms.get_bloom(bloom_id)

if original_bloom is None:
return make_response(
jsonify({"success": False, "message": "Bloom not found"}), 404
)

# Create a new bloom from the original one
content = f"Rebloomed from @{original_bloom.sender}: {original_bloom.content}"

blooms.add_bloom(sender=current_user, content=content)

return jsonify(
{
"success": True,
}
)


def get_bloom(id_str):
try:
id_int = int(id_str)
Expand Down Expand Up @@ -244,4 +269,4 @@ def verify_request_fields(names_to_types: Dict[str, type]) -> Union[Response, No
400,
)
)
return None
return None
4 changes: 3 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
register,
self_profile,
send_bloom,
rebloom,
suggested_follows,
user_blooms,
)
Expand Down Expand Up @@ -57,6 +58,7 @@ def main():
app.add_url_rule("/suggested-follows/<limit_str>", view_func=suggested_follows)

app.add_url_rule("/bloom", methods=["POST"], view_func=send_bloom)
app.add_url_rule("/rebloom/<int:bloom_id>", methods=["POST"], view_func=rebloom)
app.add_url_rule("/bloom/<id_str>", methods=["GET"], view_func=get_bloom)
app.add_url_rule("/blooms/<profile_username>", view_func=user_blooms)
app.add_url_rule("/hashtag/<hashtag>", view_func=hashtag)
Expand All @@ -65,4 +67,4 @@ def main():


if __name__ == "__main__":
main()
main()
12 changes: 10 additions & 2 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,17 @@ <h2 id="bloom-form-title" class="bloom-form__title">Share a Bloom</h2>
<article class="bloom box" data-bloom data-bloom-id="">
<div class="bloom__header flex">
<a href="#" class="bloom__username" data-username>Username</a>
<a href="#" class="bloom__time"><time class="bloom__time" data-time>2m</time></a>
<a href="#" class="bloom__time">
<time class="bloom__time" data-time>2m</time>
</a>
</div>
<div class="bloom__content" data-content></div>

<div class="bloom__actions">
<button type="button" data-action="rebloom">
🔁 Rebloom
</button>
</div>
</article>
</template>

Expand All @@ -258,4 +266,4 @@ <h2 id="bloom-form-title" class="bloom-form__title">Share a Bloom</h2>

<script type="module" src="/index.mjs"></script>
</body>
</html>
</html>
14 changes: 13 additions & 1 deletion front-end/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ window.addEventListener("unhandledrejection", (event) => {
handleErrorDialog(event.reason);
});

// Rebloom click handler
document.querySelector("#app").addEventListener("click", async (event) => {
const action = event.target.dataset.action;

if (action === "rebloom") {
const bloomElement = event.target.closest("[data-bloom]");
const bloomId = bloomElement.dataset.bloomId;

await apiService.rebloom(bloomId);
}
});

export {
getLogoutContainer,
getLoginContainer,
Expand All @@ -68,4 +80,4 @@ export {
getErrorDialog,
state,
apiService,
};
};
18 changes: 18 additions & 0 deletions front-end/lib/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@ async function postBloom(content) {
}
}

// Re bloom
async function rebloom(bloomId) {
try {
const data = await _apiRequest(`/rebloom/${bloomId}`, {
method: "POST",
});

if (data.success) {
await getBlooms();
}

return data;
} catch (error) {
return {success: false};
}
}

// ======= USER methods
async function getProfile(username) {
const endpoint = username ? `/profile/${username}` : "/profile";
Expand Down Expand Up @@ -291,6 +308,7 @@ const apiService = {
getBloom,
getBlooms,
postBloom,
rebloom,
getBloomsByHashtag,

// User methods
Expand Down