This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from IronKinoko/favorites-action
Favorites action
- Loading branch information
Showing
23 changed files
with
465 additions
and
111 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
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,29 @@ | ||
import React, { forwardRef } from 'react' | ||
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles' | ||
|
||
import Loading from './Loading' | ||
import { IconButton, IconButtonProps } from '@material-ui/core' | ||
import clsx from 'clsx' | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
root: { | ||
position: 'relative', | ||
display: 'inline-block', | ||
}, | ||
}) | ||
) | ||
const LoadingIconButton = forwardRef< | ||
HTMLButtonElement, | ||
IconButtonProps & { loading?: boolean } | ||
>(({ loading, children, className, ...rest }, ref) => { | ||
const classes = useStyles() | ||
|
||
return ( | ||
<IconButton ref={ref} className={clsx(classes.root, className)} {...rest}> | ||
{children} | ||
{loading && <Loading size={48} />} | ||
</IconButton> | ||
) | ||
}) | ||
export default LoadingIconButton |
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,21 @@ | ||
import React from 'react' | ||
import { SvgIcon } from '@material-ui/core' | ||
|
||
const TorrentIcon = (props: any) => { | ||
return ( | ||
<SvgIcon viewBox="-10 -10 228 228"> | ||
<g> | ||
<path | ||
d="M166,128c0,0-6,18-22,26s-44,6-44,6s11.7967,26.7384,20.5935,46.6836 c37.5236-6.0196,68.344-32.1092,81.09-66.91C195.4099,139.828,188.9531,139.414,184,138C170,134,166,128,166,128z" | ||
fill="currentColor" | ||
/> | ||
<path | ||
d="M104,0C46.5623,0,0,46.5624,0,104c0,46.9452,31.1055,86.6248,73.828,99.5548 C51.6171,147.5624,19.3591,64.6408,22,62c4-4,30-10,36-8s26,80,54,82s42-20,38-30s-26-60-26-60l32-8c0,0,24,58,34,70 c3.7031,4.4416,10.4179,6.418,17.4099,7.1444C207.8007,111.4844,208,107.7656,208,104C208,46.5624,161.4375,0,104,0z" | ||
fill="currentColor" | ||
/> | ||
</g> | ||
</SvgIcon> | ||
) | ||
} | ||
|
||
export default TorrentIcon |
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,11 +1,16 @@ | ||
import React from 'react' | ||
import useRequest, { Config } from './useRequest' | ||
import { Detailpage } from 'interface/gallery' | ||
|
||
export default function useGallery( | ||
{ url }: { [k: string]: string }, | ||
config?: Config<Detailpage> | ||
) { | ||
const res = useRequest<Detailpage>({ url: '/api/gallery' + url }, config) | ||
import useSWR from 'swr' | ||
import { axios } from 'apis' | ||
export default function useGallery({ url }: { [k: string]: string }) { | ||
const res = useSWR( | ||
'/api/gallery' + url, | ||
async (url) => { | ||
const res = await axios.get<Detailpage>(url) | ||
if (res.data.error) throw new Error('error') | ||
return res.data | ||
}, | ||
{ errorRetryInterval: 100 } | ||
) | ||
return res | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ const nextConfig = { | |
autoPrerender: false, | ||
}, | ||
env: { | ||
VERSION: '2.0.1', | ||
VERSION: '2.1.0', | ||
}, | ||
} | ||
|
||
|
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,100 @@ | ||
import React, { useState } from 'react' | ||
import { axios } from 'apis' | ||
import { IndexListItemPorps } from 'interface/gallery' | ||
import { | ||
Tooltip, | ||
IconButton, | ||
SwipeableDrawer, | ||
AppBar, | ||
Toolbar, | ||
Typography, | ||
List, | ||
ListItem, | ||
ListItemIcon, | ||
ListItemText, | ||
Grid, | ||
} from '@material-ui/core' | ||
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder' | ||
import FavoriteIcon from '@material-ui/icons/Favorite' | ||
import useFavoritesInfo from 'hooks/useFavoritesInfo' | ||
import FolderIcon from '@material-ui/icons/Folder' | ||
import { mutate } from 'swr' | ||
import { Detailpage } from 'interface/gallery' | ||
import { cloneDeep } from 'lodash' | ||
import LoadingIconButton from 'components/LoadingButton' | ||
const FavIconButton: React.FC<{ info: IndexListItemPorps }> = ({ info }) => { | ||
const { data } = useFavoritesInfo() | ||
const [open, setOpen] = useState(false) | ||
const [loading, setLoading] = useState(false) | ||
const handleFavorite = async () => { | ||
if (info.favoritelink !== '') { | ||
update('favdel', '') | ||
} else { | ||
setOpen(true) | ||
} | ||
} | ||
|
||
const update = async (favcat: string | number, favoritelink: string) => { | ||
setLoading(true) | ||
await axios.put(`/api/favorites/add${info.path}?favcat=${favcat}`) | ||
setLoading(false) | ||
mutate('/api/gallery' + info.path, (v: Detailpage) => { | ||
const a = cloneDeep(v) | ||
a.info.favoritelink = favoritelink | ||
return a | ||
}) | ||
} | ||
return ( | ||
<> | ||
<Tooltip title={info.favoritelink || 'Add'}> | ||
<LoadingIconButton | ||
loading={loading} | ||
color="primary" | ||
onClick={handleFavorite} | ||
> | ||
{info.favoritelink !== '' ? <FavoriteIcon /> : <FavoriteBorderIcon />} | ||
</LoadingIconButton> | ||
</Tooltip> | ||
{data && ( | ||
<SwipeableDrawer | ||
anchor="right" | ||
disableDiscovery | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
onOpen={() => setOpen(true)} | ||
> | ||
<AppBar position="static"> | ||
<Toolbar> | ||
<Typography variant="h6">Favorites</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
<List onClick={() => setOpen(false)} style={{ width: 250 }}> | ||
{data.slice(1).map((o) => ( | ||
<ListItem | ||
key={o.index} | ||
button | ||
onClick={() => update(o.index, o.favName)} | ||
> | ||
<ListItemIcon> | ||
<FolderIcon /> | ||
</ListItemIcon> | ||
<ListItemText> | ||
<Grid container> | ||
<Grid item xs zeroMinWidth> | ||
<Typography noWrap>{o.favName}</Typography> | ||
</Grid> | ||
<Grid> | ||
<Typography>{o.count}</Typography> | ||
</Grid> | ||
</Grid> | ||
</ListItemText> | ||
</ListItem> | ||
))} | ||
</List> | ||
</SwipeableDrawer> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default FavIconButton |
Oops, something went wrong.