-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'wzixiao/mobile-option' into dev
- Loading branch information
Showing
10 changed files
with
189 additions
and
35 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
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,55 @@ | ||
import * as React from 'react' | ||
import { Input, Typography } from '@mui/material' | ||
import Markdown from '../markdown' | ||
import Switch from '@mui/material/Switch'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
|
||
import { IMobileContext } from "../infoview/context" | ||
|
||
interface PreferencesPopupProps extends IMobileContext{ | ||
handleClose: () => void | ||
} | ||
|
||
export function PreferencesPopup({ mobile, setMobile, lockMobile, setLockMobile, handleClose }: PreferencesPopupProps) { | ||
return <div className="modal-wrapper"> | ||
<div className="modal-backdrop" onClick={handleClose} /> | ||
<div className="modal"> | ||
<div className="codicon codicon-close modal-close" onClick={handleClose}></div> | ||
<Typography variant="body1" component="div" className="settings"> | ||
<div className='preferences-category'> | ||
<div className='category-title'> | ||
<h3>Mobile layout</h3> | ||
</div> | ||
<div className='preferences-item'> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={mobile} | ||
onChange={() => setMobile(!mobile)} | ||
name="checked" | ||
color="primary" | ||
/> | ||
} | ||
label="Enable" | ||
labelPlacement="start" | ||
/> | ||
</div> | ||
<div className='preferences-item'> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={!lockMobile} | ||
onChange={() => setLockMobile(!lockMobile)} | ||
name="checked" | ||
color="primary" | ||
/> | ||
} | ||
label="Auto" | ||
labelPlacement="start" | ||
/> | ||
</div> | ||
</div> | ||
</Typography> | ||
</div> | ||
</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
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,6 +1,30 @@ | ||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' | ||
import type { RootState, AppDispatch } from './state/store' | ||
|
||
import { setMobile as setMobileState, setLockMobile as setLockMobileState} from "./state/preferences" | ||
|
||
// Use throughout your app instead of plain `useDispatch` and `useSelector` | ||
export const useAppDispatch: () => AppDispatch = useDispatch | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector | ||
|
||
export const useMobile = () => { | ||
const dispatch = useAppDispatch(); | ||
|
||
const mobile = useAppSelector((state) => state.preferences.mobile); | ||
const lockMobile = useAppSelector((state) => state.preferences.lockMobile); | ||
|
||
const setMobile = (val: boolean) => { | ||
dispatch(setMobileState(val)); | ||
}; | ||
|
||
const setLockMobile = (val: boolean) => { | ||
dispatch(setLockMobileState(val)); | ||
}; | ||
|
||
return { | ||
mobile, | ||
setMobile, | ||
lockMobile, | ||
setLockMobile, | ||
}; | ||
}; |
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,37 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
import { loadPreferences } from "./local_storage"; | ||
|
||
interface PreferencesState { | ||
mobile: boolean; | ||
lockMobile: boolean; | ||
} | ||
|
||
export function getWindowDimensions() { | ||
const {innerWidth: width, innerHeight: height } = window | ||
return {width, height} | ||
} | ||
|
||
const { width } = getWindowDimensions() | ||
|
||
export const AUTO_SWITCH_THRESHOLD = 800 | ||
|
||
const initialState: PreferencesState = loadPreferences() ?? { | ||
mobile: width < AUTO_SWITCH_THRESHOLD, | ||
lockMobile: false | ||
} | ||
|
||
export const preferencesSlice = createSlice({ | ||
name: "preferences", | ||
initialState, | ||
reducers: { | ||
setMobile: (state, action) => { | ||
state.mobile = action.payload; | ||
}, | ||
setLockMobile: (state, action) => { | ||
state.lockMobile = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setMobile, setLockMobile } = preferencesSlice.actions; |
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 was deleted.
Oops, something went wrong.