-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/3.6.6' into main
- Loading branch information
Showing
34 changed files
with
1,080 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ name: Dev | |
on: | ||
push: | ||
branches: [ develop ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { AppState } from '@/ui_models/app_state'; | ||
import { toDirective, useAutorunValue } from './utils'; | ||
import { useRef, useState } from 'preact/hooks'; | ||
import { WebApplication } from '@/ui_models/application'; | ||
import VisuallyHidden from '@reach/visually-hidden'; | ||
import { | ||
Disclosure, | ||
DisclosureButton, | ||
DisclosurePanel, | ||
} from '@reach/disclosure'; | ||
import { FocusEvent } from 'react'; | ||
import { Switch } from './Switch'; | ||
import TuneIcon from '../../icons/ic_tune.svg'; | ||
|
||
type Props = { | ||
appState: AppState; | ||
application: WebApplication; | ||
}; | ||
|
||
function SearchOptions({ appState }: Props) { | ||
const { searchOptions } = appState; | ||
|
||
const { | ||
includeProtectedContents, | ||
includeArchived, | ||
includeTrashed, | ||
} = useAutorunValue( | ||
() => ({ | ||
includeProtectedContents: searchOptions.includeProtectedContents, | ||
includeArchived: searchOptions.includeArchived, | ||
includeTrashed: searchOptions.includeTrashed, | ||
}), | ||
[searchOptions] | ||
); | ||
|
||
const [ | ||
togglingIncludeProtectedContents, | ||
setTogglingIncludeProtectedContents, | ||
] = useState(false); | ||
|
||
async function toggleIncludeProtectedContents() { | ||
setTogglingIncludeProtectedContents(true); | ||
try { | ||
await searchOptions.toggleIncludeProtectedContents(); | ||
} finally { | ||
setTogglingIncludeProtectedContents(false); | ||
} | ||
} | ||
|
||
const [open, setOpen] = useState(false); | ||
const [optionsPanelTop, setOptionsPanelTop] = useState(0); | ||
const buttonRef = useRef<HTMLButtonElement>(); | ||
const panelRef = useRef<HTMLDivElement>(); | ||
|
||
function closeOnBlur(event: FocusEvent<HTMLElement>) { | ||
if ( | ||
!togglingIncludeProtectedContents && | ||
!panelRef.current.contains(event.relatedTarget as Node) | ||
) { | ||
setOpen(false); | ||
} | ||
} | ||
|
||
return ( | ||
<Disclosure | ||
open={open} | ||
onChange={() => { | ||
const { height } = buttonRef.current.getBoundingClientRect(); | ||
setOptionsPanelTop(height); | ||
setOpen((prevOpen) => !prevOpen); | ||
}} | ||
> | ||
<DisclosureButton | ||
ref={buttonRef} | ||
onBlur={closeOnBlur} | ||
className="sn-icon-button color-neutral hover:color-info" | ||
> | ||
<VisuallyHidden>Search options</VisuallyHidden> | ||
<TuneIcon className="fill-current block" /> | ||
</DisclosureButton> | ||
<DisclosurePanel | ||
ref={panelRef} | ||
style={{ | ||
top: optionsPanelTop, | ||
}} | ||
className="sn-dropdown sn-dropdown-anchor-right grid gap-2 py-2" | ||
> | ||
<Switch | ||
checked={includeProtectedContents} | ||
onChange={toggleIncludeProtectedContents} | ||
onBlur={closeOnBlur} | ||
> | ||
<p className="capitalize">Include protected contents</p> | ||
</Switch> | ||
<Switch | ||
checked={includeArchived} | ||
onChange={searchOptions.toggleIncludeArchived} | ||
onBlur={closeOnBlur} | ||
> | ||
<p className="capitalize">Include archived notes</p> | ||
</Switch> | ||
<Switch | ||
checked={includeTrashed} | ||
onChange={searchOptions.toggleIncludeTrashed} | ||
onBlur={closeOnBlur} | ||
> | ||
<p className="capitalize">Include trashed notes</p> | ||
</Switch> | ||
</DisclosurePanel> | ||
</Disclosure> | ||
); | ||
} | ||
|
||
export const SearchOptionsDirective = toDirective<Props>(SearchOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ComponentChildren, FunctionalComponent } from 'preact'; | ||
import { useState } from 'preact/hooks'; | ||
import { HTMLProps } from 'react'; | ||
import { | ||
CustomCheckboxContainer, | ||
CustomCheckboxInput, | ||
CustomCheckboxInputProps, | ||
} from '@reach/checkbox'; | ||
import '@reach/checkbox/styles.css'; | ||
|
||
export type SwitchProps = HTMLProps<HTMLInputElement> & { | ||
checked?: boolean; | ||
onChange: (checked: boolean) => void; | ||
children: ComponentChildren; | ||
}; | ||
|
||
export const Switch: FunctionalComponent<SwitchProps> = ( | ||
props: SwitchProps | ||
) => { | ||
const [checkedState, setChecked] = useState(props.checked || false); | ||
const checked = props.checked ?? checkedState; | ||
return ( | ||
<label className="sn-component flex justify-between items-center cursor-pointer hover:bg-contrast py-2 px-3"> | ||
{props.children} | ||
<CustomCheckboxContainer | ||
checked={checked} | ||
onChange={(event) => { | ||
setChecked(event.target.checked); | ||
props.onChange(event.target.checked); | ||
}} | ||
className={`sn-switch ${checked ? 'bg-info' : 'bg-secondary-contrast'}`} | ||
> | ||
<CustomCheckboxInput | ||
{...({ | ||
...props, | ||
children: undefined, | ||
} as CustomCheckboxInputProps)} | ||
/> | ||
<span | ||
aria-hidden | ||
className={`sn-switch-handle ${ | ||
checked ? 'sn-switch-handle-right' : '' | ||
}`} | ||
/> | ||
</CustomCheckboxContainer> | ||
</label> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.