mirror of
https://github.com/fergalmoran/opengifame.git
synced 2025-12-22 09:38:44 +00:00
Merge conflicts
This commit is contained in:
2673
package-lock.json
generated
2673
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@@ -35,52 +35,6 @@
|
||||
"zod": "^3.23.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
<<<<<<< Updated upstream
|
||||
"@headlessui/react": "^1.7.4",
|
||||
"@next-auth/prisma-adapter": "^1.0.5",
|
||||
"@prisma/client": "^4.5.0",
|
||||
"@tailwindcss/forms": "^0.5.3",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"@types/formidable": "^2.0.5",
|
||||
"@types/js-cookie": "^3.0.2",
|
||||
"@types/lodash": "^4.14.188",
|
||||
"@types/mime-types": "^2.1.1",
|
||||
"@types/node": "18.11.9",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-copy-to-clipboard": "^5.0.4",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"autoprefixer": "^10.4.12",
|
||||
"bcrypt": "^5.1.0",
|
||||
"chalk": "^5.1.2",
|
||||
"cookie": "^0.5.0",
|
||||
"daisyui": "^2.38.0",
|
||||
"dotenv-cli": "^6.0.0",
|
||||
"eslint": "^8.25.0",
|
||||
"eslint-config-next": "13.0.2",
|
||||
"formidable": "^2.0.1",
|
||||
"i": "^0.3.7",
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash": "^4.17.21",
|
||||
"loglevel": "^1.8.0",
|
||||
"loglevel-plugin-prefix": "^0.8.4",
|
||||
"mime-types": "^2.1.35",
|
||||
"next": "13.0.2",
|
||||
"next-auth": "^4.15.1",
|
||||
"next-themes": "^0.2.1",
|
||||
"npm": "^8.19.3",
|
||||
"postcss": "^8.4.18",
|
||||
"prisma": "^4.5.0",
|
||||
"react": "18.2.0",
|
||||
"react-copy-to-clipboard": "^5.1.0",
|
||||
"react-dom": "18.2.0",
|
||||
"react-hook-form": "^7.39.1",
|
||||
"react-icons": "^4.6.0",
|
||||
"request-ip": "^3.3.0",
|
||||
"tailwindcss": "^3.1.8",
|
||||
"typescript": "4.8.4",
|
||||
"uuid": "^9.0.0"
|
||||
=======
|
||||
"@types/eslint": "^8.56.10",
|
||||
"@types/node": "^20.14.10",
|
||||
"@types/react": "^18.3.3",
|
||||
@@ -96,7 +50,6 @@
|
||||
"prettier-plugin-tailwindcss": "^0.6.5",
|
||||
"tailwindcss": "^3.4.3",
|
||||
"typescript": "^5.5.3"
|
||||
>>>>>>> Stashed changes
|
||||
},
|
||||
"ct3aMetadata": {
|
||||
"initVersion": "7.37.0"
|
||||
|
||||
50
src/components/trending-images.tsx
Normal file
50
src/components/trending-images.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { api } from "@/trpc/react";
|
||||
|
||||
export function TrendingImages() {
|
||||
const [latestPost] = api.post.getLatest.useSuspenseQuery();
|
||||
|
||||
const utils = api.useUtils();
|
||||
const [name, setName] = useState("");
|
||||
const createPost = api.post.create.useMutation({
|
||||
onSuccess: async () => {
|
||||
await utils.post.invalidate();
|
||||
setName("");
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-xs">
|
||||
{latestPost ? (
|
||||
<p className="truncate">Your most recent post: {latestPost.name}</p>
|
||||
) : (
|
||||
<p>You have no posts yet.</p>
|
||||
)}
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
createPost.mutate({ name });
|
||||
}}
|
||||
className="flex flex-col gap-2"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Title"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="w-full rounded-full px-4 py-2 text-black"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20"
|
||||
disabled={createPost.isPending}
|
||||
>
|
||||
{createPost.isPending ? "Submitting..." : "Submit"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
69
src/components/widgets/CopyTextInput.tsx
Normal file
69
src/components/widgets/CopyTextInput.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
'use client';
|
||||
import { Transition } from '@headlessui/react';
|
||||
import React from 'react';
|
||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||
import { HiOutlineClipboardCopy } from 'react-icons/hi';
|
||||
|
||||
interface ICopyTextInput {
|
||||
label: string;
|
||||
text: string;
|
||||
}
|
||||
const CopyTextInput: React.FC<ICopyTextInput> = ({ label, text }) => {
|
||||
const [showResult, setShowResult] = React.useState(false);
|
||||
const _onCopy = () => {
|
||||
setShowResult(true);
|
||||
setTimeout(() => {
|
||||
setShowResult(false);
|
||||
}, 2000);
|
||||
};
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div>
|
||||
<label
|
||||
htmlFor="text-to-copy"
|
||||
className="block text-sm font-medium label"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
|
||||
<div className="flex mt-1 rounded-md shadow-sm ">
|
||||
<div className="relative flex items-stretch flex-grow indicator focus-within:z-10">
|
||||
<Transition
|
||||
show={showResult}
|
||||
enter="transition-opacity duration-200"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="transition-opacity duration-500"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<span className="w-3/4 indicator-item indicator-center badge badge-accent">
|
||||
Copied successfully
|
||||
</span>
|
||||
</Transition>
|
||||
<input
|
||||
id="text-to-copy"
|
||||
readOnly={true}
|
||||
value={text}
|
||||
className="block w-full rounded-none input input-md rounded-l-md sm:text-sm"
|
||||
placeholder="John Doe"
|
||||
/>
|
||||
</div>
|
||||
<CopyToClipboard
|
||||
text={text}
|
||||
onCopy={_onCopy}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="relative inline-flex items-center px-4 py-2 -ml-px space-x-2 text-sm font-medium btn rounded-r-md"
|
||||
>
|
||||
<HiOutlineClipboardCopy className="w-6 h-6 text-accent" />
|
||||
</button>
|
||||
</CopyToClipboard>
|
||||
</div>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export default CopyTextInput;
|
||||
100
src/components/widgets/GifContainer.tsx
Normal file
100
src/components/widgets/GifContainer.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
'use client';
|
||||
import React from 'react';
|
||||
import Image from 'next/image';
|
||||
import { TbThumbUp, TbThumbDown } from 'react-icons/tb';
|
||||
import { Gif } from 'models';
|
||||
import Link from 'next/link';
|
||||
|
||||
interface IGifContainerProps {
|
||||
gif: Gif;
|
||||
isLink?: boolean;
|
||||
showDetails?: boolean;
|
||||
}
|
||||
const GifContainer: React.FC<IGifContainerProps> = ({
|
||||
gif,
|
||||
isLink = true,
|
||||
showDetails = true,
|
||||
}) => {
|
||||
const [upVotes, setUpVotes] = React.useState<number>(gif.upVotes);
|
||||
const [downVotes, setDownVotes] = React.useState<number>(gif.downVotes);
|
||||
|
||||
const _doot = async (id: string, isUp: boolean) => {
|
||||
const response = await fetch(`api/votes?gifId=${id}&isUp=${isUp ? 1 : 0}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (response.status === 200) {
|
||||
const result = (await response.json()) as Gif;
|
||||
setUpVotes(result.upVotes);
|
||||
setDownVotes(result.downVotes);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className="group relative h-[17.5rem] transform overflow-hidden rounded-4xl">
|
||||
<div className="absolute inset-0">
|
||||
{isLink ? (
|
||||
<Link
|
||||
href={`gifs/${gif.slug}`}
|
||||
title={gif.title}
|
||||
>
|
||||
<Image
|
||||
alt={gif.title}
|
||||
className="absolute inset-0 transition duration-300 group-hover:scale-110"
|
||||
src={gif.fileName}
|
||||
fill
|
||||
sizes="100vw"
|
||||
style={{
|
||||
objectFit: 'fill',
|
||||
}}
|
||||
/>
|
||||
</Link>
|
||||
) : (
|
||||
<Image
|
||||
alt={gif.title}
|
||||
className="absolute inset-0 transition duration-300 group-hover:scale-110"
|
||||
src={gif.fileName}
|
||||
fill
|
||||
sizes="100vw"
|
||||
style={{
|
||||
objectFit: 'fill',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{showDetails && (
|
||||
<div className="flex flex-row p-2">
|
||||
<div className="flex-1 space-x-2 text-base">
|
||||
{gif.searchTerms?.map((t) => (
|
||||
<div
|
||||
key={t}
|
||||
className="mr-0.5 badge badge-info badge-md badge-outline"
|
||||
>
|
||||
{`#${t}`}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center justify-center space-x-1">
|
||||
<div className="flex transition duration-75 ease-in-out delay-150 hover:text-orange-700 hover:cursor-pointer">
|
||||
<span onClick={() => _doot(gif.id, true)}>
|
||||
<TbThumbUp className="w-5" />
|
||||
</span>
|
||||
<span className="text-xs">{upVotes}</span>
|
||||
</div>
|
||||
<div className="flex transition duration-75 ease-in-out delay-150 hover:text-orange-700 hover:cursor-pointer">
|
||||
<span
|
||||
onClick={() => _doot(gif.id, false)}
|
||||
className="pl-2 "
|
||||
>
|
||||
<TbThumbDown className="w-5" />
|
||||
</span>
|
||||
<span className="text-xs">{downVotes}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default GifContainer;
|
||||
64
src/components/widgets/ImageUpload.tsx
Normal file
64
src/components/widgets/ImageUpload.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import React from 'react';
|
||||
import { HiOutlineXMark } from 'react-icons/hi2';
|
||||
import { ImUpload2 } from 'react-icons/im';
|
||||
interface IImageUploadProps {
|
||||
value: string | undefined;
|
||||
onChange: (image: File) => void;
|
||||
}
|
||||
const ImageUpload: React.FC<IImageUploadProps> = ({ onChange }) => {
|
||||
const [image, setImage] = React.useState<string>();
|
||||
const onImageChange = ($event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
console.log('ImageUpload', 'onImageChange', $event);
|
||||
if ($event.target.files) {
|
||||
const url = URL.createObjectURL($event.target.files[0]);
|
||||
setImage(url);
|
||||
onChange($event.target.files[0]);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="flex justify-center px-6 pt-5 pb-6 mt-1 border-2 border-dashed rounded-md border-secondary">
|
||||
{image ? (
|
||||
<div>
|
||||
<div className="relative">
|
||||
<img
|
||||
src={image}
|
||||
alt="Preview"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute top-0 right-0 p-2 m-2 rounded-full "
|
||||
onClick={() => setImage('')}
|
||||
>
|
||||
{''}
|
||||
<HiOutlineXMark className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-1 text-center">
|
||||
<ImUpload2 className="w-8 h-8 mx-auto mb-3 text-base-content/70" />
|
||||
<div className="flex text-sm text-base-content">
|
||||
<label
|
||||
htmlFor="gif-upload"
|
||||
className="relative font-medium rounded-md cursor-pointer hover:text-accent badge badge-primary"
|
||||
>
|
||||
<span>Upload a file</span>
|
||||
<input
|
||||
accept="image/gif,video/mp4,video/mov,video/quicktime,video/webm,youtube,vimeo"
|
||||
id="gif-upload"
|
||||
type="file"
|
||||
className="sr-only"
|
||||
onChange={onImageChange}
|
||||
/>
|
||||
</label>
|
||||
<p className="pl-1">or drag and drop</p>
|
||||
</div>
|
||||
<p className="text-xs ">PNG, JPG, GIF up to 10MB</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageUpload;
|
||||
92
src/components/widgets/Loading.tsx
Normal file
92
src/components/widgets/Loading.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import React from 'react';
|
||||
|
||||
const Loading = () => {
|
||||
return (
|
||||
<div
|
||||
aria-label="Loading..."
|
||||
role="status"
|
||||
className="flex items-center space-x-2"
|
||||
>
|
||||
<svg
|
||||
className="w-6 h-6 animate-spin stroke-accent"
|
||||
viewBox="0 0 256 256"
|
||||
>
|
||||
<line
|
||||
x1="128"
|
||||
y1="32"
|
||||
x2="128"
|
||||
y2="64"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="195.9"
|
||||
y1="60.1"
|
||||
x2="173.3"
|
||||
y2="82.7"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="224"
|
||||
y1="128"
|
||||
x2="192"
|
||||
y2="128"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="195.9"
|
||||
y1="195.9"
|
||||
x2="173.3"
|
||||
y2="173.3"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="128"
|
||||
y1="224"
|
||||
x2="128"
|
||||
y2="192"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="60.1"
|
||||
y1="195.9"
|
||||
x2="82.7"
|
||||
y2="173.3"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="32"
|
||||
y1="128"
|
||||
x2="64"
|
||||
y2="128"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
<line
|
||||
x1="60.1"
|
||||
y1="60.1"
|
||||
x2="82.7"
|
||||
y2="82.7"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={24}
|
||||
/>
|
||||
</svg>
|
||||
<span className="text-xs font-medium text-accent">Loading...</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Loading;
|
||||
151
src/components/widgets/TaggedInput.tsx
Normal file
151
src/components/widgets/TaggedInput.tsx
Normal file
@@ -0,0 +1,151 @@
|
||||
import { logger } from '@lib/logger';
|
||||
import React, { KeyboardEventHandler } from 'react';
|
||||
|
||||
interface ITaggedInputProps {
|
||||
label: string;
|
||||
value: string[];
|
||||
onChange: (tags: string[]) => void;
|
||||
}
|
||||
const TaggedInput: React.FC<ITaggedInputProps> = ({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
}) => {
|
||||
const [isSearching, setIsSearching] = React.useState(false);
|
||||
const [searchText, setSearchText] = React.useState<string>('');
|
||||
const [searchResults, setSearchResults] = React.useState<Array<string>>([]);
|
||||
const [tags, setTags] = React.useState<Array<string>>(value);
|
||||
|
||||
React.useEffect(() => {
|
||||
logger.debug('TaggedInput', 'callingOnChange', tags);
|
||||
onChange(tags);
|
||||
}, [tags, onChange]);
|
||||
const removeTag = (tag: string) => {
|
||||
setTags(tags.filter((obj) => obj !== tag));
|
||||
};
|
||||
const searchTags = async (query: string) => {
|
||||
if (!query) {
|
||||
setSearchResults([]);
|
||||
return;
|
||||
}
|
||||
setIsSearching(true);
|
||||
const response = await fetch(`api/tags/search?q=${searchText}`);
|
||||
if (response.status === 200) {
|
||||
const results = await response.json();
|
||||
setSearchResults(results.map((r: { name: string }) => r.name));
|
||||
}
|
||||
setIsSearching(false);
|
||||
};
|
||||
const handleChange = async ($event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { value } = $event.target;
|
||||
setSearchText(value);
|
||||
await searchTags(value);
|
||||
};
|
||||
const handleKeyPress = ($event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if ($event.code === 'Enter' || $event.code === 'NumpadEnter') {
|
||||
__addTag(searchText);
|
||||
}
|
||||
};
|
||||
const __addTag = (tag: string) => {
|
||||
setTags([...tags, tag]);
|
||||
setSearchResults([]);
|
||||
setIsSearching(false);
|
||||
setSearchText('');
|
||||
};
|
||||
const doResultClick = ($event: any) => __addTag($event.target.textContent);
|
||||
return (
|
||||
<>
|
||||
<label
|
||||
htmlFor="{name}"
|
||||
className="block text-sm font-medium"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
<div className="flex w-full text-sm align-middle border rounded-lg shadow-sm border-accent ">
|
||||
<div className="flex flex-row pt-3 pl-2 space-x-1">
|
||||
{tags &&
|
||||
tags.map((tag) => (
|
||||
<span
|
||||
key={tag}
|
||||
className="badge badge-primary badge-lg py-0.5"
|
||||
>
|
||||
{tag}
|
||||
<button
|
||||
onClick={() => removeTag(tag)}
|
||||
type="button"
|
||||
className="flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center "
|
||||
>
|
||||
<span className="sr-only">{tag}</span>
|
||||
<svg
|
||||
className="w-2 h-2"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 8 8"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeWidth={1.5}
|
||||
d="M1 1l6 6m0-6L1 7"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<input
|
||||
value={searchText}
|
||||
onKeyDown={handleKeyPress}
|
||||
onChange={handleChange}
|
||||
placeholder="Start typing and press enter"
|
||||
className="w-full input focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
{isSearching && (
|
||||
<div
|
||||
role="status"
|
||||
className="z-50 ml-5 -mt-3"
|
||||
>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
className="w-4 h-4 mr-2 "
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span className="sr-only">Loading...</span>
|
||||
</div>
|
||||
)}
|
||||
{searchResults && searchResults.length !== 0 && (
|
||||
<div className={`z-50 mb-4 flex space-y-0`}>
|
||||
<aside
|
||||
aria-labelledby="menu-heading"
|
||||
className="absolute z-50 flex flex-col items-start w-64 -mt-5 text-sm bg-white border rounded-md shadow-md"
|
||||
>
|
||||
<ul className="flex flex-col w-full">
|
||||
{searchResults.map((result) => (
|
||||
<li
|
||||
key={result}
|
||||
onClick={doResultClick}
|
||||
className="px-2 py-1 space-x-2 cursor-pointer hover:bg-indigo-500 hover:text-white focus:bg-indigo-500 focus:text-white focus:outline-none"
|
||||
>
|
||||
{result}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaggedInput;
|
||||
58
src/components/widgets/UserNavDropdown.tsx
Normal file
58
src/components/widgets/UserNavDropdown.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
'use client';
|
||||
import { logger } from '@lib/logger';
|
||||
import React, { Fragment } from 'react';
|
||||
import { Menu, Transition } from '@headlessui/react';
|
||||
import { signOut } from 'next-auth/react';
|
||||
|
||||
interface IUserNavDropdownProps {
|
||||
session: any;
|
||||
}
|
||||
const UserNavDropdown: React.FC<IUserNavDropdownProps> = ({ session }) => {
|
||||
React.useEffect(() => {
|
||||
logger.debug('UserNavDropdown', 'session', session);
|
||||
}, [session]);
|
||||
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
<Menu
|
||||
as="div"
|
||||
className="relative flex-shrink-0 ml-4"
|
||||
>
|
||||
<div>
|
||||
<Menu.Button className="flex text-sm text-white bg-gray-800 rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white">
|
||||
<span className="sr-only">Open user menu</span>
|
||||
<img
|
||||
className="w-8 h-8 rounded-full"
|
||||
src={session?.user?.image as string}
|
||||
alt="Profile image"
|
||||
/>
|
||||
</Menu.Button>
|
||||
</div>
|
||||
<Transition
|
||||
as={Fragment}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Menu.Items className="absolute right-0 z-50 w-48 py-1 mt-2 origin-top-right bg-white rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
|
||||
<Menu.Item>
|
||||
{({ active }) => (
|
||||
<button
|
||||
onClick={() => signOut()}
|
||||
className="block px-4 py-2 text-sm text-gray-700"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
)}
|
||||
</Menu.Item>
|
||||
</Menu.Items>
|
||||
</Transition>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserNavDropdown;
|
||||
26
src/components/widgets/login/LoginButton.tsx
Normal file
26
src/components/widgets/login/LoginButton.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import { signIn } from 'next-auth/react';
|
||||
import { RiLoginCircleLine } from 'react-icons/ri';
|
||||
import { UserNavDropdown } from '@components';
|
||||
|
||||
interface ILoginButtonProps {
|
||||
session: any;
|
||||
}
|
||||
|
||||
const LoginButton: React.FC<ILoginButtonProps> = ({ session }) => {
|
||||
return session ? (
|
||||
<UserNavDropdown session={session} />
|
||||
) : (
|
||||
<button
|
||||
onClick={() => signIn()}
|
||||
className="normal-case btn btn-ghost drawer-button"
|
||||
>
|
||||
<RiLoginCircleLine className="inline-block w-6 h-6 fill-current md:mr-1" />
|
||||
Login
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginButton;
|
||||
92
src/components/widgets/login/SocialLogin.tsx
Normal file
92
src/components/widgets/login/SocialLogin.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
ClientSafeProvider,
|
||||
getProviders,
|
||||
LiteralUnion,
|
||||
signIn,
|
||||
useSession,
|
||||
} from 'next-auth/react';
|
||||
import { logger } from '@lib/logger';
|
||||
import { BuiltInProviderType } from 'next-auth/providers';
|
||||
import {
|
||||
FaFacebook,
|
||||
FaGithub,
|
||||
FaGithubAlt,
|
||||
FaGoogle,
|
||||
FaTwitter,
|
||||
} from 'react-icons/fa';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
const SocialLogin = () => {
|
||||
const router = useRouter();
|
||||
const [providers, setproviders] = React.useState<Record<
|
||||
LiteralUnion<BuiltInProviderType, string>,
|
||||
ClientSafeProvider
|
||||
> | null>();
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
React.useEffect(() => {
|
||||
const setTheProviders = async () => {
|
||||
const setupProviders = await getProviders();
|
||||
setproviders(setupProviders);
|
||||
};
|
||||
setTheProviders();
|
||||
}, []);
|
||||
const handleProviderAuth = async (provider: string) => {
|
||||
logger.debug('signin', 'handleProviderAuth', provider);
|
||||
const res = await signIn(provider, {
|
||||
callbackUrl: `${process.env.API_URL}`,
|
||||
});
|
||||
logger.debug('signin', 'handleProviderAuth_res', res);
|
||||
if (res?.ok) {
|
||||
router.push('/');
|
||||
}
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className="divider">or continue with</div>
|
||||
<div className="flex flex-grow w-full gap-3 mt-6">
|
||||
{providers?.facebook && (
|
||||
<button
|
||||
onClick={() => handleProviderAuth(providers.facebook.id)}
|
||||
className="justify-center flex-1 w-full px-2 py-1 btn btn-outline "
|
||||
>
|
||||
<span className="sr-only">Sign in with Facebook</span>
|
||||
<FaFacebook className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
{providers?.google && (
|
||||
<button
|
||||
onClick={() => handleProviderAuth(providers.google.id)}
|
||||
className="justify-center flex-1 w-full px-2 py-1 btn btn-outline "
|
||||
>
|
||||
<span className="sr-only">Sign in with Google</span>
|
||||
<FaGoogle className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
{providers?.github && (
|
||||
<button
|
||||
onClick={() => handleProviderAuth(providers.github.id)}
|
||||
className="justify-center flex-1 w-full px-2 py-1 btn btn-outline "
|
||||
>
|
||||
<span className="sr-only">Sign in with GitHub</span>
|
||||
<FaGithub className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
{providers?.twitter && (
|
||||
<button
|
||||
onClick={() => handleProviderAuth(providers.twitter.id)}
|
||||
className="justify-center flex-1 w-full px-2 py-1 btn btn-outline "
|
||||
>
|
||||
<span className="sr-only">Sign in with Twitter</span>
|
||||
<FaTwitter className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SocialLogin;
|
||||
@@ -26,55 +26,17 @@
|
||||
/* Path Aliases */
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
<<<<<<< Updated upstream
|
||||
"@*": [
|
||||
"./*"
|
||||
]
|
||||
},
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
]
|
||||
=======
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
>>>>>>> Stashed changes
|
||||
},
|
||||
"include": [
|
||||
".eslintrc.cjs",
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
<<<<<<< Updated upstream
|
||||
".next/types/**/*.ts"
|
||||
, ".working/.pages/upload.tsx" ],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
=======
|
||||
"**/*.cjs",
|
||||
"**/*.js",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user