Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Added]: Custom label functionality. #78

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/containers/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ import { Label, sortedLabels } from '@/models/Label';
import { Language, sortedLanguages } from '@/models/Language';
import { SortingTag, sortedSortingTags } from '@/models/SortingTag';
import { useUrlValues } from '@/providers/urlProvider';
import { FormEvent, useState } from 'react';

const Filter = () => {
const [customLabel, setCustomLabel] = useState("");

const [labels, setLabels] = useState(sortedLabels);

const customLabelHandler = (e: FormEvent) => {
e.preventDefault();
setLabels([...labels, customLabel]);
onLabelChange(customLabel);
setCustomLabel("");
}

const { dispatch, language, ordering, sortingTag, label } = useUrlValues();

const onLanguageChange = (payload: Language) => {
Expand Down Expand Up @@ -40,7 +52,7 @@ const Filter = () => {

<MiniContainer title='labels'>
<ul className='flex flex-wrap gap-3 mt-4'>
{sortedLabels.map((l) => (
{labels.map((l) => (
<li key={toId(l)}>
<Select
value={l}
Expand All @@ -51,6 +63,15 @@ const Filter = () => {
</li>
))}
</ul>
<form className='mt-2' onSubmit={(e) => { customLabelHandler(e) }}>
<input
value={customLabel}
type='input'
onChange={(e) => { setCustomLabel(e.target.value) }}
placeholder='+ add custom label'
className='block bg-transparent p-3 py-1.5 font-mono text-xs capitalize transition-all border rounded cursor-pointer hover:text-accent hover:border-accent focus:text-accent focus:border-accent border-dark-2 peer-hover:border-accent peer-focus:border-accent peer-focus:text-accent peer-checked:text-accent peer-checked:border-accent peer-checked:bg-accent-light peer-focus:outline-none'
/>
</form>
</MiniContainer>

<MiniContainer title='sort'>
Expand Down
4 changes: 2 additions & 2 deletions src/models/Label.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const label = [
export let label = [
'none',
'hacktoberfest',
'good first issue',
'bug',
'enhancement',
'documentation',
'easy fix',
] as const;
];

vatsalsinghkv marked this conversation as resolved.
Show resolved Hide resolved
export const sortedLabels = [...label];

Expand Down
Loading