-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
234 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"Recoil Atom": { | ||
"prefix": "sq-atom", | ||
"body": [ | ||
"import { atom } from 'recoil';", | ||
"", | ||
"export const ${1:CollectionId}Atom = atom({", | ||
" key: '${1:CollectionId}Atom',", | ||
" default: 1", | ||
"});" | ||
], | ||
"description": "Creates a new atom", | ||
"scope": "typescript" | ||
}, | ||
"Recoil Selector (sync)": { | ||
"prefix": "sq-selector-sync", | ||
"body": [ | ||
"import { selector } from 'recoil';", | ||
"", | ||
"export const ${1:CollectionData}Selector = selector({", | ||
" key: '${1:CollectionData}Selector',", | ||
" get: ({get}) => {", | ||
" return get(${2:CollectionIdState});", | ||
" }", | ||
"});" | ||
], | ||
"description": "Creates a new synchronous selector", | ||
"scope": "typescript" | ||
}, | ||
"Recoil Selector (async)": { | ||
"prefix": "sq-selector-async", | ||
"body": [ | ||
"import { selector } from 'recoil';", | ||
"", | ||
"export const ${1:CollectionData}Selector = selector({", | ||
" key: '${1:CollectionData}Selector',", | ||
" get: async ({get}) => {", | ||
" return await dataFetch(get(${2:CollectionIdState}));", | ||
" }", | ||
"});" | ||
], | ||
"description": "Creates a new asynchronous selector", | ||
"scope": "typescript" | ||
}, | ||
"Recoil selectorFamily": { | ||
"prefix": "sq-selector-fam", | ||
"body": [ | ||
"import { selectorFamily } from 'recoil';", | ||
"", | ||
"export const ${1:CollectionData}Selector = selectorFamily({", | ||
" key: '${1:CollectionData}Selector',", | ||
" get: id => async () => {", | ||
" return await dataFetch({id});", | ||
" }", | ||
"});" | ||
], | ||
"description": "Creates a selectorFamily (same as selector, but used to provide parameters)", | ||
"scope": "typescript" | ||
}, | ||
"useTranslation": { | ||
"prefix": ["sq-translation", "useTranslation"], | ||
"body": "const { t: strings } = useTranslation();", | ||
"description": "Include the translations", | ||
"scope": "typescriptreact" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
import * as React from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { ViewAtom, ViewType } from '../../state'; | ||
import { ViewGridIcon, ViewListIcon } from '@heroicons/react/solid'; | ||
import { STORAGE_VIEW_TYPE } from '../../constants/Storage'; | ||
|
||
export interface IViewSwitchProps {} | ||
|
||
export const ViewSwitch: React.FunctionComponent<IViewSwitchProps> = (props: React.PropsWithChildren<IViewSwitchProps>) => { | ||
const [ view, setView ] = useRecoilState(ViewAtom); | ||
|
||
const toggleView = () => { | ||
const newView = view === ViewType.Grid ? ViewType.List : ViewType.Grid; | ||
window.localStorage.setItem(STORAGE_VIEW_TYPE, newView.toString()); | ||
setView(newView); | ||
}; | ||
|
||
return ( | ||
<div className={`flex rounded-sm bg-vulcan-50 lg:mb-1`}> | ||
<button className={`flex items-center p-2 rounded-l-sm ${view === ViewType.Grid ? 'bg-teal-500 text-vulcan-500' : 'text-whisper-500'}`} onClick={toggleView}> | ||
<ViewGridIcon className={`w-4 h-4`} /> | ||
<span className={`sr-only`}>Change to grid</span> | ||
</button> | ||
<button className={`flex items-center p-2 rounded-r-sm ${view === ViewType.List ? 'bg-teal-500 text-vulcan-500' : 'text-whisper-500'}`} onClick={toggleView}> | ||
<ViewListIcon className={`w-4 h-4`} /> | ||
<span className={`sr-only`}>Change to list</span> | ||
</button> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,47 +1,77 @@ | ||
import * as React from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { MessageHelper } from '../../helpers/MessageHelper'; | ||
import { MarkdownIcon } from '../../viewpanel/components/Icons/MarkdownIcon'; | ||
import { DashboardMessage } from '../DashboardMessage'; | ||
import { Page } from '../models/Page'; | ||
import { ViewSelector, ViewType } from '../state'; | ||
import { DateField } from './DateField'; | ||
import { Status } from './Status'; | ||
|
||
export interface IItemProps extends Page {} | ||
|
||
export const Item: React.FunctionComponent<IItemProps> = ({ fmFilePath, date, title, draft, description, preview }: React.PropsWithChildren<IItemProps>) => { | ||
const view = useRecoilValue(ViewSelector); | ||
|
||
let className = ''; | ||
if (view === ViewType.Grid) { | ||
className = `grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8`; | ||
} else if (view === ViewType.List) { | ||
className = `divide-y divide-vulcan-200`; | ||
} | ||
|
||
const openFile = () => { | ||
MessageHelper.sendMessage(DashboardMessage.openFile, fmFilePath); | ||
}; | ||
|
||
return ( | ||
<li className="relative"> | ||
<button className={`group cursor-pointer flex flex-wrap items-start content-start h-full w-full bg-gray-50 dark:bg-vulcan-200 text-vulcan-500 dark:text-whisper-500 text-left overflow-hidden shadow-md hover:shadow-xl dark:hover:bg-vulcan-100`} | ||
onClick={openFile}> | ||
<div className="relative h-36 w-full overflow-hidden border-b border-gray-100 dark:border-vulcan-100 dark:group-hover:border-vulcan-200"> | ||
{ | ||
preview ? ( | ||
<img src={`${preview}`} alt={title} className="absolute inset-0 h-full w-full object-cover" loading="lazy" /> | ||
) : ( | ||
<div className={`flex items-center justify-center bg-whisper-500 dark:bg-vulcan-200 dark:group-hover:bg-vulcan-100`}> | ||
<MarkdownIcon className={`h-32 text-vulcan-100 dark:text-whisper-100`} /> | ||
</div> | ||
) | ||
} | ||
</div> | ||
|
||
<div className="p-4 w-full"> | ||
<div className={`flex justify-between items-center`}> | ||
<Status draft={!!draft} /> | ||
if (view === ViewType.Grid) { | ||
return ( | ||
<li className="relative"> | ||
<button className={`group cursor-pointer flex flex-wrap items-start content-start h-full w-full bg-gray-50 dark:bg-vulcan-200 text-vulcan-500 dark:text-whisper-500 text-left overflow-hidden shadow-md hover:shadow-xl dark:hover:bg-vulcan-100`} | ||
onClick={openFile}> | ||
<div className="relative h-36 w-full overflow-hidden border-b border-gray-100 dark:border-vulcan-100 dark:group-hover:border-vulcan-200"> | ||
{ | ||
preview ? ( | ||
<img src={`${preview}`} alt={title} className="absolute inset-0 h-full w-full object-cover" loading="lazy" /> | ||
) : ( | ||
<div className={`flex items-center justify-center bg-whisper-500 dark:bg-vulcan-200 dark:group-hover:bg-vulcan-100`}> | ||
<MarkdownIcon className={`h-32 text-vulcan-100 dark:text-whisper-100`} /> | ||
</div> | ||
) | ||
} | ||
</div> | ||
|
||
<div className="p-4 w-full"> | ||
<div className={`flex justify-between items-center`}> | ||
<Status draft={!!draft} /> | ||
|
||
<DateField value={date} /> | ||
</div> | ||
|
||
<h2 className="mt-2 mb-2 font-bold">{title}</h2> | ||
|
||
<p className="text-xs text-vulcan-200 dark:text-whisper-800">{description}</p> | ||
</div> | ||
</button> | ||
</li> | ||
); | ||
} else if (view === ViewType.List) { | ||
return ( | ||
<li className="relative"> | ||
<button className={`px-5 cursor-pointer w-full text-left grid grid-cols-12 gap-x-4 sm:gap-x-6 xl:gap-x-8 py-2 border-b border-vulcan-50 hover:bg-vulcan-50 hover:bg-opacity-70`} onClick={openFile}> | ||
<div className="col-span-8 font-bold truncate"> | ||
{title} | ||
</div> | ||
<div className="col-span-2"> | ||
<DateField value={date} /> | ||
</div> | ||
<div className="col-span-2"> | ||
<Status draft={!!draft} /> | ||
</div> | ||
</button> | ||
</li> | ||
); | ||
} | ||
|
||
<h2 className="mt-2 mb-2 font-bold">{title}</h2> | ||
|
||
<p className="text-xs text-vulcan-200 dark:text-whisper-800">{description}</p> | ||
</div> | ||
</button> | ||
</li> | ||
); | ||
return null; | ||
}; |
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 @@ | ||
export const STORAGE_VIEW_TYPE = 'FrontMatter:ListViewType'; |
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,14 @@ | ||
import { atom } from 'recoil'; | ||
import { STORAGE_VIEW_TYPE } from '../../constants/Storage'; | ||
|
||
export enum ViewType { | ||
Grid = 1, | ||
List | ||
} | ||
|
||
const defaultView: number = parseInt(window.localStorage.getItem(STORAGE_VIEW_TYPE) as string); | ||
|
||
export const ViewAtom = atom<ViewType>({ | ||
key: 'ViewAtom', | ||
default: isNaN(defaultView) ? ViewType.Grid : defaultView | ||
}); |
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 @@ | ||
export * from './ViewAtom'; |
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,2 @@ | ||
export * from './atom'; | ||
export * from './selectors'; |
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,9 @@ | ||
import { selector } from 'recoil'; | ||
import { ViewAtom } from '..'; | ||
|
||
export const ViewSelector = selector({ | ||
key: 'ViewSelector', | ||
get: ({get}) => { | ||
return get(ViewAtom); | ||
} | ||
}); |
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 @@ | ||
export * from './ViewSelector'; |
b8dee7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: