Skip to content

Commit

Permalink
Merge pull request #405 from picsoritdidnthappen/database-staging
Browse files Browse the repository at this point in the history
mobile nav + improved ban
  • Loading branch information
picsoritdidnthappen authored Dec 1, 2024
2 parents 8545422 + f5da752 commit 880afc1
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 69 deletions.
16 changes: 14 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ model Bounties {
in_progress Boolean? @default(true)
is_joined_bounty Boolean? @default(false)
is_canceled Boolean? @default(false)
is_banned Boolean? @default(false)
is_multiplayer Boolean?
is_voting Boolean? @default(false)
deadline Int?
claims Claims[]
participations ParticipationsBounties[]
issuerUser Users? @relation(fields: [issuer], references: [address])
ban Ban[]
@@id([id, chain_id])
}
Expand All @@ -36,13 +36,13 @@ model Claims {
description String
url String
issuer String
is_banned Boolean?
is_accepted Boolean?
bounty_id Int
owner String
bounty Bounties? @relation(fields: [bounty_id, chain_id], references: [id, chain_id])
issuerUser Users? @relation(fields: [issuer], references: [address])
ban Ban[]
@@id([id, chain_id])
}
Expand Down Expand Up @@ -70,3 +70,15 @@ model Users {
@@id([address])
}

model Ban {
id Int @id @default(autoincrement())
chain_id Int
bounty_id Int?
claim_id Int?
banned_at DateTime @default(now())
banned_by String
bounty Bounties? @relation(fields: [bounty_id, chain_id], references: [id, chain_id])
claim Claims? @relation(fields: [claim_id, chain_id], references: [id, chain_id])
}
10 changes: 9 additions & 1 deletion src/app/[netname]/bounty/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ import 'react-toastify/dist/ReactToastify.css';
import BountyClaims from '@/components/bounty/BountyClaims';
import BountyInfo from '@/components/bounty/BountyInfo';
import CreateClaim from '@/components/ui/CreateClaim';
import NavBarMobile from '@/components/global/NavBarMobile';
import { useScreenSize } from '@/hooks/useScreenSize';

export default function Bounty({ params }: { params: { id: string } }) {
const isMobile = useScreenSize();

return (
<>
<div className='px-5 lg:px-20'>
<BountyInfo bountyId={params.id} />
<BountyClaims bountyId={params.id} />
</div>
<CreateClaim bountyId={params.id} />
{isMobile ? (
<NavBarMobile type='claim' bountyId={params.id} />
) : (
<CreateClaim bountyId={params.id} />
)}
<ToastContainer />
<div className='h-80' />
</>
Expand Down
6 changes: 5 additions & 1 deletion src/app/[netname]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

import ContentHome from '@/components/layout/ContentHome';
import NavBarMobile from '@/components/global/NavBarMobile';
import CreateBounty from '@/components/ui/CreateBounty';
import { useScreenSize } from '@/hooks/useScreenSize';

export default function Home() {
const isMobile = useScreenSize();

return (
<>
<ContentHome />
<CreateBounty />
{isMobile ? <NavBarMobile type='bounty' /> : <CreateBounty />}
<ToastContainer />
</>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/bounty/BountyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ export default function BountyInfo({ bountyId }: { bountyId: string }) {
toast.error('You are not an admin');
}
}}
disabled={bounty.data.is_banned || false}
disabled={bounty.data.ban.length > 0 || false}
className={cn(
'border border-[#F15E5F] w-fit rounded-md py-2 px-5 mt-5',
bounty.data.isBanned
bounty.data.ban.length > 0
? 'bg-red-400 text-white'
: 'hover:bg-red-400 hover:text-white'
)}
>
{bounty.data.isBanned ? 'banned' : 'ban'}
{bounty.data.ban.length > 0 ? 'banned' : 'ban'}
</button>
)}
<p className='mt-5 font-bold'>
Expand Down
1 change: 1 addition & 0 deletions src/components/bounty/ClaimItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function ClaimItem({
if (!signature) {
throw new Error('Failed to sign message');
}

await banClaimMutation.mutateAsync({
id: Number(claimId),
chainId: chain.id,
Expand Down
42 changes: 10 additions & 32 deletions src/components/global/FormClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function FormClaim({
const [status, setStatus] = useState<string>('');
const [file, setFile] = useState<File | null>(null);
const utils = trpc.useUtils();
const [uploading, setUploading] = useState(false);

const account = useAccount();
const writeContract = useWriteContract({});
Expand All @@ -53,15 +54,7 @@ export default function FormClaim({
reader.readAsDataURL(file);
}, []);

const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop,
maxFiles: 1,
accept: {
'image/png': ['.png'],
'image/jpeg': ['.jpg', '.jpeg'],
'image/heic': ['.heic'],
},
});
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });

const compressImage = async (image: File): Promise<File> => {
const options = {
Expand Down Expand Up @@ -102,15 +95,19 @@ export default function FormClaim({
useEffect(() => {
const uploadImage = async () => {
if (file) {
setUploading(true);
try {
const compressedFile = await compressImage(file);
const cid = await retryUpload(compressedFile);
setImageURI(`${LINK_IPFS}/${cid}`);
} catch (error) {
toast.error('Failed to upload image: ' + error);
console.error('Error uploading file:', error);
alert('Trouble uploading file');
}
setUploading(false);
}
};

uploadImage();
}, [file]);

Expand Down Expand Up @@ -208,20 +205,7 @@ export default function FormClaim({
<DialogContent>
<div
{...getRootProps()}
style={{
border: '2px dashed #D1ECFF',
padding: '20px',
borderRadius: '30px',
textAlign: 'center',
cursor: imageURI ? 'default' : 'pointer',
marginBottom: '10px',
opacity: imageURI ? 1 : 0.5,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
height: 'fit-content',
minHeight: '200px',
}}
className='flex items-center flex-col text-left text-white rounded-[30px] border border-[#D1ECFF] border-dashed p-5 w-full lg:min-w-[400px] justify-center cursor-pointer'
>
<input {...getInputProps()} />
{isDragActive ? (
Expand All @@ -237,13 +221,7 @@ export default function FormClaim({
<Image
src={preview}
alt='Preview'
width={300}
height={300}
style={{
marginTop: '10px',
objectFit: 'contain',
borderRadius: '10px',
}}
className='w-[300px] h-[300px] mt-2 rounded-md object-contain'
/>
)}
</div>
Expand Down Expand Up @@ -271,7 +249,7 @@ export default function FormClaim({
account.isDisconnected && 'opacity-50 cursor-not-allowed'
)}
onClick={() => {
if (name && description && imageURI) {
if (name && description && imageURI && !uploading) {
onClose();
createClaimMutations.mutate(BigInt(bountyId));
} else {
Expand Down
Loading

0 comments on commit 880afc1

Please sign in to comment.