Skip to content

Instantly share code, notes, and snippets.

View mikenath223's full-sized avatar
๐Ÿ’œ
Looking for the next challenging opportunity

Michgolden Ukeje mikenath223

๐Ÿ’œ
Looking for the next challenging opportunity
View GitHub Profile
@mikenath223
mikenath223 / useMswMock.hooks.ts
Created November 10, 2024 09:21
Setup MSW for mock testing graphql requests, used as MSW mock service worker to intercept request and return mock results to fastract frontend development, before actual APIs are built.
import { useEffect, useState } from "react";
const isEnabledMocking = process.env.NEXT_PUBLIC_ENABLE_API_MOCKING === "true";
export default function useMswMock() {
const [shouldRender, setShouldRender] = useState(!isEnabledMocking);
useEffect(() => {
async function initMocks() {
const { worker } = await import("./browser");
@mikenath223
mikenath223 / transcribe.ts
Last active December 14, 2024 07:38
OpenAI's Whisper model was integrated into an API handler I developed for a Next.js application, designed to process HTTP POST requests and transcribe audio files to the model..
import type { NextApiRequest, NextApiResponse } from "next";
import axios from "axios";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "POST") {
return res.status(405).json({ message: "Method not allowed" });
}
try {
const formData = new FormData();
@mikenath223
mikenath223 / filter.js
Created May 28, 2020 02:33
components/filter.js
import React from "react";
import PropTypes from "prop-types";
const Filter = ({ filter, handleFilterChange }) => (
<div>
<h3>Search Available Books</h3>
<input value={filter} type="text" onChange={handleFilterChange} />
</div>
);
@mikenath223
mikenath223 / bookForm.js
Created May 28, 2020 02:30
containers/bookForm.js
import React from "react";
import { connect } from "react-redux";
import { ADDBOOK } from "../actions/index";
import PropTypes from "prop-types";
const mapDispatchToProps = dispatch => ({
createBook: book => dispatch(ADDBOOK(book))
});
const BookForm = ({ createBook }) => {
@mikenath223
mikenath223 / bookList.js
Created May 28, 2020 02:28
containers/bookList.js
import React from "react";
import { CREATEBOOK, REMOVEBOOK, FILTER } from "../actions/index";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import Filter from "../components/filterBook";
import Book from "../components/book";
const mapStateToProps = state => ({
books: state.book,
filter: state.filter
@mikenath223
mikenath223 / book.js
Created May 28, 2020 02:21
components/book.js
import React from "react";
import PropTypes from "prop-types";
const Book = ({ bk, handleRemove }) => (
<div style={{ border: "1px solid green", padding: "5px" }}>
<h2>{bk.name}</h2>
<h3>{bk.author}</h3>
<button type="button" onClick={() => handleRemove(bk)}>
Delete
</button>
@mikenath223
mikenath223 / index.js
Created May 28, 2020 02:20
src/index.js
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { createStore } from "redux";
import rootReducer from "./reducers/index";
import App from "./components/App";
const store = createStore(rootReducer);
ReactDOM.render(
@mikenath223
mikenath223 / index.js
Created May 28, 2020 02:19
reducers/index.js
import book from "./book";
import filter from "./filter";
import { combineReducers } from "redux";
const rootReducer = combineReducers({
book,
filter
});
export default rootReducer;
@mikenath223
mikenath223 / filter.js
Created May 28, 2020 02:15
reducers/filter.js
const filter = (state = "", action) => {
switch (action.type) {
case "FILTER":
return action.filter;
default:
return state;
}
};
export default filter;
@mikenath223
mikenath223 / book.js
Created May 28, 2020 02:06
book reducer
const initialState = [
{
name: "The Intelligent Investor",
author: "Ben Graham"
},
{
name: "Harry Potter and the Philosopher's Stone",
author: "J. K. Rowling"
}
];