From e7928e88c328ba89f3f0548283c7e6bf132257c5 Mon Sep 17 00:00:00 2001 From: Ashwin Rajesh <46510831+VanillaViking@users.noreply.github.com> Date: Sun, 8 Sep 2024 06:35:19 +1000 Subject: [PATCH] feat: dynamic prompt pages, fixed UI issues with prompt list (#122) * feat: dynamic prompt pages, fixed UI issues with prompt list * fix: remove migrate body --- nginx-docker/convert-nginx.sh | 2 -- nginx-docker/nginx.conf | 2 +- zyenyo-backend/src/models.rs | 1 + zyenyo-backend/src/routes/mod.rs | 1 + zyenyo-backend/src/routes/prompts.rs | 28 +++++++++++++++++-- .../src/main/java/dataStructures/Aliases.java | 1 + zyenyo-frontend/src/app/page.tsx | 2 +- .../src/app/prompts/[slug]/page.tsx | 28 +++++++++++++++++++ zyenyo-frontend/src/app/prompts/page.tsx | 2 +- .../src/components/HomePage/Dashboard.tsx | 8 +++--- .../src/components/Navigation/Header.tsx | 2 +- .../src/components/PromptsPage/PromptCard.tsx | 18 +++++------- .../components/PromptsPage/PromptControls.tsx | 13 ++++----- 13 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 zyenyo-frontend/src/app/prompts/[slug]/page.tsx diff --git a/nginx-docker/convert-nginx.sh b/nginx-docker/convert-nginx.sh index 14a832e..490b44d 100644 --- a/nginx-docker/convert-nginx.sh +++ b/nginx-docker/convert-nginx.sh @@ -1,6 +1,4 @@ # !/usr/bin/env bash envsubst '$${NEXTJS_CONTAINER_IP} $${ACTIX_CONTAINER_IP}' < /etc/nginx/conf.d/${CONF_FILE} > /etc/nginx/conf.d/default.conf -rm -rf /etc/nginx/conf.d/dev-nginx.conf -rm -rf /etc/nginx/conf.d/prod-nginx.conf nginx -g "daemon off;" diff --git a/nginx-docker/nginx.conf b/nginx-docker/nginx.conf index 005c4c6..84f61c3 100644 --- a/nginx-docker/nginx.conf +++ b/nginx-docker/nginx.conf @@ -45,5 +45,5 @@ http { # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. - include /etc/nginx/conf.d/*.conf; + include /etc/nginx/conf.d/default.conf; } diff --git a/zyenyo-backend/src/models.rs b/zyenyo-backend/src/models.rs index 90e9a9b..8eb3134 100644 --- a/zyenyo-backend/src/models.rs +++ b/zyenyo-backend/src/models.rs @@ -7,6 +7,7 @@ pub struct Prompt { pub title: String, pub text: String, pub rating: f64, + pub slug: String, } #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] diff --git a/zyenyo-backend/src/routes/mod.rs b/zyenyo-backend/src/routes/mod.rs index 7bf4fa1..b9c4856 100644 --- a/zyenyo-backend/src/routes/mod.rs +++ b/zyenyo-backend/src/routes/mod.rs @@ -6,5 +6,6 @@ use actix_web::web; pub fn api_config(cfg: &mut web::ServiceConfig) { cfg .service(prompts::prompts) + .service(prompts::prompt) .service(botstats::botstats); } diff --git a/zyenyo-backend/src/routes/prompts.rs b/zyenyo-backend/src/routes/prompts.rs index 55bebbe..e7972f9 100644 --- a/zyenyo-backend/src/routes/prompts.rs +++ b/zyenyo-backend/src/routes/prompts.rs @@ -51,13 +51,13 @@ async fn prompts( ) -> impl Responder { let info = controls.into_inner(); - match prompt_query(context, info).await { + match prompts_query(context, info).await { Ok(prompts_vec) => HttpResponse::Ok().json(prompts_vec), Err(e) => HttpResponse::InternalServerError().body(e.to_string()), } } -async fn prompt_query( +async fn prompts_query( context: web::Data, controls: PromptsConfig, ) -> Result, Box> { @@ -84,3 +84,27 @@ async fn prompt_query( .filter_map(|doc| bson::from_document::(doc.to_owned()).ok()) .collect()) } + + +#[get("/prompt/{slug}")] +async fn prompt(context: web::Data, path: web::Path) -> impl Responder { + let slug = path.into_inner(); + + dbg!(&slug); + + match prompts_by_slug_query(context, slug).await { + Ok(Some(prompt)) => HttpResponse::Ok().json(prompt), + Ok(None) => HttpResponse::NotFound().body("No prompt found"), + Err(e) => HttpResponse::InternalServerError().body(e.to_string()), + } +} + +async fn prompts_by_slug_query(context: web::Data, slug: String) -> Result, Box> { + let collection: Collection = context.db.collection("prompts"); + + Ok(collection.find_one(doc! {"slug": slug}, None).await?) + + + + +} diff --git a/zyenyo-discord/src/main/java/dataStructures/Aliases.java b/zyenyo-discord/src/main/java/dataStructures/Aliases.java index 81cd821..e67c3c8 100644 --- a/zyenyo-discord/src/main/java/dataStructures/Aliases.java +++ b/zyenyo-discord/src/main/java/dataStructures/Aliases.java @@ -62,6 +62,7 @@ public final class Aliases BotConfig.PREFIX + "compare", BotConfig.PREFIX + "c"); public static final Set TYPEDIFF = Set.of( + BotConfig.PREFIX + "typediff", BotConfig.PREFIX + "difference", BotConfig.PREFIX + "diff"); public final static Set CHART = Collections.singleton(BotConfig.PREFIX + "chart"); diff --git a/zyenyo-frontend/src/app/page.tsx b/zyenyo-frontend/src/app/page.tsx index 74695a6..fa089d0 100644 --- a/zyenyo-frontend/src/app/page.tsx +++ b/zyenyo-frontend/src/app/page.tsx @@ -2,7 +2,7 @@ import Dashboard from '@/components/HomePage/Dashboard' export default function Home() { return ( -
+
diff --git a/zyenyo-frontend/src/app/prompts/[slug]/page.tsx b/zyenyo-frontend/src/app/prompts/[slug]/page.tsx new file mode 100644 index 0000000..9872dc7 --- /dev/null +++ b/zyenyo-frontend/src/app/prompts/[slug]/page.tsx @@ -0,0 +1,28 @@ +"use client" +import Header from "@/components/Navigation/Header"; +import { Prompt } from "@/components/PromptsPage/PromptControls"; +import axios from "axios"; +import { useEffect, useState } from "react"; + +export default function Prompt({ params }: { params: { slug: string } }) { + const [prompt, setPrompt] = useState(null) + + useEffect(() => { + async function query() { + const res = await axios.get(`/api/prompt/${params.slug}`); + setPrompt(res.data as Prompt) + + } + query() + }, [params.slug]) + + + return ( +
+
+
{prompt?.title}
+
{prompt?.text}
+
Type Rating: {prompt?.rating.toFixed(2)}
+
+ ) +} diff --git a/zyenyo-frontend/src/app/prompts/page.tsx b/zyenyo-frontend/src/app/prompts/page.tsx index 8c60447..f690917 100644 --- a/zyenyo-frontend/src/app/prompts/page.tsx +++ b/zyenyo-frontend/src/app/prompts/page.tsx @@ -3,7 +3,7 @@ import PromptControls from "@/components/PromptsPage/PromptControls"; export default function PromptsPage() { return ( -
+
diff --git a/zyenyo-frontend/src/components/HomePage/Dashboard.tsx b/zyenyo-frontend/src/components/HomePage/Dashboard.tsx index 12ffe93..b3b0a58 100644 --- a/zyenyo-frontend/src/components/HomePage/Dashboard.tsx +++ b/zyenyo-frontend/src/components/HomePage/Dashboard.tsx @@ -20,7 +20,7 @@ const Dashboard = () => {
- +

Get Zyenyo

@@ -28,7 +28,7 @@ const Dashboard = () => {
- +

Commands

@@ -36,7 +36,7 @@ const Dashboard = () => {
- +

Leaderboards

@@ -44,7 +44,7 @@ const Dashboard = () => {
- +

Prompts

diff --git a/zyenyo-frontend/src/components/Navigation/Header.tsx b/zyenyo-frontend/src/components/Navigation/Header.tsx index 5cf9056..c28bf93 100644 --- a/zyenyo-frontend/src/components/Navigation/Header.tsx +++ b/zyenyo-frontend/src/components/Navigation/Header.tsx @@ -4,7 +4,7 @@ import Link from "next/link" const Header = () => { return ( -
+
Zyenyo
Bot
diff --git a/zyenyo-frontend/src/components/PromptsPage/PromptCard.tsx b/zyenyo-frontend/src/components/PromptsPage/PromptCard.tsx index 29a541a..9e0cb87 100644 --- a/zyenyo-frontend/src/components/PromptsPage/PromptCard.tsx +++ b/zyenyo-frontend/src/components/PromptsPage/PromptCard.tsx @@ -1,6 +1,7 @@ import {useState} from "react" import {Prompt} from "./PromptControls" import { ChevronDoubleDownIcon, ChevronDoubleUpIcon } from "@heroicons/react/24/outline"; +import Link from "next/link"; type PromptCardProps = { @@ -12,18 +13,13 @@ const PromptCard = (props: PromptCardProps) => { let { prompt } = props return ( - + ) } diff --git a/zyenyo-frontend/src/components/PromptsPage/PromptControls.tsx b/zyenyo-frontend/src/components/PromptsPage/PromptControls.tsx index ab3353e..15efc05 100644 --- a/zyenyo-frontend/src/components/PromptsPage/PromptControls.tsx +++ b/zyenyo-frontend/src/components/PromptsPage/PromptControls.tsx @@ -13,6 +13,7 @@ export type Prompt = { title: String, text: String, rating: number, + slug: String } const sortOptions = [ @@ -40,11 +41,11 @@ const PromptControls = () => { }, [promptControls]) return ( -
+
debounced(e.target.value)}/> -
+

Sort By

@@ -52,7 +53,7 @@ const PromptControls = () => { classNames={{ control: () => "bg-zinc-800 border-2 border-amber-400 rounded-xl p-2", menu: () => "bg-zinc-800 border-2 border-amber-400 rounded-xl p-3", - option: (state) => state.isFocused ? 'bg-zinc-800' : 'bg-zinc-800' + option: (state) => state.isFocused ? 'bg-zinc-700' : 'bg-zinc-800' }} unstyled isSearchable={false} @@ -72,7 +73,7 @@ const PromptControls = () => { classNames={{ control: () => "bg-zinc-800 border-2 border-amber-400 rounded-xl p-2", menu: () => "bg-zinc-800 border-2 border-amber-400 rounded-xl p-3", - option: (state) => state.isFocused ? 'bg-zinc-800' : 'bg-zinc-800' + option: (state) => state.isFocused ? 'bg-zinc-700' : 'bg-zinc-800' }} unstyled isSearchable={false} @@ -100,10 +101,8 @@ const PromptControls = () => {
-
- +
{prompts?.map((prompt, idx) => )} -
)