-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Appearance setting for show/hide scroll bar on chat window (#2187)
* implement appearance setting for show/hide scrollbar * put back comments * revert backend for show_scrollbar * show scrollbar save to localstorage * old model function * lint * edit --------- Co-authored-by: Timothy Carambat <[email protected]>
- Loading branch information
1 parent
a30fa9b
commit fb191d8
Showing
5 changed files
with
90 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { APPEARANCE_SETTINGS } from "@/utils/constants"; | ||
|
||
const Appearance = { | ||
/** | ||
* Fetches any locally storage settings for the user | ||
* @returns {{showScrollbar: boolean}} | ||
*/ | ||
getSettings: () => { | ||
const settings = localStorage.getItem(APPEARANCE_SETTINGS); | ||
return settings ? JSON.parse(settings) : { showScrollbar: false }; | ||
}, | ||
|
||
/** | ||
* Updates locally stored user settings | ||
* @param {object} newSettings - new settings to update. | ||
* @returns {object} | ||
*/ | ||
updateSettings: (newSettings) => { | ||
const updatedSettings = { ...Appearance.getSettings(), ...newSettings }; | ||
localStorage.setItem(APPEARANCE_SETTINGS, JSON.stringify(updatedSettings)); | ||
return updatedSettings; | ||
}, | ||
}; | ||
|
||
export default Appearance; |
56 changes: 56 additions & 0 deletions
56
frontend/src/pages/GeneralSettings/Appearance/ShowScrollbar/index.jsx
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,56 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import Appearance from "@/models/appearance"; | ||
|
||
export default function ShowScrollbar() { | ||
const [saving, setSaving] = useState(false); | ||
const [showScrollbar, setShowScrollbar] = useState(false); | ||
|
||
const handleChange = async (e) => { | ||
const newValue = e.target.checked; | ||
setShowScrollbar(newValue); | ||
setSaving(true); | ||
try { | ||
Appearance.updateSettings({ showScrollbar: newValue }); | ||
} catch (error) { | ||
console.error("Failed to update appearance settings:", error); | ||
setShowScrollbar(!newValue); | ||
} | ||
setSaving(false); | ||
}; | ||
|
||
useEffect(() => { | ||
function fetchSettings() { | ||
const settings = Appearance.getSettings(); | ||
setShowScrollbar(settings.showScrollbar); | ||
} | ||
fetchSettings(); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex flex-col w-full gap-y-4 mt-6"> | ||
<div className="flex flex-col gap-y-1"> | ||
<h2 className="text-base leading-6 font-bold text-white"> | ||
Show chat window scrollbar | ||
</h2> | ||
<p className="text-xs leading-[18px] font-base text-white/60"> | ||
Enable or disable the scrollbar in the chat window | ||
</p> | ||
<div className="mt-2"> | ||
<label className="relative inline-flex cursor-pointer items-center"> | ||
<input | ||
id="show_scrollbar" | ||
type="checkbox" | ||
name="show_scrollbar" | ||
value="yes" | ||
checked={showScrollbar} | ||
onChange={handleChange} | ||
disabled={saving} | ||
className="peer sr-only" | ||
/> | ||
<div className="pointer-events-none peer h-6 w-11 rounded-full bg-stone-400 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:shadow-xl after:border after:border-gray-600 after:bg-white after:box-shadow-md after:transition-all after:content-[''] peer-checked:bg-lime-300 peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-800"></div> | ||
</label> | ||
</div> | ||
</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