Skip to content

Commit

Permalink
Feat: Add tag options to navbar from db
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilalekha committed Jun 16, 2021
1 parent 85205c6 commit d0a89e7
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions component/myblogs/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,58 @@ import React, { useRef, useEffect, useState } from "react";
import Link from "next/link";
import Select from "react-select";
import styles from "./blogs.module.scss";
import tagOptions from "../../utils/tags";
// import tagOptions from "../../utils/tags";
import { useRouter } from "next/router";
import Cookies from "universal-cookie";
import PostService from "../../services/PostService";
import TagService from "../../services/TagService";

export default function Navbar(props) {
const { currentNav, getPosts } = props;
const cookies = new Cookies();
const userCookie = cookies.get("userNullcast");
const router = useRouter();
const [tag, setTag] = useState("");
const [tagOptions, setTagOptions] = useState([]);
const [status, setStatus] = useState("");

const statusOptions = [
{ label: "All Posts", value: "" },
{ label: "Approved", value: "approved" },
{ label: "Pending", value: "pending" },
{ label: "Rejected", value: "rejected" },
{ label: "Published", value: "published" },
{ label: "Drafted", value: "drafted" }
{ label: "ALL POSTS", value: "" },
{ label: "APPROVED", value: "approved" },
{ label: "PENDING", value: "pending" },
{ label: "REJECTED", value: "rejected" },
{ label: "PUBLISHED", value: "published" },
{ label: "DRAFTED", value: "drafted" }
];

useEffect(() => {
getSettingsTags();
}, []);

/**
* gets tags from db and sets the tags
* options in label and value format
* @author akhilalekha
*/
async function getSettingsTags() {
const res = await TagService.getTags();
// console.log("get tags response", res);
let resTagOptions = res.map((tag) => {
return {
label: `${tag.name.toUpperCase()}`,
value: `${tag.name}`
};
});
// setTagOptions;
const allOption = {
label: "ALL TAGS",
value: ""
};
resTagOptions = [allOption, ...resTagOptions];
console.log({ resTagOptions });
setTagOptions(resTagOptions);
}

function handleTagSelect(e) {
// console.log(e);
// const tag = e.value;
Expand Down

0 comments on commit d0a89e7

Please sign in to comment.