C
C#6mo ago
KidKai25

✅ Is it a good idea to store CSS class as a property in my C# model?

Example
class UserStatus
{
string StatusName {get;set;}
string StyleClass {get;set;}
}
class UserStatus
{
string StatusName {get;set;}
string StyleClass {get;set;}
}
Then I store like "Online","green-circle" "Offline", "red-circle" Or should I check the status and then add the css in my js code itself?
9 Replies
KidKai25
KidKai25OP6mo ago
I ask this again because I would like more opinions
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
KidKai25
KidKai25OP6mo ago
Hi @TeBeCo
I just didn't like code duplication on back end and front end. Code duplication? How? Otherwise I again then have to check in .js
if(status === "Online") //this check again
var styleClass == "green-circle";
if(status === "Online") //this check again
var styleClass == "green-circle";
I had need to maintain a list of Status in FE and BE and keep them in sync I could avoid this check if I just store it in the back end. and then I just do
<div id="${row.UserGuid}"> <i class="${row.StatusName}" style="margin-right:4px"'></i>"${row.Status.SyleClass}"</div>
<div id="${row.UserGuid}"> <i class="${row.StatusName}" style="margin-right:4px"'></i>"${row.Status.SyleClass}"</div>
Spaxter
Spaxter6mo ago
I guess it's really a personal preference and there's nothing wrong with what you're doing, but IMO the back-end should not be responsible for any styling or other CSS/HTML related stuff, that's the front-ends job. The back-end provides data and the front-end decides how to render that data.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
FusedQyou
FusedQyou6mo ago
Please don't store frontend specific things like this in the frontend backend. It should be available without communicating to the backend If you really need this, then there might be a way to have a tool generate the relevant css on both sides That said, why would the backend need to use frontend css? If this is because it depends on a state, why not use an enum instead?
jiniux
jiniux6mo ago
don't do that. in case you'll decide to apply more complex restyling, everything will fall apart
Pobiega
Pobiega6mo ago
I'd say normally you'd just have a switch somewhere in your js rendering that would assign the correct classes based on the status
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server