mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
fix paginator
This commit is contained in:
parent
50f076084f
commit
c210ea3f89
@ -6,7 +6,7 @@ function IncButton({ children, label, className, ...buttonProps }) {
|
|||||||
<button
|
<button
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
className={cn(
|
className={cn(
|
||||||
'rounded-md border border-transparent p-1 text-center text-sm transition-all hover:bg-foreground active:bg-lineBackground disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none',
|
'border border-transparent p-1 text-center text-sm transition-all hover:bg-foreground active:bg-lineBackground disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
type="button"
|
type="button"
|
||||||
@ -41,7 +41,7 @@ export function Incrementor({ onChange, value, min = -Infinity, max = Infinity,
|
|||||||
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
|
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
|
||||||
</svg>
|
</svg>
|
||||||
</IncButton>
|
</IncButton>
|
||||||
<IncButton label={'decrement'} disabled={value >= max} onClick={() => onChange(value + 1)}>
|
<IncButton label={'decrement'} className="rounded-r-md" disabled={value >= max} onClick={() => onChange(value + 1)}>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" className="w-4 h-4">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" className="w-4 h-4">
|
||||||
<path d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z" />
|
<path d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
|
|
||||||
import { Incrementor } from '../incrementor/Incrementor';
|
import { Incrementor } from '../incrementor/Incrementor';
|
||||||
|
|
||||||
export function Pagination({ currPage, onPageChange, className }) {
|
export function Pagination({ currPage, onPageChange, className }) {
|
||||||
return <Incrementor min={1} value={currPage} onChange={onPageChange} className={className} />;
|
return <Incrementor min={1} value={currPage} onChange={onPageChange} className={className} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,7 @@ import { settingsMap, useSettings } from '../../../settings.mjs';
|
|||||||
import { Pagination } from '../pagination/Pagination.jsx';
|
import { Pagination } from '../pagination/Pagination.jsx';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useDebounce } from '../usedebounce.jsx';
|
import { useDebounce } from '../usedebounce.jsx';
|
||||||
|
import { cn } from 'tailwind_utils.mjs';
|
||||||
function classNames(...classes) {
|
|
||||||
return classes.filter(Boolean).join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function PatternLabel({ pattern } /* : { pattern: Tables<'code'> } */) {
|
export function PatternLabel({ pattern } /* : { pattern: Tables<'code'> } */) {
|
||||||
const meta = useMemo(() => getMetadata(pattern.code), [pattern]);
|
const meta = useMemo(() => getMetadata(pattern.code), [pattern]);
|
||||||
@ -46,7 +43,7 @@ export function PatternLabel({ pattern } /* : { pattern: Tables<'code'> } */) {
|
|||||||
function PatternButton({ showOutline, onClick, pattern, showHiglight }) {
|
function PatternButton({ showOutline, onClick, pattern, showHiglight }) {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
className={classNames(
|
className={cn(
|
||||||
'mr-4 hover:opacity-50 cursor-pointer block',
|
'mr-4 hover:opacity-50 cursor-pointer block',
|
||||||
showOutline && 'outline outline-1',
|
showOutline && 'outline outline-1',
|
||||||
showHiglight && 'bg-selection',
|
showHiglight && 'bg-selection',
|
||||||
@ -169,8 +166,8 @@ function UserPatterns({ context }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function PatternPageWithPagination({ patterns, patternOnClick, context, paginationOnChange }) {
|
function PatternPageWithPagination({ patterns, patternOnClick, context, paginationOnChange, initialPage }) {
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(initialPage);
|
||||||
const debouncedPageChange = useDebounce(() => {
|
const debouncedPageChange = useDebounce(() => {
|
||||||
paginationOnChange(page);
|
paginationOnChange(page);
|
||||||
});
|
});
|
||||||
@ -192,13 +189,14 @@ function PatternPageWithPagination({ patterns, patternOnClick, context, paginati
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2 py-2">
|
<div className="flex items-center gap-2 py-2">
|
||||||
<label htmlFor="pattern pagination">Page</label>{' '}
|
<label htmlFor="pattern pagination">Page</label>
|
||||||
<Pagination id="pattern pagination" currPage={page} onPageChange={onPageChange} />
|
<Pagination id="pattern pagination" currPage={page} onPageChange={onPageChange} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let featuredPageNum = 1
|
||||||
function FeaturedPatterns({ context }) {
|
function FeaturedPatterns({ context }) {
|
||||||
const examplePatterns = useExamplePatterns();
|
const examplePatterns = useExamplePatterns();
|
||||||
const collections = examplePatterns.collections;
|
const collections = examplePatterns.collections;
|
||||||
@ -207,6 +205,7 @@ function FeaturedPatterns({ context }) {
|
|||||||
<PatternPageWithPagination
|
<PatternPageWithPagination
|
||||||
patterns={patterns}
|
patterns={patterns}
|
||||||
context={context}
|
context={context}
|
||||||
|
initialPage={featuredPageNum}
|
||||||
patternOnClick={(id) => {
|
patternOnClick={(id) => {
|
||||||
updateCodeWindow(
|
updateCodeWindow(
|
||||||
context,
|
context,
|
||||||
@ -216,11 +215,13 @@ function FeaturedPatterns({ context }) {
|
|||||||
}}
|
}}
|
||||||
paginationOnChange={async (pageNum) => {
|
paginationOnChange={async (pageNum) => {
|
||||||
await loadAndSetFeaturedPatterns(pageNum);
|
await loadAndSetFeaturedPatterns(pageNum);
|
||||||
|
featuredPageNum = pageNum
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let latestPageNum = 1
|
||||||
function LatestPatterns({ context }) {
|
function LatestPatterns({ context }) {
|
||||||
const examplePatterns = useExamplePatterns();
|
const examplePatterns = useExamplePatterns();
|
||||||
const collections = examplePatterns.collections;
|
const collections = examplePatterns.collections;
|
||||||
@ -229,15 +230,13 @@ function LatestPatterns({ context }) {
|
|||||||
<PatternPageWithPagination
|
<PatternPageWithPagination
|
||||||
patterns={patterns}
|
patterns={patterns}
|
||||||
context={context}
|
context={context}
|
||||||
|
initialPage={latestPageNum}
|
||||||
patternOnClick={(id) => {
|
patternOnClick={(id) => {
|
||||||
updateCodeWindow(
|
updateCodeWindow(context, { ...patterns[id], collection: patternFilterName.public }, autoResetPatternOnChange);
|
||||||
context,
|
|
||||||
{ ...patterns[id], collection: patternFilterName.public },
|
|
||||||
autoResetPatternOnChange,
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
paginationOnChange={async (pageNum) => {
|
paginationOnChange={async (pageNum) => {
|
||||||
await loadAndSetPublicPatterns(pageNum);
|
await loadAndSetPublicPatterns(pageNum);
|
||||||
|
latestPageNum = pageNum
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
import { cn } from 'tailwind_utils.mjs';
|
import { cn } from 'tailwind_utils.mjs';
|
||||||
// type TextboxProps = {
|
|
||||||
// onChange: (val: string | number) => void;
|
export function Textbox({ onChange, className, ...inputProps }) {
|
||||||
// ...inputProps
|
|
||||||
// }
|
|
||||||
export function Textbox(props) {
|
|
||||||
const {onChange, className, ...inputProps} = props
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
className={cn('p-1 bg-background rounded-md my-2 border-foreground', props.className)}
|
className={cn('p-1 bg-background rounded-md my-2 border-foreground', className)}
|
||||||
onChange={(e) => props.onChange(e.target.value)}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
{...inputProps}
|
{...inputProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// utility for combining class names
|
// utility for combining class names
|
||||||
export function cn(...classNameStrings) {
|
export function cn(...classes) {
|
||||||
return classNameStrings.join(' ')
|
return classes.filter(Boolean).join(' ');
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user